You are here

public function FormStateTest::testRewriteValuesAsSetter in Drupal 7 to 8/9 Module Upgrader 8

File

tests/src/Unit/Plugin/DMU/Rewriter/FormStateTest.php, line 64

Class

FormStateTest
@group DMU.Rewriter @covers \Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\FormState

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Rewriter

Code

public function testRewriteValuesAsSetter() {

  /** @var \Pharborist\Operators\AssignNode $expr */
  $expr = Parser::parseExpression('$form_state["values"]["foo"] = "baz"');
  $rewritten = $this->plugin
    ->rewriteAsSetter($expr
    ->getLeftOperand(), 'values', $expr);
  $this
    ->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $rewritten);
  $this
    ->assertEquals('$form_state->setValue(["foo"], "baz")', $rewritten
    ->getText());
  $expr = Parser::parseExpression('$form_state["values"]["foo"][1] = "bar"');
  $rewritten = $this->plugin
    ->rewriteAsSetter($expr
    ->getLeftOperand(), 'values', $expr);
  $this
    ->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $rewritten);
  $this
    ->assertEquals('$form_state->setValue(["foo", 1], "bar")', $rewritten
    ->getText());
}