You are here

public function HookToYAMLTest::test in Drupal 7 to 8/9 Module Upgrader 8

File

tests/src/Unit/Plugin/DMU/Fixer/HookToYAMLTest.php, line 14

Class

HookToYAMLTest
@group DMU.Fixer

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Fixer

Code

public function test() {
  $permissions = [
    'bazify' => [
      'title' => 'Do snazzy bazzy things',
    ],
  ];
  $indexer = $this
    ->getMockBuilder('\\Drupal\\drupalmoduleupgrader\\Plugin\\DMU\\Indexer\\Functions')
    ->disableOriginalConstructor()
    ->getMock();
  $indexer
    ->method('has')
    ->with('hook_permission')
    ->willReturn(TRUE);
  $indexer
    ->method('hasExecutable')
    ->with('hook_permission')
    ->willReturn(TRUE);
  $indexer
    ->method('execute')
    ->with('hook_permission')
    ->willReturn($permissions);
  $this->container
    ->get('plugin.manager.drupalmoduleupgrader.indexer')
    ->method('createInstance')
    ->with('function')
    ->willReturn($indexer);
  $config = [
    'hook' => 'permission',
    'destination' => '~/foo.permissions.yml',
  ];
  $plugin = new HookToYAML($config, uniqid(), []);
  $plugin
    ->setTarget($this->target);
  $plugin
    ->execute();
  $url = $this->dir
    ->getChild('foo.permissions.yml')
    ->url();
  $this
    ->assertFileExists($url);
  $this
    ->assertSame(YAML::encode($permissions), file_get_contents($url));
}