public function FormStateTest::testRewriteValuesAsGetter in Drupal 7 to 8/9 Module Upgrader 8
File
- tests/
src/ Unit/ Plugin/ DMU/ Rewriter/ FormStateTest.php, line 33
Class
- FormStateTest
- @group DMU.Rewriter @covers \Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\FormState
Namespace
Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\RewriterCode
public function testRewriteValuesAsGetter() {
$expr = Parser::parseExpression('$form_state["values"]');
$rewritten = $this->plugin
->rewriteAsGetter($expr, 'values');
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $rewritten);
$this
->assertEquals('$form_state->getValues()', $rewritten
->getText());
$expr = Parser::parseExpression('$form_state["values"]["foo"]');
$rewritten = $this->plugin
->rewriteAsGetter($expr, 'values');
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $rewritten);
$this
->assertEquals('$form_state->getValue(["foo"])', $rewritten
->getText());
$expr = Parser::parseExpression('$form_state["values"]["foo"][0]');
$rewritten = $this->plugin
->rewriteAsGetter($expr, 'values');
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $rewritten);
$this
->assertEquals('$form_state->getValue(["foo", 0])', $rewritten
->getText());
}