3 namespace Drupal\Tests\drupalmoduleupgrader\Unit;
5 use Drupal\drupalmoduleupgrader\Issue;
11 class IssueTest extends TestBase {
14 * @var \Drupal\drupalmoduleupgrader\IssueInterface
18 public function setUp() {
20 $this->issue = new Issue($this->target, 'Foobaz');
23 public function testTitle() {
24 $this->issue->setTitle('Foobar');
25 $this->assertEquals('Foobar', $this->issue->getTitle());
28 public function testSummary() {
29 $this->issue->setSummary('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.');
30 $this->assertEquals("<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>\n", $this->issue->getSummary());
33 public function testDocumentation() {
34 $this->issue->addDocumentation('http://www.google.com', 'Just Google it, baby!');
35 $documentation = $this->issue->getDocumentation();
36 $this->assertInternalType('array', $documentation);
37 $this->assertCount(1, $documentation);
38 $this->assertArrayHasKey('url', $documentation[0]);
39 $this->assertArrayHasKey('title', $documentation[0]);
40 $this->assertEquals('http://www.google.com', $documentation[0]['url']);
41 $this->assertEquals('Just Google it, baby!', $documentation[0]['title']);
44 public function testViolationsAndDetectors() {
45 $analyzer = $this->getMockBuilder('\Drupal\drupalmoduleupgrader\AnalyzerBase')->disableOriginalConstructor()->getMock();
46 $analyzer->method('getPluginId')->willReturn('blarg');
47 $this->issue->addAffectedFile($this->dir->getChild('foo.info')->url(), $analyzer);
53 * Implements hook_permission().
55 function foo_permission() {
59 $this->dir->getChild('foo.module')->setContent($code);
62 ->open($this->dir->getChild('foo.module')->url())
63 ->children(Filter::isFunction('foo_permission'))
65 $this->issue->addViolation($node, $analyzer);
67 $violations = $this->issue->getViolations();
68 $this->assertInternalType('array', $violations);
69 $this->assertCount(2, $violations);
70 $this->assertArrayHasKey('file', $violations[0]);
71 $this->assertArrayNotHasKey('line_number', $violations[0]);
72 $this->assertEquals($this->dir->getChild('foo.info')->url(), $violations[0]['file']);
73 $this->assertArrayHasKey('file', $violations[1]);
74 $this->assertArrayHasKey('line_number', $violations[1]);
75 $this->assertEquals($this->dir->getChild('foo.module')->url(), $violations[1]['file']);
77 $detectors = $this->issue->getDetectors();
78 $this->assertInternalType('array', $detectors);
79 $this->assertCount(1, $detectors);
80 $this->assertEquals($analyzer->getPluginId(), $detectors[0]);
83 public function testFixes() {
84 $this->issue->addFix('foo');
85 $this->issue->addFix('baz', ['bar' => 'wambooli']);
87 $fixes = $this->issue->getFixes();
88 $this->assertInternalType('array', $fixes);
89 $this->assertCount(2, $fixes);
90 $this->assertEquals(['_plugin_id' => 'foo'], $fixes[0]);
91 $this->assertEquals(['_plugin_id' => 'baz', 'bar' => 'wambooli'], $fixes[1]);