You are here

public function IssueTest::testViolationsAndDetectors in Drupal 7 to 8/9 Module Upgrader 8

File

tests/src/Unit/IssueTest.php, line 44

Class

IssueTest
@group DMU

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit

Code

public function testViolationsAndDetectors() {
  $analyzer = $this
    ->getMockBuilder('\\Drupal\\drupalmoduleupgrader\\AnalyzerBase')
    ->disableOriginalConstructor()
    ->getMock();
  $analyzer
    ->method('getPluginId')
    ->willReturn('blarg');
  $this->issue
    ->addAffectedFile($this->dir
    ->getChild('foo.info')
    ->url(), $analyzer);
  $code = <<<'END'
<?php

/**
 * Implements hook_permission().
 */
function foo_permission() {
  return array();
}
END;
  $this->dir
    ->getChild('foo.module')
    ->setContent($code);
  $node = $this->target
    ->open($this->dir
    ->getChild('foo.module')
    ->url())
    ->children(Filter::isFunction('foo_permission'))
    ->get(0);
  $this->issue
    ->addViolation($node, $analyzer);
  $violations = $this->issue
    ->getViolations();
  $this
    ->assertInternalType('array', $violations);
  $this
    ->assertCount(2, $violations);
  $this
    ->assertArrayHasKey('file', $violations[0]);
  $this
    ->assertArrayNotHasKey('line_number', $violations[0]);
  $this
    ->assertEquals($this->dir
    ->getChild('foo.info')
    ->url(), $violations[0]['file']);
  $this
    ->assertArrayHasKey('file', $violations[1]);
  $this
    ->assertArrayHasKey('line_number', $violations[1]);
  $this
    ->assertEquals($this->dir
    ->getChild('foo.module')
    ->url(), $violations[1]['file']);
  $detectors = $this->issue
    ->getDetectors();
  $this
    ->assertInternalType('array', $detectors);
  $this
    ->assertCount(1, $detectors);
  $this
    ->assertEquals($analyzer
    ->getPluginId(), $detectors[0]);
}