Skip to content

Commit

Permalink
scripts: improve test discovery, make them run!
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Nov 16, 2023
1 parent c9ca7af commit 9f6ece5
Show file tree
Hide file tree
Showing 35 changed files with 191 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function testPluginsAdded(): void
public function testScanDir(): void
{
// Use the component directory without artifacts, because this should be mostly stable.
$expected = ["ROADMAP.md", "classes", "exceptions", "maintenance.json", "service.xml", "test"];
$expected = ["ROADMAP.md", "classes", "exceptions", "maintenance.json", "service.xml", "tests"];
$actual = array_values(
array_diff(
$this->builder->_scanDir(__DIR__ . "/../.."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ public function testBeginTag(): void
$this->assertEquals($expected, $this->processor->getData());
}

public function testTagComponentTypeMismatch(): void
{
$this->expectException(\InvalidArgumentException::class);

$type = "components/ILIAS";
$name = "NAME";
$id = "ID";

$this->processor->beginComponent($name, $type);
$this->processor->beginTag("module", ["id" => $id]);
}

public function testMissingId(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function _getComponents(): array
$components = $reader->_getComponents();

$this->assertIsArray($components);
$this->assertContains(["components/ILIAS", "Course", realpath(__DIR__ . "/../../../components/ILIAS/Course/module.xml")], $components);
$this->assertContains(["components/ILIAS", "Component", realpath(__DIR__ . "/../../../components/ILIAS/Component/service.xml")], $components);
$this->assertContains(["components/ILIAS", "Course", realpath(__DIR__ . "/../../../../components/ILIAS/Course/module.xml")], $components);
$this->assertContains(["components/ILIAS", "Component", realpath(__DIR__ . "/../../../../components/ILIAS/Component/service.xml")], $components);
}

public function testReadComponentDefinitions(): void
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/Contact/BuddySystem/test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

declare(strict_types=1);

require_once __DIR__ . '/../../../../vendor/composer/vendor/autoload.php';
require_once __DIR__ . '/../../../../../vendor/composer/vendor/autoload.php';
2 changes: 1 addition & 1 deletion components/ILIAS/Context/tests/ilServicesContextSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function suite(): self
{
$suite = new ilServicesContextSuite();

require_once("components/ILIAS/Context/tests/ilContextTest.php");
require_once(__DIR__ . "/ilContextTest.php");

$suite->addTestSuite("ilContextTest");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static function suite()
{
$suite = new ilServicesCopyWizardSuite();

require_once(__DIR__ . "/ilCopyWizardOptionsTest.php");

$suite->addTestSuite(ilCopyWizardOptionsTest::class);
return $suite;
}
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/EventHandling/tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use PHPUnit\Framework\TestCase;
use ILIAS\DI\Container;

require_once __DIR__ . "/../../../vendor/composer/vendor/autoload.php";
require_once __DIR__ . "/../../../../vendor/composer/vendor/autoload.php";

/**
* Test clipboard repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use PHPUnit\Framework\TestSuite;

require_once 'vendor/composer/vendor/autoload.php';
require_once __DIR__ . '/../../../../vendor/composer/vendor/autoload.php';

/**
* @author Alexander Killing <[email protected]>
Expand All @@ -31,7 +31,7 @@ public static function suite(): self
{
$suite = new self();

require_once("./components/ILIAS/EventHandling/tests/EventTest.php");
require_once(__DIR__ . "/EventTest.php");
$suite->addTestSuite("EventTest");

return $suite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function testDeliverWithNormalPathWhichShouldSucceed(): void
public function testDeliverWithDataPathWhichShouldSucceed(): void
{
$expectedHeader = 'X-Accel-Redirect';
$path = './public/data/path/to/what/ever';
$path = './data/path/to/what/ever';
$expectedPath = '/secured-data/path/to/what/ever';

$response = $this->getMockBuilder(ResponseInterface::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
$this->convert_to_ascii = $general_settings->isDownloadWithAsciiFileName();
$this->settings = $settings;
/** @noRector */
$this->white_list_default = include "../components/ILIAS/FileServices/defaults/default_whitelist.php";
$this->white_list_default = include __DIR__ . "/../defaults/default_whitelist.php";
$this->file_admin_ref_id = $this->determineFileAdminRefId();
$this->read();
}
Expand Down Expand Up @@ -122,7 +122,7 @@ private function readBlackList(): void
explode(",", $this->settings->get("suffix_custom_expl_black") ?? '')
);

$this->black_list_prohibited = array_filter($this->black_list_prohibited, fn ($item): bool => $item !== '');
$this->black_list_prohibited = array_filter($this->black_list_prohibited, fn($item): bool => $item !== '');
$this->black_list_overall = $this->black_list_prohibited;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testActualWhitelist(): void
->method('fetchAssoc')
->willReturn([]);

$default_whitelist = include __DIR__ . "/../../../components/ILIAS/FileServices/defaults/default_whitelist.php";
$default_whitelist = include __DIR__ . "/../defaults/default_whitelist.php";

// Blacklist
$settings_mock->expects($this->exactly(3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

use PHPUnit\Framework\TestSuite;

require_once 'vendor/composer/vendor/autoload.php';
require_once __DIR__ . '/../../../../vendor/composer/vendor/autoload.php';

class ilServicesFileSystemSuite extends TestSuite
{
public static function suite(): self
{
$suite = new self();

require_once("./components/ILIAS/FileSystem/tests/ilServicesFileSystemTest.php");
require_once(__DIR__ . "/ilServicesFileSystemTest.php");
$suite->addTestSuite("ilServicesFileSystemTest");

return $suite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use ILIAS\UI\Implementation\Component\BreadCrumbs\Breadcrumbs;

require_once('IliasMocks.php');
require_once(__DIR__ . "/../../../components/ILIAS/UI/tests/Base.php");
require_once(__DIR__ . "/../../../../components/ILIAS/UI/tests/Base.php");

/**
* This file is part of ILIAS, a powerful learning management system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace ILIAS\ResourceStorage\Resource;

require_once(__DIR__ . "/../AbstractBaseResourceBuilderTest.php");

use ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest;
use ILIAS\ResourceStorage\Collection\CollectionBuilder;
use ILIAS\ResourceStorage\Collection\ResourceCollection;
Expand Down Expand Up @@ -300,7 +302,7 @@ public function testByTitleDescSorting(): void
private function getFlatOrder(ResourceCollection $collection): array
{
return array_map(
fn (ResourceIdentification $rid): string => $rid->serialize(),
fn(ResourceIdentification $rid): string => $rid->serialize(),
$collection->getResourceIdentifications()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace ILIAS\ResourceStorage\Policy;

require_once(__DIR__ . "/../AbstractBaseResourceBuilderTest.php");

use ILIAS\MainMenu\Tests\DummyIDGenerator;
use ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest;
use ILIAS\ResourceStorage\Resource\ResourceBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace ILIAS\ResourceStorage\Resource;

require_once(__DIR__ . "/../AbstractBaseResourceBuilderTest.php");

use ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace ILIAS\ResourceStorage\Revision;

require_once(__DIR__ . "/../AbstractBaseTest.php");

use ILIAS\Filesystem\Filesystem;
use ILIAS\ResourceStorage\AbstractBaseTest;
use ILIAS\ResourceStorage\StorageHandler\FileSystemBased\FileSystemStorageHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@

namespace ILIAS\Tests\Setup\Objective;

require_once(__DIR__ . "/../Helper.php");

use ILIAS\Setup;
use ILIAS\Setup\Objective;
use ILIAS\Tests\Setup as Test;
use PHPUnit\Framework\TestCase;

class ObjectiveWithPreconditionsTest extends TestCase
{
use Test\Helper;
use \ILIAS\Tests\Setup\Helper;

protected Setup\Objective $objective;
protected Setup\Objective $precondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use PHPUnit\Framework\TestSuite;

require_once 'vendor/composer/vendor/autoload.php';
require_once __DIR__ . '/../../../../../vendor/composer/vendor/autoload.php';

/**
* @author Alexander Killing <[email protected]>
Expand All @@ -31,7 +31,7 @@ public static function suite(): self
{
$suite = new self();

require_once("./components/ILIAS/Style/Content/tests/ContentStyleStandardGUIRequestTest.php");
require_once(__DIR__ . "/ContentStyleStandardGUIRequestTest.php");
$suite->addTestSuite("ContentStyleStandardGUIRequestTest");

return $suite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ilSystemStyleDocumentationGUI
protected ILIAS\UI\Renderer $r;

public const SHOW_TREE = 'system_styles_show_tree';
public const DATA_PATH = '../components/ILIAS/Style/System/data/data.php';
public const DATA_PATH = __DIR__ . '/../../data/data.php';
public const ROOT_FACTORY_PATH = __DIR__ . '/../../../../../../components/ILIAS/Style/System/data/abstractDataFactory.php';

public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

declare(strict_types=1);

require_once('vendor/composer/vendor/autoload.php');
include_once('components/ILIAS/Style/System/tests/Exceptions/ilSystemStyleExceptionBaseUnit.php');

require_once(__DIR__ . '/../../../../../../vendor/composer/vendor/autoload.php');
require_once(__DIR__ . '/ilSystemStyleExceptionBaseUnit.php');

class ilSystemStyleColorExceptionTest extends ilSystemStyleExceptionBaseUnit
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

declare(strict_types=1);

require_once('vendor/composer/vendor/autoload.php');
include_once('components/ILIAS/Style/System/tests/Exceptions/ilSystemStyleExceptionBaseUnit.php');
require_once(__DIR__ . '/../../../../../../vendor/composer/vendor/autoload.php');
require_once(__DIR__ . '/ilSystemStyleExceptionBaseUnit.php');

class ilSystemStyleIconExceptionTest extends ilSystemStyleExceptionBaseUnit
{
protected function getClassName(): string
{
return 'ilSystemStyleIconException';
return ilSystemStyleIconException::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

declare(strict_types=1);

require_once('vendor/composer/vendor/autoload.php');
include_once('components/ILIAS/Style/System/tests/Exceptions/ilSystemStyleExceptionBaseUnit.php');
require_once(__DIR__ . '/../../../../../../vendor/composer/vendor/autoload.php');
require_once(__DIR__ . '/ilSystemStyleExceptionBaseUnit.php');

class ilSystemStyleMessageStackExceptionTest extends ilSystemStyleExceptionBaseUnit
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

declare(strict_types=1);

require_once('vendor/composer/vendor/autoload.php');
require_once(__DIR__ . '/../../../../../../vendor/composer/vendor/autoload.php');

class ilSystemStyleStyleScssFileTest extends ilSystemStyleBaseFS
{
protected ilSystemStyleScssSettingsFile $file;

protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -126,7 +128,7 @@ public function testGetItems(): void

public function testGetContent(): void
{
$expected_content = file_get_contents($this->file->getScssVariablesSettingsPath()."/variables1.scss");
$expected_content = file_get_contents($this->file->getScssVariablesSettingsPath() . "/variables1.scss");
$this->assertEquals($expected_content, $this->file->getContent());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ilSkinStyleContainerTest extends ilSystemStyleBaseFS
protected ilSkinStyle $style1;
protected ilSkinStyle $style2;
protected ilSkinFactory $factory;
protected string $skin_directory;

protected function setUp(): void
{
Expand Down Expand Up @@ -101,7 +102,7 @@ public function testAddStyle(): void

$container = $this->factory->skinStyleContainerFromId($this->skin->getId(), $this->message_stack);

$this->assertTrue(is_dir($this->skin_directory. '/style1/style1image'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1image'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1sound'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1font'));
$this->assertTrue(is_file($this->skin_directory . '/style1/style1.css'));
Expand Down Expand Up @@ -238,7 +239,7 @@ public function testAddSubstyle(): void

$new_sub_style->setSubstyleOf("style1");

$this->assertTrue(is_dir($this->skin_directory. '/style1/style1image'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1image'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1sound'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1font'));
$this->assertTrue(is_file($this->skin_directory . '/style1/style1.css'));
Expand All @@ -259,7 +260,7 @@ public function testAddSubstyle(): void
$this->assertCount(1, $container->getSkin()->getSubstylesOfStyle('style1'));


$this->assertTrue(is_dir($this->skin_directory. '/style1/style1image'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1image'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1sound'));
$this->assertTrue(is_dir($this->skin_directory . '/style1/style1font'));
$this->assertTrue(is_file($this->skin_directory . '/style1/style1.css'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class ilSystemStyleConfigMock extends ilSystemStyleConfig
{
protected string $default_skin_id = 'defaultSkin';
protected string $default_style_id = 'defaultStyle';
protected string $default_template_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/defaultSkin/template.xml';
protected string $delos_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/defaultSkin/defaultStyle';
protected string $rel_delos_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/defaultSkin/defaultStyle';
protected string $default_settings_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/defaultSkin/010-settings';
protected string $default_images_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/defaultSkin/images/';
protected string $default_fonts_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/defaultSkin/fonts/';
protected string $default_template_path = __DIR__ . '/../skins_temp/defaultSkin/template.xml';
protected string $delos_path = __DIR__ . '/../skins_temp/defaultSkin/defaultStyle';
protected string $rel_delos_path = __DIR__ . '/../skins_temp/defaultSkin/defaultStyle';
protected string $default_settings_path = __DIR__ . '/../skins_temp/defaultSkin/010-settings';
protected string $default_images_path = __DIR__ . '/../skins_temp/defaultSkin/images/';
protected string $default_fonts_path = __DIR__ . '/../skins_temp/defaultSkin/fonts/';
protected string $default_sounds_path = '';
protected string $customizing_skin_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/customSkins/';
public string $test_skin_original_path = '../components/ILIAS/Style/System/tests/fixtures/skins/';
public string $test_skin_temp_path = '../components/ILIAS/Style/System/tests/fixtures/skins_temp/';
protected string $customizing_skin_path = __DIR__ . '/../skins_temp/customSkins/';
public string $test_skin_original_path = __DIR__ . '/../skins/';
public string $test_skin_temp_path = __DIR__ . '/../skins_temp/';
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public static function suite(): TestSuite
{
$suite = new ilServicesStyleSystemSuite();

$base_dir = './components/ILIAS/Style/System/tests/';
$base_dir = __DIR__;
$rec_it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base_dir));

foreach ($rec_it as $file) {
if (strpos($file->getFilename(), 'Test.php') !== false) {
include_once($file->getPathname());
if (preg_match("#^[^.]+Test\.php$#", $file->getFilename())) {
require_once($file->getPathname());
$test_class = str_replace('.php', '', $file->getFilename());
$suite->addTestSuite($test_class);
}
Expand Down
6 changes: 3 additions & 3 deletions components/ILIAS/Style/tests/ilServicesStyleSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static function suite()
$suite = new ilServicesStyleSuite();

// add each test class of the component
include_once("./components/ILIAS/Style/System/tests/ilServicesStyleSystemSuite.php");
include_once("./components/ILIAS/Style/Content/tests/ilServicesStyleContentSuite.php");
$suite->addTestSuite("ilServicesStyleSystemSuite");
require_once(__DIR__ . "/../System/test/ilServicesStyleSystemSuite.php");
require_once(__DIR__ . "/../Content/test/ilServicesStyleContentSuite.php");
$suite->addTestSuite(ilServicesStyleSystemSuite::class);
$suite->addTestSuite("ilServicesStyleContentSuite");
return $suite;
}
Expand Down
Loading

0 comments on commit 9f6ece5

Please sign in to comment.