Skip to content

Commit

Permalink
Adjust filter plugin requirements to comply with 4.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Oct 8, 2024
1 parent f722b93 commit 43dda63
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
19 changes: 15 additions & 4 deletions src/PluginValidate/Requirements/FilterRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@ class FilterRequirements extends GenericRequirements
{
public function getRequiredFiles(): array
{
return array_merge(parent::getRequiredFiles(), [
'filter.php',
]);
$files = [];
if ($this->moodleVersion >= 405) {
$files[] = 'classes/text_filter.php';
} else {
// This must exist in 405 if plugin supports older version, but we don't identify support range to validate.
$files[] = 'filter.php';
}

return array_merge(parent::getRequiredFiles(), $files);
}

public function getRequiredClasses(): array
{
if ($this->moodleVersion <= 404) {
// Really we should have a class for the filter.php file, but we don't identify support range to validate.
return [];
}

return [
FileTokens::create('filter.php')->mustHave('filter_' . $this->plugin->name),
FileTokens::create('classes/text_filter.php')->mustHave("filter_{$this->plugin->name}\\text_filter"),
];
}

Expand Down
31 changes: 22 additions & 9 deletions tests/PluginValidate/Requirements/FilterRequirementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class FilterRequirementsTest extends \PHPUnit\Framework\TestCase

protected function setUp(): void
{
$this->requirements = new FilterRequirements(new Plugin('filter_activitynames', 'filter', 'activitynames', ''), 29);
$this->requirements404 = new FilterRequirements(new Plugin('filter_activitynames', 'filter', 'activitynames', ''), 404);
$this->requirements = new FilterRequirements(new Plugin('filter_activitynames', 'filter', 'activitynames', ''), 405);
}

protected function tearDown(): void
{
$this->requirements = null;
$this->requirements404 = null;
$this->requirements = null;
}

public function testResolveRequirements()
Expand All @@ -39,16 +41,27 @@ public function testResolveRequirements()

$this->assertInstanceOf(
'MoodlePluginCI\PluginValidate\Requirements\FilterRequirements',
$resolver->resolveRequirements(new Plugin('', 'filter', '', ''), 29)
$resolver->resolveRequirements(new Plugin('', 'filter', '', ''), 404)
);
}

public function testGetRequiredFiles404()
{
$files = $this->requirements404->getRequiredFiles();

$this->assertTrue(in_array('filter.php', $files, true));
$this->assertFalse(in_array('classes/text_filter.php', $files, true));
foreach ($files as $file) {
$this->assertIsString($file);
}
}

public function testGetRequiredFiles()
{
$files = $this->requirements->getRequiredFiles();

$this->assertNotEmpty($files);
$this->assertTrue(in_array('filter.php', $files, true));
$this->assertFalse(in_array('filter.php', $files, true));
$this->assertTrue(in_array('classes/text_filter.php', $files, true));
foreach ($files as $file) {
$this->assertIsString($file);
}
Expand All @@ -58,10 +71,10 @@ public function testGetRequiredClasses()
{
$classes = $this->requirements->getRequiredClasses();

$this->assertNotEmpty($classes);
foreach ($classes as $class) {
$this->assertInstanceOf('MoodlePluginCI\PluginValidate\Finder\FileTokens', $class);
}
$this->assertCount(1, $classes);
$class = reset($classes);
$this->assertInstanceOf('MoodlePluginCI\PluginValidate\Finder\FileTokens', $class);
$this->assertSame('classes/text_filter.php', $class->file);
}

public function testGetRequiredStrings()
Expand Down

0 comments on commit 43dda63

Please sign in to comment.