diff --git a/src/PluginValidate/Requirements/FilterRequirements.php b/src/PluginValidate/Requirements/FilterRequirements.php index cbed68db..8381af0b 100644 --- a/src/PluginValidate/Requirements/FilterRequirements.php +++ b/src/PluginValidate/Requirements/FilterRequirements.php @@ -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"), ]; } diff --git a/tests/PluginValidate/Requirements/FilterRequirementsTest.php b/tests/PluginValidate/Requirements/FilterRequirementsTest.php index de2b2d4d..0739676c 100644 --- a/tests/PluginValidate/Requirements/FilterRequirementsTest.php +++ b/tests/PluginValidate/Requirements/FilterRequirementsTest.php @@ -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() @@ -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()