AlterTest.php

Same filename in this branch
  1. 9 core/modules/system/tests/src/Functional/Common/AlterTest.php
  2. 9 core/tests/Drupal/KernelTests/Core/Database/AlterTest.php
Same filename and directory in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Form/AlterTest.php
  2. 8.9.x core/modules/system/tests/src/Functional/Common/AlterTest.php
  3. 8.9.x core/tests/Drupal/KernelTests/Core/Database/AlterTest.php
  4. 10 core/modules/system/tests/src/Kernel/Common/AlterTest.php
  5. 10 core/modules/system/tests/src/Functional/Form/AlterTest.php
  6. 10 core/tests/Drupal/KernelTests/Core/Database/AlterTest.php
  7. 11.x core/modules/system/tests/src/Kernel/Common/AlterTest.php
  8. 11.x core/modules/system/tests/src/Functional/Form/AlterTest.php
  9. 11.x core/tests/Drupal/KernelTests/Core/Database/AlterTest.php

Namespace

Drupal\Tests\system\Functional\Form

File

core/modules/system/tests/src/Functional/Form/AlterTest.php

View source
<?php

namespace Drupal\Tests\system\Functional\Form;

use Drupal\Component\Utility\Xss;
use Drupal\Tests\BrowserTestBase;

/**
 * Tests hook_form_alter() and hook_form_FORM_ID_alter().
 *
 * @group Form
 */
class AlterTest extends BrowserTestBase {
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'block',
        'form_test',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests execution order of hook_form_alter() and hook_form_FORM_ID_alter().
     */
    public function testExecutionOrder() {
        $this->drupalGet('form-test/alter');
        // Ensure that the order is first by module, then for a given module, the
        // id-specific one after the generic one.
        $expected = [
            'block_form_form_test_alter_form_alter() executed.',
            'form_test_form_alter() executed.',
            'form_test_form_form_test_alter_form_alter() executed.',
            'system_form_form_test_alter_form_alter() executed.',
        ];
        $content = preg_replace('/\\s+/', ' ', Xss::filter($this->getSession()
            ->getPage()
            ->getContent(), []));
        $this->assertStringContainsString(implode(' ', $expected), $content, 'Form alter hooks executed in the expected order.');
    }

}

Classes

Title Deprecated Summary
AlterTest Tests hook_form_alter() and hook_form_FORM_ID_alter().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.