class BlockFormInBlockTest
Same name and namespace in other branches
- 11.x core/modules/block/tests/src/Functional/BlockFormInBlockTest.php \Drupal\Tests\block\Functional\BlockFormInBlockTest
- 10 core/modules/block/tests/src/Functional/BlockFormInBlockTest.php \Drupal\Tests\block\Functional\BlockFormInBlockTest
- 8.9.x core/modules/block/tests/src/Functional/BlockFormInBlockTest.php \Drupal\Tests\block\Functional\BlockFormInBlockTest
Tests form in block caching.
@group block
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\block\Functional\BlockFormInBlockTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of BlockFormInBlockTest
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockFormInBlockTest.php, line 13
Namespace
Drupal\Tests\block\FunctionalView source
class BlockFormInBlockTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'block',
'block_test',
'test_page_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Enable our test block.
$this->drupalPlaceBlock('test_form_in_block');
}
/**
* Tests to see if form in block's redirect isn't cached.
*/
public function testCachePerPage() {
$form_values = [
'email' => 'test@example.com',
];
// Go to "test-page" and test if the block is enabled.
$this->drupalGet('test-page');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Your .com email address.');
// Make sure that we're currently still on /test-page after submitting the
// form.
$this->submitForm($form_values, 'Submit');
$this->assertSession()
->addressEquals('test-page');
$this->assertSession()
->pageTextContains('Your email address is test@example.com');
// Go to a different page and see if the block is enabled there as well.
$this->drupalGet('test-render-title');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Your .com email address.');
// Make sure that submitting the form didn't redirect us to the first page
// we submitted the form from after submitting the form from
// /test-render-title.
$this->submitForm($form_values, 'Submit');
$this->assertSession()
->addressEquals('test-render-title');
$this->assertSession()
->pageTextContains('Your email address is test@example.com');
}
/**
* Tests the actual placeholders.
*/
public function testPlaceholders() {
$this->drupalGet('test-multiple-forms');
$placeholder = 'form_action_' . Crypt::hashBase64('Drupal\\Core\\Form\\FormBuilder::prepareForm');
$this->assertSession()
->pageTextContains('Form action: ' . $placeholder);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.