FormExecuteHandlersTest.php in Drupal 7 to 8/9 Module Upgrader 8
File
tests/src/Unit/Plugin/DMU/Converter/Functions/FormExecuteHandlersTest.php
View source
<?php
namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Converter\Functions;
use Pharborist\Parser;
class FormExecuteHandlersTest extends FunctionCallModifierTestBase {
public function testRewriteValidate() {
$function_call = Parser::parseExpression('form_execute_handlers("validate", $form, $form_state)');
$rewritten = $this->plugin
->rewrite($function_call, $this->target);
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $rewritten);
$this
->assertEquals('\\Drupal::formBuilder()->executeValidateHandlers($form, $form_state)', $rewritten
->getText());
}
public function testRewriteSubmit() {
$function_call = Parser::parseExpression('form_execute_handlers("submit", $form, $form_state)');
$rewritten = $this->plugin
->rewrite($function_call, $this->target);
$this
->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $rewritten);
$this
->assertEquals('\\Drupal::formBuilder()->executeSubmitHandlers($form, $form_state)', $rewritten
->getText());
}
public function testRewriteInvalidHandlerType() {
$function_call = Parser::parseExpression('form_execute_handlers("blorfable", $form, $form_state)');
$rewritten = $this->plugin
->rewrite($function_call, $this->target);
$this
->assertNull($rewritten);
}
}