Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Plugin / DMU / Fixer / ImplementHookTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Fixer;
4
5 use Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer\ImplementHook;
6 use Drupal\Tests\drupalmoduleupgrader\Unit\TestBase;
7 use Pharborist\Filter;
8
9 /**
10  * @group DMU.Fixer
11  */
12 class ImplementHookTest extends TestBase {
13
14   public function test() {
15     eval('function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {}');
16
17     $config = [
18       'hook' => 'tokens',
19       'module' => 'system',
20     ];
21     $module_handler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface');
22     $plugin = new ImplementHook($config, uniqID(), [], $module_handler);
23     $plugin->setTarget($this->target);
24     $plugin->execute();
25
26     $module = $this->target->getPath('.module');
27     $function = $this->target->open($module)->children(Filter::isFunction('foo_tokens'))->get(0);
28     $this->assertInstanceOf('\Pharborist\Functions\FunctionDeclarationNode', $function);
29     $this->assertEquals('foo_tokens', $function->getName()->getText());
30
31     $parameters = $function->getParameters();
32     $this->assertCount(4, $parameters);
33
34     $this->assertNull($parameters[0]->getTypeHint());
35     $this->assertEquals('type', $parameters[0]->getName());
36     $this->assertNull($parameters[0]->getValue());
37
38     $this->assertNull($parameters[1]->getTypeHint());
39     $this->assertEquals('tokens', $parameters[1]->getName());
40     $this->assertNull($parameters[1]->getValue());
41
42     $this->assertInstanceOf('\Pharborist\TokenNode', $parameters[2]->getTypeHint());
43     $this->assertSame(T_ARRAY, $parameters[2]->getTypeHint()->getType());
44     $this->assertEquals('data', $parameters[2]->getName());
45     $this->assertInstanceOf('\Pharborist\Types\ArrayNode', $parameters[2]->getValue());
46
47     $this->assertInstanceOf('\Pharborist\TokenNode', $parameters[3]->getTypeHint());
48     $this->assertSame(T_ARRAY, $parameters[3]->getTypeHint()->getType());
49     $this->assertEquals('options', $parameters[3]->getName());
50     $this->assertInstanceOf('\Pharborist\Types\ArrayNode', $parameters[3]->getValue());
51   }
52
53 }