Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Plugin / DMU / Analyzer / HookPermissionTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Analyzer;
4
5 use Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer\Functions;
6
7 /**
8  * @group DMU.Analyzer
9  * @covers \Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer\HookPermission
10  *
11  * @todo Add a test for dynamic permissions. Drupal 8 still uses
12  * hook_permission() for this, so dynamic permissions should not result in
13  * an issue being flagged.
14  */
15 class HookPermissionTest extends AnalyzerTestBase {
16
17   public function setUp() {
18     parent::setUp();
19
20     $code = <<<'END'
21 <?php
22
23 /**
24  * Implements hook_permission().
25  */
26 function foo_permission() {
27   return array();
28 }
29 END;
30     $this->dir->getChild('foo.module')->setContent($code);
31
32     $indexer = new Functions([], 'function', [], $this->db, $this->target);
33     $indexer->build();
34     $this->container
35       ->get('plugin.manager.drupalmoduleupgrader.indexer')
36       ->method('createInstance')
37       ->with('function')
38       ->willReturn($indexer);
39
40     $this->analyzer = $this->getPlugin();
41   }
42
43   public function test() {
44     $issues = $this->analyzer->analyze($this->target);
45     $this->assertInternalType('array', $issues);
46     $this->assertNotEmpty($issues);
47     $this->assertIssueDefaults($issues[0]);
48     $this->assertCount(1, $issues[0]->getViolations());
49     $fixes = $issues[0]->getFixes();
50     $this->assertNotEmpty($fixes);
51   }
52
53 }