View source
<?php
namespace Drupal\Tests\standard\Functional;
use Drupal\Component\Utility\Html;
use Drupal\media\Entity\MediaType;
use Drupal\media\Plugin\media\Source\Image;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\contact\Entity\ContactForm;
use Drupal\Core\Url;
use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
use Drupal\user\Entity\Role;
class StandardTest extends BrowserTestBase {
use SchemaCheckTestTrait;
use RequirementsPageTrait;
protected $profile = 'standard';
protected $adminUser;
public function testStandard() {
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains('Powered by Drupal');
$this->adminUser = $this
->drupalCreateUser([
'administer blocks',
'post comments',
'skip comment approval',
'create article content',
'create page content',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/structure/block/add/system_menu_block:main/olivero');
$this
->submitForm([
'region' => 'sidebar',
'id' => 'main_navigation',
], 'Save block');
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains('Main navigation');
$this
->drupalGet('admin/structure/block');
$this
->assertSession()
->elementAttributeContains('xpath', "//div[@id='block-olivero-help']", 'role', 'complementary');
$this
->drupalLogout();
$this
->assertSession()
->pageTextContains('Main navigation');
$this
->drupalCreateNode([
'type' => 'article',
'title' => 'Foobar',
'promote' => 1,
'status' => 1,
'body' => [
[
'value' => 'Then she picked out two somebodies,<br />Sally and me',
'format' => 'basic_html',
],
],
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node/1');
$this
->assertSession()
->responseContains('Then she picked out two somebodies,<br />Sally and me');
$this
->submitForm([
'subject[0][value]' => 'Barfoo',
'comment_body[0][value]' => 'Then she picked out two somebodies, Sally and me',
], 'Save');
$this
->drupalGet('rss.xml');
$this
->assertSession()
->responseContains('Foobar');
$this
->assertSession()
->responseNotContains('Then she picked out two somebodies, Sally and me');
$this
->drupalGet('block/add');
$this
->assertSession()
->fieldExists('body[0][value]');
$names = $this->container
->get('config.storage')
->listAll();
$typed_config = $this->container
->get('config.typed');
foreach ($names as $name) {
$config = $this
->config($name);
$this
->assertConfigSchema($typed_config, $name, $config
->get());
}
foreach (FilterFormat::loadMultiple() as $filter) {
$filter
->filters();
$filter
->removeFilter('editor_file_reference');
$filter
->save();
}
\Drupal::service('module_installer')
->uninstall([
'editor',
'ckeditor',
]);
$this
->rebuildContainer();
\Drupal::service('module_installer')
->install([
'editor',
]);
$contact_form = ContactForm::load('feedback');
$recipients = $contact_form
->getRecipients();
$this
->assertEquals([
'simpletest@example.com',
], $recipients);
$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
->assertSession()
->statusCodeEquals(200);
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('update.php/selection');
$this
->updateRequirementsProblem();
$this
->drupalGet('update.php/selection');
$this
->assertSession()
->pageTextContains('No pending updates.');
$this
->assertFalse($this->container
->get('entity.definition_update_manager')
->needsUpdates(), 'After installation, entity schema is up to date.');
$this
->drupalGet('admin/config/media/image-styles');
$this
->assertSession()
->pageTextNotContains('Max 325x325');
$this
->assertSession()
->pageTextNotContains('Max 650x650');
$this
->assertSession()
->pageTextNotContains('Max 1300x1300');
$this
->assertSession()
->pageTextNotContains('Max 2600x2600');
\Drupal::service('module_installer')
->install([
'responsive_image',
]);
$this
->rebuildContainer();
$this
->drupalGet('admin/config/media/image-styles');
$this
->assertSession()
->pageTextContains('Max 325x325');
$this
->assertSession()
->pageTextContains('Max 650x650');
$this
->assertSession()
->pageTextContains('Max 1300x1300');
$this
->assertSession()
->pageTextContains('Max 2600x2600');
$this
->drupalLogin($this->adminUser);
$url = Url::fromRoute('contact.site_page');
$this
->drupalGet($url);
$this
->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'UNCACHEABLE');
$url = Url::fromRoute('<front>');
$this
->drupalGet($url);
$this
->drupalGet($url);
$this
->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
$url = Url::fromRoute('entity.node.canonical', [
'node' => 1,
]);
$this
->drupalGet($url);
$this
->drupalGet($url);
$this
->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
$url = Url::fromRoute('entity.user.canonical', [
'user' => 1,
]);
$this
->drupalGet($url);
$this
->drupalGet($url);
$this
->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
\Drupal::service('module_installer')
->install([
'content_moderation',
]);
$role = Role::create([
'id' => 'admin_workflows',
'label' => 'Admin workflow',
]);
$role
->grantPermission('administer workflows');
$role
->save();
$this->adminUser
->addRole($role
->id());
$this->adminUser
->save();
$this
->rebuildContainer();
$this
->drupalGet('admin/config/workflow/workflows/manage/editorial');
$this
->assertSession()
->pageTextContains('Draft');
$this
->assertSession()
->pageTextContains('Published');
$this
->assertSession()
->pageTextContains('Archived');
$this
->assertSession()
->pageTextContains('Create New Draft');
$this
->assertSession()
->pageTextContains('Publish');
$this
->assertSession()
->pageTextContains('Archive');
$this
->assertSession()
->pageTextContains('Restore to Draft');
$this
->assertSession()
->pageTextContains('Restore');
\Drupal::service('module_installer')
->install([
'media',
]);
$role = Role::create([
'id' => 'admin_media',
'label' => 'Admin media',
]);
$role
->grantPermission('administer media');
$role
->grantPermission('administer media display');
$role
->save();
$this->adminUser
->addRole($role
->id());
$this->adminUser
->save();
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
foreach (MediaType::loadMultiple() as $media_type) {
$media_type_machine_name = $media_type
->id();
$this
->drupalGet('media/add/' . $media_type_machine_name);
$form_selector = '#media-' . Html::cleanCssIdentifier($media_type_machine_name) . '-add-form';
$form = $assert_session
->elementExists('css', $form_selector);
$form_html = $form
->getOuterHtml();
$assert_session
->fieldNotExists('Name', $form);
$source_field_label = $media_type
->getSource()
->getSourceFieldDefinition($media_type)
->getLabel();
$test_source_field = $assert_session
->elementExists('xpath', "//*[contains(text(), '{$source_field_label}')]", $form)
->getOuterHtml();
$vertical_tabs = $assert_session
->elementExists('css', '.js-form-type-vertical-tabs', $form)
->getOuterHtml();
$this
->assertGreaterThan(strpos($form_html, $test_source_field), strpos($form_html, $vertical_tabs));
$date_field = $assert_session
->fieldExists('Date', $form)
->getOuterHtml();
$published_checkbox = $assert_session
->fieldExists('Published', $form)
->getOuterHtml();
$this
->assertGreaterThan(strpos($form_html, $date_field), strpos($form_html, $published_checkbox));
if (is_a($media_type
->getSource(), Image::class, TRUE)) {
$this
->drupalGet('/admin/structure/media/manage/' . $media_type
->id() . '/display');
$assert_session
->fieldValueEquals('fields[field_media_image][type]', 'image');
$assert_session
->elementTextContains('css', 'tr[data-drupal-selector="edit-fields-field-media-image"]', 'Image style: Large (480×480)');
$assert_session
->elementsCount('css', 'input[name$="_settings_edit"]', 1);
}
}
}
}