216e5d2014037a23022926b917909acb0bb14646
[yaffs-website] / web / core / modules / system / src / Tests / Form / AlterTest.php
1 <?php
2
3 namespace Drupal\system\Tests\Form;
4
5 use Drupal\Component\Utility\Xss;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9  * Tests hook_form_alter() and hook_form_FORM_ID_alter().
10  *
11  * @group Form
12  */
13 class AlterTest extends WebTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['block', 'form_test'];
21
22   /**
23    * Tests execution order of hook_form_alter() and hook_form_FORM_ID_alter().
24    */
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.
29     $expected = [
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.',
34     ];
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.');
37   }
38
39 }