Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / profiles / demo_umami / tests / src / Functional / DemoUmamiProfileTest.php
1 <?php
2
3 namespace Drupal\Tests\demo_umami\Functional;
4
5 use Drupal\Core\Config\FileStorage;
6 use Drupal\Core\Config\InstallStorage;
7 use Drupal\Core\Config\StorageInterface;
8 use Drupal\KernelTests\AssertConfigTrait;
9 use Drupal\Tests\BrowserTestBase;
10
11 /**
12  * Tests demo_umami profile.
13  *
14  * @group demo_umami
15  */
16 class DemoUmamiProfileTest extends BrowserTestBase {
17   use AssertConfigTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function installParameters() {
23     $parameters = parent::installParameters();
24     $parameters['forms']['install_configure_form']['site_mail'] = 'admin@example.com';
25     return $parameters;
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   protected $profile = 'demo_umami';
32
33   /**
34    * Tests demo_umami profile warnings shown on Status Page.
35    */
36   public function testWarningsOnStatusPage() {
37     $account = $this->drupalCreateUser(['administer site configuration']);
38     $this->drupalLogin($account);
39
40     // Check the requirements warning for using an experimental profile.
41     $this->drupalGet('admin/reports/status');
42     $this->assertSession()->pageTextContains('Experimental profiles are provided for testing purposes only. Use at your own risk. To start building a new site, reinstall Drupal and choose a non-experimental profile.');
43   }
44
45   /**
46    * Tests the profile supplied configuration is the same after installation.
47    */
48   public function testConfig() {
49     // Just connect directly to the config table so we don't need to worry about
50     // the cache layer.
51     $active_config_storage = $this->container->get('config.storage');
52
53     $default_config_storage = new FileStorage(drupal_get_path('profile', 'demo_umami') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY, InstallStorage::DEFAULT_COLLECTION);
54     $this->assertDefaultConfig($default_config_storage, $active_config_storage);
55
56     $default_config_storage = new FileStorage(drupal_get_path('profile', 'demo_umami') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY, InstallStorage::DEFAULT_COLLECTION);
57     $this->assertDefaultConfig($default_config_storage, $active_config_storage);
58   }
59
60   /**
61    * Asserts that the default configuration matches active configuration.
62    *
63    * @param \Drupal\Core\Config\StorageInterface $default_config_storage
64    *   The default configuration storage to check.
65    * @param \Drupal\Core\Config\StorageInterface $active_config_storage
66    *   The active configuration storage.
67    */
68   protected function assertDefaultConfig(StorageInterface $default_config_storage, StorageInterface $active_config_storage) {
69     /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
70     $config_manager = $this->container->get('config.manager');
71
72     foreach ($default_config_storage->listAll() as $config_name) {
73       if ($active_config_storage->exists($config_name)) {
74         $result = $config_manager->diff($default_config_storage, $active_config_storage, $config_name);
75         $this->assertConfigDiff($result, $config_name, [
76           // The filter.format.*:roles key is a special install key.
77           'filter.format.basic_html' => ['roles:', '  - authenticated'],
78           'filter.format.full_html' => ['roles:', '  - administrator'],
79           'filter.format.restricted_html' => ['roles:', '  - anonymous'],
80           // The system.site config is overwritten during tests by
81           // FunctionalTestSetupTrait::installParameters().
82           'system.site' => ['uuid:', 'name:', 'mail:'],
83         ]);
84       }
85       else {
86         $this->fail("$config_name has not been installed");
87       }
88     }
89   }
90
91   /**
92    * Tests the successful editing of nodes by admin.
93    */
94   public function testEditNodesByAdmin() {
95     $permissions = [
96       'administer nodes',
97       'edit any recipe content',
98       'use editorial transition create_new_draft',
99     ];
100     $account = $this->drupalCreateUser($permissions);
101     $this->drupalLogin($account);
102     $webassert = $this->assertSession();
103
104     // Check that admin is able to edit the node.
105     $nodes = $this->container->get('entity_type.manager')
106       ->getStorage('node')
107       ->loadByProperties(['title' => 'Deep mediterranean quiche']);
108     $node = reset($nodes);
109     $this->drupalGet($node->toUrl('edit-form'));
110     $webassert->statusCodeEquals('200');
111     $this->submitForm([], "Save");
112     $webassert->pageTextContains('Recipe Deep mediterranean quiche has been updated.');
113   }
114
115   /**
116    * Tests that the Umami theme is available on the Appearance page.
117    */
118   public function testAppearance() {
119     $account = $this->drupalCreateUser(['administer themes']);
120     $this->drupalLogin($account);
121     $webassert = $this->assertSession();
122
123     $this->drupalGet('admin/appearance');
124     $webassert->pageTextContains('Umami');
125   }
126
127   /**
128    * Tests that the toolbar warning only appears on the admin pages.
129    */
130   public function testDemonstrationWarningMessage() {
131     $permissions = [
132       'access content overview',
133       'access toolbar',
134       'administer nodes',
135       'edit any recipe content',
136       'create recipe content',
137       'use editorial transition create_new_draft',
138     ];
139     $account = $this->drupalCreateUser($permissions);
140     $this->drupalLogin($account);
141     $web_assert = $this->assertSession();
142
143     $nodes = $this->container->get('entity_type.manager')
144       ->getStorage('node')
145       ->loadByProperties(['title' => 'Deep mediterranean quiche']);
146     /* @var \Drupal\node\Entity\Node $recipe_node */
147     $recipe_node = reset($nodes);
148
149     // Check when editing a node, the warning is visible.
150     $this->drupalGet($recipe_node->toUrl('edit-form'));
151     $web_assert->statusCodeEquals('200');
152     $web_assert->pageTextContains('This site is intended for demonstration purposes.');
153
154     // Check when adding a node, the warning is visible.
155     $this->drupalGet('node/add/recipe');
156     $web_assert->statusCodeEquals('200');
157     $web_assert->pageTextContains('This site is intended for demonstration purposes.');
158
159     // Check when looking at admin/content, the warning is visible.
160     $this->drupalGet('admin/content');
161     $web_assert->statusCodeEquals('200');
162     $web_assert->pageTextContains('This site is intended for demonstration purposes.');
163
164     // Check when viewing a node, the warning is not visible.
165     $this->drupalGet($recipe_node->toUrl());
166     $web_assert->statusCodeEquals('200');
167     $web_assert->pageTextNotContains('This site is intended for demonstration purposes.');
168
169     // Check when viewing the homepage, the warning is not visible.
170     $this->drupalGet('<front>');
171     $web_assert->statusCodeEquals('200');
172     $web_assert->pageTextNotContains('This site is intended for demonstration purposes.');
173   }
174
175 }