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 3, 2024
1 parent f722b93 commit 1c0d4a2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
17 changes: 13 additions & 4 deletions src/PluginValidate/Requirements/FilterRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ class FilterRequirements extends GenericRequirements
{
public function getRequiredFiles(): array
{
return array_merge(parent::getRequiredFiles(), [
'filter.php',
]);
$files = ['filter.php'];
if ($this->moodleVersion >= 45) {
$files[] = 'classes/text_filter.php';
}

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

public function getRequiredClasses(): array
{
if ($this->moodleVersion <= 44) {
return [
FileTokens::create('filter.php')->mustHave('filter_' . $this->plugin->name),
];
}

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
39 changes: 31 additions & 8 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->requirements44 = new FilterRequirements(new Plugin('filter_activitynames', 'filter', 'activitynames', ''), 44);
$this->requirements = new FilterRequirements(new Plugin('filter_activitynames', 'filter', 'activitynames', ''), 45);
}

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

public function testResolveRequirements()
Expand All @@ -39,29 +41,50 @@ public function testResolveRequirements()

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

public function testGetRequiredFiles44()
{
$files = $this->requirements44->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->assertTrue(in_array('classes/text_filter.php', $files, true));
foreach ($files as $file) {
$this->assertIsString($file);
}
}

public function testGetRequiredClasses44()
{
$classes = $this->requirements44->getRequiredClasses();

$this->assertCount(1, $classes);
$class = reset($classes);
$this->assertInstanceOf('MoodlePluginCI\PluginValidate\Finder\FileTokens', $class);
$this->assertSame('filter.php', $class->file);
}

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 1c0d4a2

Please sign in to comment.