Updated to Drupal 8.5. Core Media not yet in use.
[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         ]);
81       }
82       else {
83         $this->fail("$config_name has not been installed");
84       }
85     }
86   }
87
88   /**
89    * Tests the successful editing of nodes by admin.
90    */
91   public function testEditNodesByAdmin() {
92     $account = $this->drupalCreateUser(['administer nodes', 'edit any recipe content']);
93     $this->drupalLogin($account);
94     $webassert = $this->assertSession();
95
96     // Check that admin is able to edit the node.
97     $nodes = $this->container->get('entity_type.manager')
98       ->getStorage('node')
99       ->loadByProperties(['title' => 'Deep mediterranean quiche']);
100     $node = reset($nodes);
101     $this->drupalGet($node->toUrl('edit-form'));
102     $webassert->statusCodeEquals('200');
103     $this->submitForm([], "Save");
104     $webassert->pageTextContains('Recipe Deep mediterranean quiche has been updated.');
105   }
106
107   /**
108    * Tests that the Umami theme is available on the Appearance page.
109    */
110   public function testAppearance() {
111     $account = $this->drupalCreateUser(['administer themes']);
112     $this->drupalLogin($account);
113     $webassert = $this->assertSession();
114
115     $this->drupalGet('admin/appearance');
116     $webassert->pageTextContains('Umami');
117   }
118
119   /**
120    * Tests that the toolbar warning only appears on the admin pages.
121    */
122   public function testDemonstrationWarningMessage() {
123     $permissions = [
124       'access content overview',
125       'administer nodes',
126       'create recipe content',
127       'edit any recipe content',
128       'access toolbar',
129     ];
130     $account = $this->drupalCreateUser($permissions);
131     $this->drupalLogin($account);
132     $web_assert = $this->assertSession();
133
134     $nodes = $this->container->get('entity_type.manager')
135       ->getStorage('node')
136       ->loadByProperties(['title' => 'Deep mediterranean quiche']);
137     /* @var \Drupal\node\Entity\Node $recipe_node */
138     $recipe_node = reset($nodes);
139
140     // Check when editing a node, the warning is visible.
141     $this->drupalGet($recipe_node->toUrl('edit-form'));
142     $web_assert->statusCodeEquals('200');
143     $web_assert->pageTextContains('This site is intended for demonstration purposes.');
144
145     // Check when adding a node, the warning is visible.
146     $this->drupalGet('node/add/recipe');
147     $web_assert->statusCodeEquals('200');
148     $web_assert->pageTextContains('This site is intended for demonstration purposes.');
149
150     // Check when looking at admin/content, the warning is visible.
151     $this->drupalGet('admin/content');
152     $web_assert->statusCodeEquals('200');
153     $web_assert->pageTextContains('This site is intended for demonstration purposes.');
154
155     // Check when viewing a node, the warning is not visible.
156     $this->drupalGet($recipe_node->toUrl());
157     $web_assert->statusCodeEquals('200');
158     $web_assert->pageTextNotContains('This site is intended for demonstration purposes.');
159
160     // Check when viewing the homepage, the warning is not visible.
161     $this->drupalGet('<front>');
162     $web_assert->statusCodeEquals('200');
163     $web_assert->pageTextNotContains('This site is intended for demonstration purposes.');
164   }
165
166 }