3 namespace Drupal\system\Tests\Form;
5 use Drupal\Component\Utility\Xss;
6 use Drupal\simpletest\WebTestBase;
9 * Tests hook_form_alter() and hook_form_FORM_ID_alter().
13 class AlterTest extends WebTestBase {
20 public static $modules = ['block', 'form_test'];
23 * Tests execution order of hook_form_alter() and hook_form_FORM_ID_alter().
25 public function testExecutionOrder() {
26 $this->drupalGet('form-test/alter');
27 // Ensure that the order is first by module, then for a given module, the
28 // id-specific one after the generic one.
30 'block_form_form_test_alter_form_alter() executed.',
31 'form_test_form_alter() executed.',
32 'form_test_form_form_test_alter_form_alter() executed.',
33 'system_form_form_test_alter_form_alter() executed.',
35 $content = preg_replace('/\s+/', ' ', Xss::filter($this->content, []));
36 $this->assert(strpos($content, implode(' ', $expected)) !== FALSE, 'Form alter hooks executed in the expected order.');