3 namespace Drupal\Tests\drupalmoduleupgrader\Unit;
5 use Drupal\drupalmoduleupgrader\Target;
6 use Pharborist\NodeCollection;
12 class TargetTest extends TestBase {
15 * @var \Drupal\drupalmoduleupgrader\IndexerInterface
19 public function setUp() {
22 $this->indexer = $this->getMockBuilder('\Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer\Functions')
23 ->disableOriginalConstructor()
27 ->get('plugin.manager.drupalmoduleupgrader.indexer')
28 ->method('createInstance')
30 ->willReturn($this->indexer);
34 * @expectedException \RuntimeException
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);
42 public function testID() {
43 $this->assertEquals('foo', $this->target->id());
46 public function testGetBasePath() {
47 $this->assertEquals($this->dir->url(), $this->target->getBasePath());
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'));
55 public function testGetFinder() {
56 $this->assertInstanceOf('\Symfony\Component\Finder\Finder', $this->target->getFinder());
60 * @depends testGetFinder
62 public function testFinder() {
63 $expected = $this->target->getFinder()
64 ->exclude('menu_example')
70 $this->assertEquals(array_keys(iterator_to_array($expected)), array_keys(iterator_to_array($this->target->getFinder())));
73 public function testGetIndexer() {
74 $this->assertSame($this->indexer, $this->target->getIndexer('function'));
77 public function testGetServices() {
78 $this->assertInstanceOf('\Doctrine\Common\Collections\ArrayCollection', $this->target->getServices());
81 public function testImplementsHook() {
82 $this->indexer->method('has')->willReturnMap([
83 ['hook_permission', TRUE],
84 ['hook_menu_alter', FALSE],
87 $this->assertTrue($this->target->implementsHook('permission'));
88 $this->assertFalse($this->target->implementsHook('menu_alter'));
92 * @expectedException \InvalidArgumentException
94 public function testExecuteUnimplementedHook() {
95 $this->indexer->method('has')->with('hook_menu')->willReturn(FALSE);
96 $this->target->executeHook('menu');
99 public function testExecuteHook() {
102 'title' => 'It worked!',
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);
110 $actual = $this->target->executeHook('menu');
111 $this->assertInternalType('array', $actual);
112 $this->assertSame($expected, $actual);