3 namespace Drupal\Tests\system\Functional\Batch;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the content of the progress page.
12 class PageTest extends BrowserTestBase {
19 public static $modules = ['batch_test'];
22 * Tests that the batch API progress page uses the correct theme.
24 public function testBatchProgressPageTheme() {
25 // Make sure that the page which starts the batch (an administrative page)
26 // is using a different theme than would normally be used by the batch API.
27 $this->container->get('theme_handler')->install(['seven', 'bartik']);
28 $this->config('system.theme')
29 ->set('default', 'bartik')
30 ->set('admin', 'seven')
33 // Log in as an administrator who can see the administrative theme.
34 $admin_user = $this->drupalCreateUser(['view the administration theme']);
35 $this->drupalLogin($admin_user);
36 // Visit an administrative page that runs a test batch, and check that the
37 // theme that was used during batch execution (which the batch callback
38 // function saved as a variable) matches the theme used on the
39 // administrative page.
40 $this->drupalGet('admin/batch-test/test-theme');
41 // The stack should contain the name of the theme used on the progress
43 $this->assertEqual(batch_test_stack(), ['seven'], 'A progressive batch correctly uses the theme of the page that started the batch.');
47 * Tests that the batch API progress page shows the title correctly.
49 public function testBatchProgressPageTitle() {
50 // Visit an administrative page that runs a test batch, and check that the
51 // title shown during batch execution (which the batch callback function
52 // saved as a variable) matches the theme used on the administrative page.
53 $this->drupalGet('batch-test/test-title');
54 // The stack should contain the title shown on the progress page.
55 $this->assertEqual(batch_test_stack(), ['Batch Test'], 'The batch title is shown on the batch page.');
56 $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
60 * Tests that the progress messages are correct.
62 public function testBatchProgressMessages() {
63 // Go to the initial step only.
64 $this->maximumMetaRefreshCount = 0;
65 $this->drupalGet('batch-test/test-title');
66 $this->assertRaw('<div class="progress__description">Initializing.<br /> </div>', 'Initial progress message appears correctly.');
67 $this->assertNoRaw('&nbsp;', 'Initial progress message is not double escaped.');
68 // Now also go to the next step.
69 $this->maximumMetaRefreshCount = 1;
70 $this->drupalGet('batch-test/test-title');
71 $this->assertRaw('<div class="progress__description">Completed 1 of 1.</div>', 'Progress message for second step appears correctly.');