Skip to content

Commit

Permalink
Merge pull request #273 from marinaglancy/dataformat
Browse files Browse the repository at this point in the history
Validation of dataformat - custom plugin name lang string
  • Loading branch information
kabalin authored Apr 5, 2024
2 parents 6e33ca3 + 8cd51d0 commit f1624f3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/PluginValidate/Requirements/DataformatRequirements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* This file is part of the Moodle Plugin CI package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2024 Marina Glancy
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace MoodlePluginCI\PluginValidate\Requirements;

use MoodlePluginCI\PluginValidate\Finder\FileTokens;

/**
* Dataformat plugin requirements.
*/
class DataformatRequirements extends GenericRequirements
{
public function getRequiredStrings(): FileTokens
{
return FileTokens::create($this->getLangFile())->mustHave('dataformat');
}
}
1 change: 1 addition & 0 deletions src/PluginValidate/Requirements/RequirementsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function resolveRequirements(Plugin $plugin, $moodleVersion)
$map = [
'auth' => new AuthRequirements($plugin, $moodleVersion),
'block' => new BlockRequirements($plugin, $moodleVersion),
'dataformat' => new DataformatRequirements($plugin, $moodleVersion),
'filter' => new FilterRequirements($plugin, $moodleVersion),
'format' => new FormatRequirements($plugin, $moodleVersion),
'mod' => new ModuleRequirements($plugin, $moodleVersion),
Expand Down
52 changes: 52 additions & 0 deletions tests/PluginValidate/Requirements/DataformatRequirementsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* This file is part of the Moodle Plugin CI package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2024 Marina Glancy
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace MoodlePluginCI\Tests\PluginValidate;

use MoodlePluginCI\PluginValidate\Plugin;
use MoodlePluginCI\PluginValidate\Requirements\DataformatRequirements;
use MoodlePluginCI\PluginValidate\Requirements\RequirementsResolver;

class DataformatRequirementsTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DataformatRequirements
*/
private $requirements;

protected function setUp(): void
{
$this->requirements = new DataformatRequirements(new Plugin('dataformat_csv', 'dataformat', 'csv', ''), 29);
}

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

public function testResolveRequirements()
{
$resolver = new RequirementsResolver();

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

public function testGetRequiredStrings()
{
$fileToken = $this->requirements->getRequiredStrings();
$this->assertInstanceOf('MoodlePluginCI\PluginValidate\Finder\FileTokens', $fileToken);
$this->assertSame('lang/en/dataformat_csv.php', $fileToken->file);
}
}

0 comments on commit f1624f3

Please sign in to comment.