Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Plugin / DMU / Converter / Functions / NodeLoadTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Converter\Functions;
4
5 use Pharborist\Filter;
6 use Pharborist\Parser;
7
8 /**
9  * @group DMU.Converter.Functions
10  * @covers \Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions\NodeLoad
11  */
12 class NodeLoadTest extends FunctionCallModifierTestBase {
13
14   public function testRewriteWithNidOnly() {
15     $function_call = Parser::parseExpression('node_load(30)');
16     $rewritten = $this->plugin->rewrite($function_call, $this->target);
17     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
18     $this->assertEquals('\Drupal::entityManager()->getStorage(\'node\')->load(30)', $rewritten->getText());
19   }
20
21   public function testRewriteWithVid() {
22     $function_call = Parser::parseExpression('node_load(30, 32)');
23     $rewritten = $this->plugin->rewrite($function_call, $this->target);
24     $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
25     $this->assertEquals('\Drupal::entityManager()->getStorage(\'node\')->loadRevision(32)', $rewritten->getText());
26   }
27
28   /**
29    * This test is failing at the moment because for whatever reason,
30    * $snippet->children() is only fetching the first call to node_load().
31    */
32   public function _testRewriteWithCacheReset() {
33     $original = <<<'END'
34 node_load(30);
35 node_load(30, TRUE);
36 node_load(30, 32);
37 node_load(30, 32, TRUE);
38 END;
39     $expected = <<<'END'
40 \Drupal::entityManager()->getStorage('user')->load(30);
41 // FIXME: To reset the node cache, use EntityStorageInterface::resetCache().
42 \Drupal::entityManager()->getStorage('user')->load(30);
43 \Drupal::entityManager()->getStorage('user')->loadRevision(32);
44 // FIXME: To reset the node cache, use EntityStorageInterface::resetCache().
45 \Drupal::entityManager()->getStorage('user')->loadRevision(32);
46 END;
47     $snippet = Parser::parseSnippet($original);
48     $function_calls = $snippet->children(Filter::isFunctionCall('node_load'));
49     foreach ($function_calls as $function_call) {
50       $rewritten = $this->plugin->rewrite($function_call, $this->target);
51       $function_call->replaceWith($rewritten);
52     }
53     $this->assertEquals($expected, $snippet->getText());
54   }
55
56 }