class PageTest
Same name in this branch
- 9 core/modules/views/tests/src/Unit/Plugin/display/PageTest.php \Drupal\Tests\views\Unit\Plugin\display\PageTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Unit/Plugin/display/PageTest.php \Drupal\Tests\views\Unit\Plugin\display\PageTest
- 11.x core/modules/system/tests/src/Functional/Batch/PageTest.php \Drupal\Tests\system\Functional\Batch\PageTest
- 10 core/modules/views/tests/src/Unit/Plugin/display/PageTest.php \Drupal\Tests\views\Unit\Plugin\display\PageTest
- 10 core/modules/system/tests/src/Functional/Batch/PageTest.php \Drupal\Tests\system\Functional\Batch\PageTest
- 8.9.x core/modules/views/tests/src/Unit/Plugin/display/PageTest.php \Drupal\Tests\views\Unit\Plugin\display\PageTest
- 8.9.x core/modules/system/tests/src/Functional/Batch/PageTest.php \Drupal\Tests\system\Functional\Batch\PageTest
Tests the content of the progress page.
@group Batch
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\system\Functional\Batch\PageTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of PageTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Batch/ PageTest.php, line 12
Namespace
Drupal\Tests\system\Functional\BatchView source
class PageTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'batch_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that the batch API progress page uses the correct theme.
*/
public function testBatchProgressPageTheme() {
// Make sure that the page which starts the batch (an administrative page)
// is using a different theme than would normally be used by the batch API.
$this->container
->get('theme_installer')
->install([
'claro',
'olivero',
]);
$this->config('system.theme')
->set('default', 'olivero')
->set('admin', 'claro')
->save();
// Log in as an administrator who can see the administrative theme.
$admin_user = $this->drupalCreateUser([
'view the administration theme',
]);
$this->drupalLogin($admin_user);
// Visit an administrative page that runs a test batch, and check that the
// theme that was used during batch execution (which the batch callback
// function saved as a variable) matches the theme used on the
// administrative page.
$this->drupalGet('admin/batch-test/test-theme');
// The stack should contain the name of the theme used on the progress
// page.
$this->assertEquals([
'claro',
], batch_test_stack(), 'A progressive batch correctly uses the theme of the page that started the batch.');
}
/**
* Tests that the batch API progress page shows the title correctly.
*/
public function testBatchProgressPageTitle() {
// Visit an administrative page that runs a test batch, and check that the
// title shown during batch execution (which the batch callback function
// saved as a variable) matches the theme used on the administrative page.
// Run initial step only first.
$this->maximumMetaRefreshCount = 0;
$this->drupalGet('batch-test/test-title');
$this->assertSession()
->pageTextContains('Batch Test');
// Leave the batch process running.
$this->maximumMetaRefreshCount = NULL;
$this->drupalGet('batch-test/test-title');
// The stack should contain the title shown on the progress page.
$this->assertEquals([
'Batch Test',
], batch_test_stack(), 'The batch title is shown on the batch page.');
$this->assertSession()
->pageTextContains('Redirection successful.');
}
/**
* Tests that the progress messages are correct.
*/
public function testBatchProgressMessages() {
// Go to the initial step only.
$this->maximumMetaRefreshCount = 0;
$this->drupalGet('batch-test/test-title');
// Check that the initial progress message appears correctly and is not
// double escaped.
$this->assertSession()
->responseContains('<div class="progress__description">Initializing.<br /> </div>');
$this->assertSession()
->responseNotContains('&nbsp;');
// Now also go to the next step.
$this->maximumMetaRefreshCount = 1;
$this->drupalGet('batch-test/test-title');
// Check that the progress message for second step appears correctly.
$this->assertSession()
->responseContains('<div class="progress__description">Completed 1 of 1.</div>');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.