Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / TargetTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit;
4
5 use Drupal\drupalmoduleupgrader\Target;
6 use Pharborist\NodeCollection;
7 use Pharborist\Parser;
8
9 /**
10  * @group DMU
11  */
12 class TargetTest extends TestBase {
13
14   /**
15    * @var \Drupal\drupalmoduleupgrader\IndexerInterface
16    */
17   protected $indexer;
18
19   public function setUp() {
20     parent::setUp();
21
22     $this->indexer = $this->getMockBuilder('\Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer\Functions')
23       ->disableOriginalConstructor()
24       ->getMock();
25
26     $this->container
27       ->get('plugin.manager.drupalmoduleupgrader.indexer')
28       ->method('createInstance')
29       ->with('function')
30       ->willReturn($this->indexer);
31   }
32
33   /**
34    * @expectedException \RuntimeException
35    */
36   public function testInvalidBasePath() {
37     // Trying to create a target with an invalid path should instantly
38     // throw an exception.
39     new Target('foobar', $this->container);
40   }
41
42   public function testID() {
43     $this->assertEquals('foo', $this->target->id());
44   }
45
46   public function testGetBasePath() {
47     $this->assertEquals($this->dir->url(), $this->target->getBasePath());
48   }
49
50   public function testGetPath() {
51     $this->assertEquals($this->dir->getChild('foo.module')->url(), $this->target->getPath('.module'));
52     $this->assertEquals($this->dir->getChild('foo.install')->url(), $this->target->getPath('.install'));
53   }
54
55   public function testGetFinder() {
56     $this->assertInstanceOf('\Symfony\Component\Finder\Finder', $this->target->getFinder());
57   }
58
59   /**
60    * @depends testGetFinder
61    */
62   public function testFinder() {
63     $expected = $this->target->getFinder()
64       ->exclude('menu_example')
65       ->name('*.module')
66       ->name('*.install')
67       ->name('*.inc')
68       ->name('*.test')
69       ->name('*.php');
70     $this->assertEquals(array_keys(iterator_to_array($expected)), array_keys(iterator_to_array($this->target->getFinder())));
71   }
72
73   public function testGetIndexer() {
74     $this->assertSame($this->indexer, $this->target->getIndexer('function'));
75   }
76
77   public function testGetServices() {
78     $this->assertInstanceOf('\Doctrine\Common\Collections\ArrayCollection', $this->target->getServices());
79   }
80
81   public function testImplementsHook() {
82     $this->indexer->method('has')->willReturnMap([
83       ['hook_permission', TRUE],
84       ['hook_menu_alter', FALSE],
85     ]);
86
87     $this->assertTrue($this->target->implementsHook('permission'));
88     $this->assertFalse($this->target->implementsHook('menu_alter'));
89   }
90
91   /**
92    * @expectedException \InvalidArgumentException
93    */
94   public function testExecuteUnimplementedHook() {
95     $this->indexer->method('has')->with('hook_menu')->willReturn(FALSE);
96     $this->target->executeHook('menu');
97   }
98
99   public function testExecuteHook() {
100     $expected = [
101       'foo/baz' => [
102         'title' => 'It worked!',
103       ],
104     ];
105
106     $this->indexer->method('has')->with('hook_menu')->willReturn(TRUE);
107     $this->indexer->method('hasExecutable')->with('hook_menu')->willReturn(TRUE);
108     $this->indexer->method('execute')->with('hook_menu')->willReturn($expected);
109
110     $actual = $this->target->executeHook('menu');
111     $this->assertInternalType('array', $actual);
112     $this->assertSame($expected, $actual);
113   }
114
115 }