b1e46a2ea5fb8a23da871f5ca9e0e426e35d4af3
[yaffs-website] / web / core / modules / system / tests / src / Functional / Batch / PageTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Batch;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the content of the progress page.
9  *
10  * @group Batch
11  */
12 class PageTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['batch_test'];
20
21   /**
22    * Tests that the batch API progress page uses the correct theme.
23    */
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')
31       ->save();
32
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
42     // page.
43     $this->assertEqual(batch_test_stack(), ['seven'], 'A progressive batch correctly uses the theme of the page that started the batch.');
44   }
45
46   /**
47    * Tests that the batch API progress page shows the title correctly.
48    */
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     // Run initial step only first.
54     $this->maximumMetaRefreshCount = 0;
55     $this->drupalGet('batch-test/test-title');
56     $this->assertText('Batch Test', 'The test is in the html output.');
57
58     // Leave the batch process running.
59     $this->maximumMetaRefreshCount = NULL;
60     $this->drupalGet('batch-test/test-title');
61
62     // The stack should contain the title shown on the progress page.
63     $this->assertEqual(batch_test_stack(), ['Batch Test'], 'The batch title is shown on the batch page.');
64     $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
65   }
66
67   /**
68    * Tests that the progress messages are correct.
69    */
70   public function testBatchProgressMessages() {
71     // Go to the initial step only.
72     $this->maximumMetaRefreshCount = 0;
73     $this->drupalGet('batch-test/test-title');
74     $this->assertRaw('<div class="progress__description">Initializing.<br />&nbsp;</div>', 'Initial progress message appears correctly.');
75     $this->assertNoRaw('&amp;nbsp;', 'Initial progress message is not double escaped.');
76     // Now also go to the next step.
77     $this->maximumMetaRefreshCount = 1;
78     $this->drupalGet('batch-test/test-title');
79     $this->assertRaw('<div class="progress__description">Completed 1 of 1.</div>', 'Progress message for second step appears correctly.');
80   }
81
82 }