Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Plugin / DMU / Fixer / DisableTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Fixer;
4
5 use Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer\Disable;
6 use Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer\FunctionCalls;
7 use Drupal\Tests\drupalmoduleupgrader\Unit\TestBase;
8
9 /**
10  * @group DMU.Fixer
11  *
12  * @TODO Add a test of the 'where' configuration option.
13  */
14 class DisableTest extends TestBase {
15
16   public function test() {
17     $code = <<<'END'
18 <?php
19
20 variable_get('foo');
21 END;
22     $this->dir->getChild('foo.module')->setContent(rtrim($code));
23
24     $indexer = new FunctionCalls([], 'function', ['exclude' => []], $this->db, $this->target);
25     $indexer->build();
26
27     $this
28       ->container
29       ->get('plugin.manager.drupalmoduleupgrader.indexer')
30       ->method('createInstance')
31       ->with('function_call')
32       ->willReturn($indexer);
33
34     $config = [
35       'type' => 'function_call',
36       'id' => 'variable_get',
37       'note' => 'This is no longer kosher!',
38     ];
39     $plugin = new Disable($config, uniqID(), []);
40     $plugin->setTarget($this->target);
41     $plugin->execute();
42
43     $expected = <<<END
44 <?php
45
46 // This is no longer kosher!
47 // variable_get('foo');
48 END;
49
50     // trim() makes the test pass. Go figure.
51     $this->assertEquals($expected, trim($this->dir->getChild('foo.module')->getContent()));
52   }
53
54 }