3 namespace Drupal\Tests\demo_umami\Functional;
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;
12 * Tests demo_umami profile.
16 class DemoUmamiProfileTest extends BrowserTestBase {
17 use AssertConfigTrait;
22 protected function installParameters() {
23 $parameters = parent::installParameters();
24 $parameters['forms']['install_configure_form']['site_mail'] = 'admin@example.com';
31 protected $profile = 'demo_umami';
34 * Tests demo_umami profile warnings shown on Status Page.
36 public function testWarningsOnStatusPage() {
37 $account = $this->drupalCreateUser(['administer site configuration']);
38 $this->drupalLogin($account);
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.');
46 * Tests the profile supplied configuration is the same after installation.
48 public function testConfig() {
49 // Just connect directly to the config table so we don't need to worry about
51 $active_config_storage = $this->container->get('config.storage');
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);
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);
61 * Asserts that the default configuration matches active configuration.
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.
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');
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:'],
86 $this->fail("$config_name has not been installed");
92 * Tests the successful editing of nodes by admin.
94 public function testEditNodesByAdmin() {
97 'edit any recipe content',
98 'use editorial transition create_new_draft',
100 $account = $this->drupalCreateUser($permissions);
101 $this->drupalLogin($account);
102 $webassert = $this->assertSession();
104 // Check that admin is able to edit the node.
105 $nodes = $this->container->get('entity_type.manager')
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.');
116 * Tests that the Umami theme is available on the Appearance page.
118 public function testAppearance() {
119 $account = $this->drupalCreateUser(['administer themes']);
120 $this->drupalLogin($account);
121 $webassert = $this->assertSession();
123 $this->drupalGet('admin/appearance');
124 $webassert->pageTextContains('Umami');
128 * Tests that the toolbar warning only appears on the admin pages.
130 public function testDemonstrationWarningMessage() {
132 'access content overview',
135 'edit any recipe content',
136 'create recipe content',
137 'use editorial transition create_new_draft',
139 $account = $this->drupalCreateUser($permissions);
140 $this->drupalLogin($account);
141 $web_assert = $this->assertSession();
143 $nodes = $this->container->get('entity_type.manager')
145 ->loadByProperties(['title' => 'Deep mediterranean quiche']);
146 /* @var \Drupal\node\Entity\Node $recipe_node */
147 $recipe_node = reset($nodes);
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.');
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.');
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.');
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.');
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.');