public function GenericTest::testRewriteFieldLookup in Drupal 7 to 8/9 Module Upgrader 8
File
- tests/
src/ Unit/ Plugin/ DMU/ Rewriter/ GenericTest.php, line 72
Class
- GenericTest
- @group DMU.Rewriter @covers \Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\Generic
Namespace
Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\RewriterCode
public function testRewriteFieldLookup() {
/** @var \Pharborist\ArrayLookupNode $lookup */
$lookup = Parser::parseExpression('$node->field_foo[LANGUAGE_NONE][0]["value"]');
$rewritten = GenericRewriter::rewriteFieldLookup($lookup);
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectPropertyNode', $rewritten);
$this
->assertEquals('$node->field_foo[0]->value', $rewritten
->getText());
$lookup = Parser::parseExpression('$node->field_foo[\\Drupal\\Core\\Language\\Language::LANGCODE_NOT_SPECIFIED][0]["value"]');
$rewritten = GenericRewriter::rewriteFieldLookup($lookup);
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectPropertyNode', $rewritten);
$this
->assertEquals('$node->field_foo[0]->value', $rewritten
->getText());
$lookup = Parser::parseExpression('$node->field_foo["und"][0]["value"]');
$rewritten = GenericRewriter::rewriteFieldLookup($lookup);
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectPropertyNode', $rewritten);
$this
->assertEquals('$node->field_foo[0]->value', $rewritten
->getText());
$lookup = Parser::parseExpression('$node->field_foo["en"][0]["value"]');
$rewritten = GenericRewriter::rewriteFieldLookup($lookup);
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectPropertyNode', $rewritten);
$this
->assertEquals('$node->getTranslation("en")->field_foo[0]->value', $rewritten
->getText());
$lookup = Parser::parseExpression('$node->field_foo["und"][2]["wambooli"]');
$rewritten = GenericRewriter::rewriteFieldLookup($lookup);
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectPropertyNode', $rewritten);
$this
->assertEquals('$node->field_foo[2]->wambooli', $rewritten
->getText());
}