Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions phpunit-pgsql.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<phpunit bootstrap="tests/Unit/bootstrap.php" colors="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit/Libraries</directory>
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration/Libraries</directory>
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<php>
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<phpunit bootstrap="tests/Unit/bootstrap.php" colors="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit/Libraries</directory>
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration/Libraries</directory>
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<php>
Expand Down
11 changes: 7 additions & 4 deletions tests/Unit/Libraries/Cms/Feed/Parser/AtomParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ public function testInitialiseSetsDefaultVersionWithXmlDocType()
{
$dummyXml = '<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" />';
$reader = \XMLReader::XML($dummyXml);
$reader = new XMLReader();
$reader->xml($dummyXml);
$atomParser = new AtomParser($reader);
$atomParser->parse();

Expand All @@ -351,8 +352,9 @@ public function testInitialiseSetsDefaultVersionWithXmlDocType()
*/
public function testInitialiseSetsDefaultVersion()
{
$dummyXml = '<feed xmlns="http://www.w3.org/2005/Atom" />';
$reader = \XMLReader::XML($dummyXml);
$dummyXml = '<feed xmlns="http://www.w3.org/2005/Atom" />';
$reader = new XMLReader();
$reader->xml($dummyXml);
$atomParser = new AtomParser($reader);
$atomParser->parse();

Expand All @@ -374,7 +376,8 @@ public function testInitialiseSetsDefaultVersion()
public function testInitialiseSetsOldVersion()
{
$dummyXml = '<feed version="0.3" xmlns="http://www.w3.org/2005/Atom" />';
$reader = \XMLReader::XML($dummyXml);
$reader = new XMLReader();
$reader->xml($dummyXml);
$atomParser = new AtomParser($reader);
$atomParser->parse();

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Libraries/Cms/Feed/Parser/RssParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ public function testParseSetsVersion()
<title>Test Channel</title>
</channel>
</rss>';
$reader = \XMLReader::XML($dummyXml);
$reader = new XMLReader();
$reader->xml($dummyXml);
$rssParser = new RssParser($reader);
$rssParser->parse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
*/
class CheckfilesPluginTest extends UnitTestCase
{
/**
* The temporary folder.
*
* @var string
*
* @since __DEPLOY_VERSION__
*/
private $tmpFolder;

/**
* Setup
*
Expand All @@ -41,13 +50,15 @@ class CheckfilesPluginTest extends UnitTestCase
*/
public function setUp(): void
{
if (!is_dir(__DIR__ . '/tmp')) {
mkdir(__DIR__ . '/tmp');
$this->tmpFolder = JPATH_ROOT . '/tmp/test';

if (!is_dir($this->tmpFolder)) {
mkdir($this->tmpFolder);
}

$image = imagecreate(200, 200);
imagecolorallocate($image, 255, 255, 0);
imagepng($image, __DIR__ . '/tmp/test.png');
imagepng($image, $this->tmpFolder . '/test.png');
imagedestroy($image);
}

Expand All @@ -60,8 +71,8 @@ public function setUp(): void
*/
public function tearDown(): void
{
if (is_dir(__DIR__ . '/tmp')) {
Folder::delete(__DIR__ . '/tmp');
if (is_dir($this->tmpFolder)) {
Folder::delete($this->tmpFolder);
}
}

Expand All @@ -80,7 +91,7 @@ public function testResize()
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);

$plugin = new Checkfiles(new Dispatcher(), [], __DIR__);
$plugin = new Checkfiles(new Dispatcher(), [], $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand All @@ -90,14 +101,14 @@ public function testResize()
'test',
[
'subject' => $task,
'params' => (object)['path' => '/tmp', 'dimension' => 'width', 'limit' => 20, 'numImages' => 1]
'params' => (object)['path' => '/', 'dimension' => 'width', 'limit' => 20, 'numImages' => 1]
]
);
$plugin->standardRoutineHandler($event);

$this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);

list($width, $height) = getimagesize(__DIR__ . '/tmp/test.png');
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
$this->assertEquals(20, $width);
$this->assertEquals(20, $height);
}
Expand All @@ -111,15 +122,15 @@ public function testResize()
*/
public function testResizeWithLimit()
{
copy(__DIR__ . '/tmp/test.png', __DIR__ . '/tmp/test1.png');
copy($this->tmpFolder . '/test.png', $this->tmpFolder . '/test1.png');

$language = $this->createStub(Language::class);
$language->method('_')->willReturn('test');

$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);

$plugin = new Checkfiles(new Dispatcher(), [], __DIR__);
$plugin = new Checkfiles(new Dispatcher(), [], $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand All @@ -129,18 +140,18 @@ public function testResizeWithLimit()
'test',
[
'subject' => $task,
'params' => (object)['path' => '/tmp', 'dimension' => 'width', 'limit' => 20, 'numImages' => 1]
'params' => (object)['path' => '/', 'dimension' => 'width', 'limit' => 20, 'numImages' => 1]
]
);
$plugin->standardRoutineHandler($event);

$this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);

list($width, $height) = getimagesize(__DIR__ . '/tmp/test.png');
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
$this->assertEquals(20, $width);
$this->assertEquals(20, $height);

list($width, $height) = getimagesize(__DIR__ . '/tmp/test1.png');
list($width, $height) = getimagesize($this->tmpFolder . '/test1.png');
$this->assertEquals(200, $width);
$this->assertEquals(200, $height);
}
Expand All @@ -160,7 +171,7 @@ public function testIgnoreResize()
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);

$plugin = new Checkfiles(new Dispatcher(), [], __DIR__);
$plugin = new Checkfiles(new Dispatcher(), [], $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand All @@ -170,14 +181,14 @@ public function testIgnoreResize()
'test',
[
'subject' => $task,
'params' => (object)['path' => '/tmp', 'dimension' => 'width', 'limit' => 2000, 'numImages' => 1]
'params' => (object)['path' => '/', 'dimension' => 'width', 'limit' => 2000, 'numImages' => 1]
]
);
$plugin->standardRoutineHandler($event);

$this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);

list($width, $height) = getimagesize(__DIR__ . '/tmp/test.png');
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
$this->assertEquals(200, $width);
$this->assertEquals(200, $height);
}
Expand All @@ -197,7 +208,7 @@ public function testInvalidFolder()
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);

$plugin = new Checkfiles(new Dispatcher(), [], __DIR__);
$plugin = new Checkfiles(new Dispatcher(), [], $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand All @@ -212,7 +223,7 @@ public function testInvalidFolder()
);
$plugin->standardRoutineHandler($event);

list($width, $height) = getimagesize(__DIR__ . '/tmp/test.png');
list($width, $height) = getimagesize($this->tmpFolder . '/test.png');
$this->assertEquals(Status::NO_RUN, $event->getResultSnapshot()['status']);
$this->assertEquals(200, $width);
$this->assertEquals(200, $height);
Expand Down
48 changes: 34 additions & 14 deletions tests/Unit/Plugin/Task/Requests/Extension/RequestsPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
*/
class RequestsPluginTest extends UnitTestCase
{
/**
* The temporary folder.
*
* @var string
*
* @since __DEPLOY_VERSION__
*/
private $tmpFolder;

/**
* Setup
*
Expand All @@ -46,8 +55,10 @@ class RequestsPluginTest extends UnitTestCase
*/
public function setUp(): void
{
if (is_dir(__DIR__ . '/tmp')) {
Folder::delete(__DIR__ . '/tmp');
$this->tmpFolder = JPATH_ROOT . '/tmp/test';

if (is_dir($this->tmpFolder)) {
Folder::delete($this->tmpFolder);
}
}

Expand All @@ -60,8 +71,8 @@ public function setUp(): void
*/
public function tearDown(): void
{
if (is_dir(__DIR__ . '/tmp')) {
Folder::delete(__DIR__ . '/tmp');
if (is_dir($this->tmpFolder)) {
Folder::delete($this->tmpFolder);
}
}

Expand Down Expand Up @@ -95,10 +106,13 @@ public static function isSupported()
$factory = $this->createStub(HttpFactory::class);
$factory->method('getHttp')->willReturn($http);

$language = $this->createStub(Language::class);
$language->method('_')->willReturn('test');

$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($this->createStub(Language::class));
$app->method('getLanguage')->willReturn($language);

$plugin = new Requests(new Dispatcher(), [], $factory, __DIR__ . '/tmp');
$plugin = new Requests(new Dispatcher(), [], $factory, $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand All @@ -116,7 +130,7 @@ public static function isSupported()
$this->assertEquals(Status::OK, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('SAVED', $event->getResultSnapshot()['output']);
$this->assertEquals('http://example.com', $transport->url);
$this->assertStringEqualsFile(__DIR__ . '/tmp/task_1_response.html', 'test');
$this->assertStringEqualsFile($this->tmpFolder . '/task_1_response.html', 'test');
}

/**
Expand Down Expand Up @@ -149,10 +163,13 @@ public static function isSupported()
$factory = $this->createStub(HttpFactory::class);
$factory->method('getHttp')->willReturn($http);

$language = $this->createStub(Language::class);
$language->method('_')->willReturn('test');

$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($this->createStub(Language::class));
$app->method('getLanguage')->willReturn($language);

$plugin = new Requests(new Dispatcher(), [], $factory, __DIR__ . '/tmp');
$plugin = new Requests(new Dispatcher(), [], $factory, $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand All @@ -170,7 +187,7 @@ public static function isSupported()
$this->assertEquals(Status::KNOCKOUT, $event->getResultSnapshot()['status']);
$this->assertStringContainsString('SAVED', $event->getResultSnapshot()['output']);
$this->assertEquals('http://example.com', $transport->url);
$this->assertStringEqualsFile(__DIR__ . '/tmp/task_1_response.html', 'test');
$this->assertStringEqualsFile($this->tmpFolder . '/task_1_response.html', 'test');
}

/**
Expand Down Expand Up @@ -203,10 +220,13 @@ public static function isSupported()
$factory = $this->createStub(HttpFactory::class);
$factory->method('getHttp')->willReturn($http);

$language = $this->createStub(Language::class);
$language->method('_')->willReturn('test');

$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($this->createStub(Language::class));
$app->method('getLanguage')->willReturn($language);

$plugin = new Requests(new Dispatcher(), [], $factory, __DIR__ . '/tmp');
$plugin = new Requests(new Dispatcher(), [], $factory, $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand Down Expand Up @@ -256,7 +276,7 @@ public static function isSupported()
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);

$plugin = new Requests(new Dispatcher(), [], $factory, __DIR__ . '/tmp');
$plugin = new Requests(new Dispatcher(), [], $factory, $this->tmpFolder);
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand Down Expand Up @@ -305,7 +325,7 @@ public static function isSupported()
$app = $this->createStub(CMSApplicationInterface::class);
$app->method('getLanguage')->willReturn($language);

$plugin = new Requests(new Dispatcher(), [], $factory, '/invalid');
$plugin = new Requests(new Dispatcher(), [], $factory, '/proc/invalid');
$plugin->setApplication($app);

$task = $this->createStub(Task::class);
Expand Down
Loading