Skip to content

Commit

Permalink
Merge branch '4.3-dev' into add_ldap_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tatankat committed Aug 25, 2022
2 parents 45707be + 0805889 commit 88bd149
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 79 deletions.
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
9 changes: 6 additions & 3 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 @@ -356,7 +357,8 @@ public function testInitialiseSetsDefaultVersion()
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Joomla! Unit test</title>
</feed>';
$reader = \XMLReader::XML($dummyXml);
$reader = new XMLReader();
$reader->xml($dummyXml);
$atomParser = new AtomParser($reader);

// same logic as FeedFactory.php : skip head record
Expand Down Expand Up @@ -395,7 +397,8 @@ public function testInitialiseSetsOldVersion()
<feed version="0.3" xmlns="http://www.w3.org/2005/Atom">
<title type="text">Joomla! Unit test</title>
</feed>';
$reader = \XMLReader::XML($dummyXml);
$reader = new XMLReader();
$reader->xml($dummyXml);
$atomParser = new AtomParser($reader);

// same logic as FeedFactory.php : skip head record
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 @@ -589,7 +589,8 @@ public function testParseSetsVersion()
<title>Test Channel</title>
</channel>
</rss>';
$reader = \XMLReader::XML($dummyXml);
$reader = new XMLReader();
$reader->xml($dummyXml);
$rssParser = new RssParser($reader);

// same logic as FeedFactory.php : skip head record
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,16 @@ class CheckfilesPluginTest extends UnitTestCase
*/
public function setUp(): void
{
if (!is_dir(__DIR__ . '/tmp')) {
mkdir(__DIR__ . '/tmp');
// Dir must be random for parallel automated tests
$this->tmpFolder = JPATH_ROOT . '/tmp/' . rand();

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 +72,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 +92,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 +102,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 +123,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 +141,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 +172,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 +182,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 +209,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 +224,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
49 changes: 35 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,11 @@ class RequestsPluginTest extends UnitTestCase
*/
public function setUp(): void
{
if (is_dir(__DIR__ . '/tmp')) {
Folder::delete(__DIR__ . '/tmp');
// Dir must be random for parallel automated tests
$this->tmpFolder = JPATH_ROOT . '/tmp/' . rand();

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

Expand All @@ -60,8 +72,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 +107,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 +131,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 +164,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 +188,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 +221,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 +277,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 +326,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

0 comments on commit 88bd149

Please sign in to comment.