StandardTest.php 4.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Contains Drupal\standard\Tests\StandardTest.
 */

namespace Drupal\standard\Tests;

10
use Drupal\config\Tests\SchemaCheckTestTrait;
11
use Drupal\contact\Entity\ContactForm;
12
use Drupal\simpletest\WebTestBase;
13
use Drupal\user\Entity\Role;
14
15
16

/**
 * Tests Standard installation profile expectations.
17
18
 *
 * @group standard
19
20
21
 */
class StandardTest extends WebTestBase {

22
23
  use SchemaCheckTestTrait;

24
25
  protected $profile = 'standard';

26
27
28
29
30
31
32
  /**
   * The admin user.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

33
34
35
36
37
38
39
40
  /**
   * Tests Standard installation profile.
   */
  function testStandard() {
    $this->drupalGet('');
    $this->assertLink(t('Contact'));
    $this->clickLink(t('Contact'));
    $this->assertResponse(200);
41
42

    // Test anonymous user can access 'Main navigation' block.
43
    $this->adminUser = $this->drupalCreateUser(array(
44
45
46
      'administer blocks',
      'post comments',
      'skip comment approval',
47
48
      'create article content',
      'create page content',
49
    ));
50
    $this->drupalLogin($this->adminUser);
51
    // Configure the block.
52
    $this->drupalGet('admin/structure/block/add/system_menu_block:main/bartik');
53
    $this->drupalPostForm(NULL, array(
54
      'region' => 'sidebar_first',
55
      'id' => 'main_navigation',
56
57
58
59
    ), t('Save block'));
    // Verify admin user can see the block.
    $this->drupalGet('');
    $this->assertText('Main navigation');
60

61
    // Verify we have role = aria on system_powered_by and help_block
62
63
64
65
    // blocks.
    $this->drupalGet('admin/structure/block');
    $elements = $this->xpath('//div[@role=:role and @id=:id]', array(
      ':role' => 'complementary',
66
      ':id' => 'block-bartik-help',
67
68
69
70
71
72
73
    ));

    $this->assertEqual(count($elements), 1, 'Found complementary role on help block.');

    $this->drupalGet('');
    $elements = $this->xpath('//div[@role=:role and @id=:id]', array(
      ':role' => 'complementary',
74
      ':id' => 'block-bartik-powered',
75
76
77
    ));
    $this->assertEqual(count($elements), 1, 'Found complementary role on powered by block.');

78
79
80
    // Verify anonymous user can see the block.
    $this->drupalLogout();
    $this->assertText('Main navigation');
81

82
83
84
85
86
87
88
89
90
91
    // Ensure comments don't show in the front page RSS feed.
    // Create an article.
    $node = $this->drupalCreateNode(array(
      'type' => 'article',
      'title' => 'Foobar',
      'promote' => 1,
      'status' => 1,
    ));

    // Add a comment.
92
    $this->drupalLogin($this->adminUser);
93
94
    $this->drupalGet('node/1');
    $this->drupalPostForm(NULL, array(
95
      'subject[0][value]' => 'Barfoo',
96
97
98
99
100
101
      'comment_body[0][value]' => 'Then she picked out two somebodies, Sally and me',
    ), t('Save'));
    // Fetch the feed.
    $this->drupalGet('rss.xml');
    $this->assertText('Foobar');
    $this->assertNoText('Then she picked out two somebodies, Sally and me');
102

103
104
105
106
    // Ensure block body exists.
    $this->drupalGet('block/add');
    $this->assertFieldByName('body[0][value]');

107
108
109
110
111
112
113
    // Now we have all configuration imported, test all of them for schema
    // conformance. Ensures all imported default configuration is valid when
    // standard profile modules are enabled.
    $names = $this->container->get('config.storage')->listAll();
    /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
    $typed_config = $this->container->get('config.typed');
    foreach ($names as $name) {
114
      $config = $this->config($name);
115
116
      $this->assertConfigSchema($typed_config, $name, $config->get());
    }
117
118
119
120
121
122
123
124
125

    // Ensure that configuration from the Standard profile is not reused when
    // enabling a module again since it contains configuration that can not be
    // installed. For example, editor.editor.basic_html is editor configuration
    // that depends on the ckeditor module. The ckeditor module can not be
    // installed before the editor module since it depends on the editor module.
    // The installer does not have this limitation since it ensures that all of
    // the install profiles dependencies are installed before creating the
    // editor configuration.
126
    \Drupal::service('module_installer')->uninstall(array('editor', 'ckeditor'));
127
    $this->rebuildContainer();
128
    \Drupal::service('module_installer')->install(array('editor'));
129
130
131
132
    /** @var \Drupal\contact\ContactFormInterface $contact_form */
    $contact_form = ContactForm::load('feedback');
    $recipients = $contact_form->getRecipients();
    $this->assertEqual(['simpletest@example.com'], $recipients);
133
134
135
136
137
138
139
140
141
142
143

    $role = Role::create([
      'id' => 'admin_theme',
      'label' => 'Admin theme',
    ]);
    $role->grantPermission('view the administration theme');
    $role->save();
    $this->adminUser->addRole($role->id());
    $this->adminUser->save();
    $this->drupalGet('node/add');
    $this->assertResponse(200);
144
145
146
  }

}