Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -2,9 +2,9 @@
namespace Drupal\Tests\path\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
/**
* Add, edit, delete, and change alias and verify its consistency in the
@ -25,7 +25,7 @@ class PathAliasTest extends PathTestBase {
parent::setUp();
// Create test user and log in.
$web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer url aliases', 'create url aliases']);
$web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer url aliases', 'create url aliases', 'access content overview']);
$this->drupalLogin($web_user);
}
@ -84,7 +84,7 @@ class PathAliasTest extends PathTestBase {
$this->drupalGet($edit['alias']);
$this->assertText($node1->label(), 'Alias works lower case.');
$this->assertResponse(200);
$this->drupalGet(Unicode::strtoupper($edit['alias']));
$this->drupalGet(mb_strtoupper($edit['alias']));
$this->assertText($node1->label(), 'Alias works upper case.');
$this->assertResponse(200);
@ -92,7 +92,8 @@ class PathAliasTest extends PathTestBase {
$pid = $this->getPID($edit['alias']);
$previous = $edit['alias'];
$edit['alias'] = '/alias' . // Lower-case letters.
// Lower-case letters.
$edit['alias'] = '/alias' .
// "Special" ASCII characters.
"- ._~!$'\"()*@[]?&+%#,;=:" .
// Characters that look like a percent-escaped string.
@ -110,7 +111,7 @@ class PathAliasTest extends PathTestBase {
$this->drupalPostForm('admin/config/search/path/edit/' . $pid, $edit, t('Save'));
// Confirm that the alias works.
$this->drupalGet(Unicode::strtoupper($edit['alias']));
$this->drupalGet(mb_strtoupper($edit['alias']));
$this->assertText($node1->label(), 'Changed alias works.');
$this->assertResponse(200);
@ -132,7 +133,7 @@ class PathAliasTest extends PathTestBase {
$this->assertRaw(t('The alias %alias is already in use in this language.', ['%alias' => $edit['alias']]), 'Attempt to move alias was rejected.');
$edit_upper = $edit;
$edit_upper['alias'] = Unicode::strtoupper($edit['alias']);
$edit_upper['alias'] = mb_strtoupper($edit['alias']);
$this->drupalPostForm('admin/config/search/path/add', $edit_upper, t('Save'));
$this->assertRaw(t('The alias %alias could not be added because it is already in use in this language with different capitalization: %stored_alias.', [
'%alias' => $edit_upper['alias'],
@ -246,7 +247,8 @@ class PathAliasTest extends PathTestBase {
$previous = $edit['path[0][alias]'];
// Change alias to one containing "exotic" characters.
$edit['path[0][alias]'] = '/alias' . // Lower-case letters.
// Lower-case letters.
$edit['path[0][alias]'] = '/alias' .
// "Special" ASCII characters.
"- ._~!$'\"()*@[]?&+%#,;=:" .
// Characters that look like a percent-escaped string.
@ -264,7 +266,7 @@ class PathAliasTest extends PathTestBase {
$this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save'));
// Confirm that the alias works.
$this->drupalGet(Unicode::strtoupper($edit['path[0][alias]']));
$this->drupalGet(mb_strtoupper($edit['path[0][alias]']));
$this->assertText($node1->label(), 'Changed alias works.');
$this->assertResponse(200);
@ -326,6 +328,34 @@ class PathAliasTest extends PathTestBase {
$node5->delete();
$path_alias = \Drupal::service('path.alias_storage')->lookupPathAlias('/node/' . $node5->id(), $node5->language()->getId());
$this->assertFalse($path_alias, 'Alias was successfully deleted when the referenced node was deleted.');
// Create sixth test node.
$node6 = $this->drupalCreateNode();
// Create an invalid alias with two leading slashes and verify that the
// extra slash is removed when the link is generated. This ensures that URL
// aliases cannot be used to inject external URLs.
// @todo The user interface should either display an error message or
// automatically trim these invalid aliases, rather than allowing them to
// be silently created, at which point the functional aspects of this
// test will need to be moved elsewhere and switch to using a
// programmatically-created alias instead.
$alias = $this->randomMachineName(8);
$edit = ['path[0][alias]' => '//' . $alias];
$this->drupalPostForm($node6->toUrl('edit-form'), $edit, t('Save'));
$this->drupalGet(Url::fromRoute('system.admin_content'));
// This checks the link href before clicking it, rather than using
// \Drupal\Tests\BrowserTestBase::assertSession()->addressEquals() after
// clicking it, because the test browser does not always preserve the
// correct number of slashes in the URL when it visits internal links;
// using \Drupal\Tests\BrowserTestBase::assertSession()->addressEquals()
// would actually make the test pass unconditionally on the testbot (or
// anywhere else where Drupal is installed in a subdirectory).
$link_xpath = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $node6->getTitle()]);
$link_href = $link_xpath[0]->getAttribute('href');
$this->assertEquals($link_href, base_path() . $alias);
$this->clickLink($node6->getTitle());
$this->assertResponse(404);
}
/**

View file

@ -0,0 +1,109 @@
<?php
namespace Drupal\Tests\path\Functional;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
/**
* Tests path aliases with Content Moderation.
*
* @group content_moderation
* @group path
*/
class PathContentModerationTest extends BrowserTestBase {
use ContentModerationTestTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['node', 'path', 'content_moderation'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Created a content type.
$node_type = NodeType::create(['name' => 'moderated', 'type' => 'moderated']);
$node_type->save();
// Set the content type as moderated.
$workflow = $this->createEditorialWorkflow();
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
$workflow->save();
$this->drupalLogin($this->rootUser);
}
/**
* Tests node path aliases on a moderated content type.
*/
public function testNodePathAlias() {
// Create some moderated content with a path alias.
$this->drupalGet('node/add/moderated');
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
$this->drupalPostForm(NULL, [
'title[0][value]' => 'moderated content',
'path[0][alias]' => '/moderated-content',
'moderation_state[0][state]' => 'published',
], t('Save'));
$node = $this->getNodeByTitle('moderated content');
// Add a pending revision with the same alias.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertSession()->fieldValueEquals('path[0][alias]', '/moderated-content');
$this->drupalPostForm(NULL, [
'title[0][value]' => 'pending revision',
'path[0][alias]' => '/moderated-content',
'moderation_state[0][state]' => 'draft',
], t('Save'));
$this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
// Create some moderated content with no path alias.
$this->drupalGet('node/add/moderated');
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
$this->drupalPostForm(NULL, [
'title[0][value]' => 'moderated content 2',
'path[0][alias]' => '',
'moderation_state[0][state]' => 'published',
], t('Save'));
$node = $this->getNodeByTitle('moderated content 2');
// Add a pending revision with a new alias.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
$this->drupalPostForm(NULL, [
'title[0][value]' => 'pending revision',
'path[0][alias]' => '/pending-revision',
'moderation_state[0][state]' => 'draft',
], t('Save'));
$this->assertSession()->pageTextContains('You can only change the URL alias for the published version of this content.');
// Create some moderated content with no path alias.
$this->drupalGet('node/add/moderated');
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
$this->drupalPostForm(NULL, [
'title[0][value]' => 'moderated content 3',
'path[0][alias]' => '',
'moderation_state[0][state]' => 'published',
], t('Save'));
$node = $this->getNodeByTitle('moderated content 3');
// Add a pending revision with no path alias.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
$this->drupalPostForm(NULL, [
'title[0][value]' => 'pending revision',
'path[0][alias]' => '',
'moderation_state[0][state]' => 'draft',
], t('Save'));
$this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
}
}

View file

@ -0,0 +1,66 @@
<?php
namespace Drupal\Tests\path\Functional;
use Drupal\media\Entity\MediaType;
/**
* Tests the path media form UI.
*
* @group path
*/
class PathMediaFormTest extends PathTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['media', 'media_test_source'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create test user and log in.
$web_user = $this->drupalCreateUser(['create media', 'create url aliases']);
$this->drupalLogin($web_user);
}
/**
* Tests the media form UI.
*/
public function testMediaForm() {
$assert_session = $this->assertSession();
// Create media type.
$media_type_id = 'foo';
$media_type = MediaType::create([
'id' => $media_type_id,
'label' => $media_type_id,
'source' => 'test',
'source_configuration' => [],
'field_map' => [],
'new_revision' => FALSE,
]);
$media_type->save();
$this->drupalGet('media/add/' . $media_type_id);
// Make sure we have a vertical tab fieldset and 'Path' field.
$assert_session->elementContains('css', '.form-type-vertical-tabs #edit-path-0 summary', 'URL alias');
$assert_session->fieldExists('path[0][alias]');
// Disable the 'Path' field for this content type.
entity_get_form_display('media', $media_type_id, 'default')
->removeComponent('path')
->save();
$this->drupalGet('media/add/' . $media_type_id);
// See if the whole fieldset is gone now.
$assert_session->elementNotExists('css', '.form-type-vertical-tabs #edit-path-0');
$assert_session->fieldNotExists('path[0][alias]');
}
}

View file

@ -28,13 +28,15 @@ class PathNodeFormTest extends PathTestBase {
* Tests the node form ui.
*/
public function testNodeForm() {
$assert_session = $this->assertSession();
$this->drupalGet('node/add/page');
// Make sure we have a Path fieldset and Path fields.
$this->assertRaw(' id="edit-path-settings"', 'Path settings details exists');
$this->assertFieldByName('path[0][alias]', NULL, 'Path alias field exists');
// Make sure we have a vertical tab fieldset and 'Path' fields.
$assert_session->elementContains('css', '.form-type-vertical-tabs #edit-path-0 summary', 'URL alias');
$assert_session->fieldExists('path[0][alias]');
// Disable the Path field for this content type.
// Disable the 'Path' field for this content type.
entity_get_form_display('node', 'page', 'default')
->removeComponent('path')
->save();
@ -42,8 +44,8 @@ class PathNodeFormTest extends PathTestBase {
$this->drupalGet('node/add/page');
// See if the whole fieldset is gone now.
$this->assertNoRaw(' id="edit-path-settings"', 'Path settings details does not exist');
$this->assertNoFieldByName('path[0][alias]', NULL, 'Path alias field does not exist');
$assert_session->elementNotExists('css', '.form-type-vertical-tabs #edit-path-0');
$assert_session->fieldNotExists('path[0][alias]');
}
}

View file

@ -16,7 +16,14 @@ class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'content_translation', 'path', 'menu_ui'];
public static $modules = [
'language',
'content_translation',
'path',
'menu_ui',
// Required for translation migrations.
'migrate_drupal_multilingual',
];
/**
* {@inheritdoc}
@ -68,7 +75,7 @@ class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
];
$path = \Drupal::service('path.alias_storage')->load($conditions);
$this->assertPath('1', $conditions, $path);
$this->assertIdentical($id_map->lookupDestinationID([$path['pid']]), ['1'], "Test IdMap");
$this->assertIdentical($id_map->lookupDestinationId([$path['pid']]), ['1'], "Test IdMap");
$conditions = [
'source' => '/node/2',
@ -103,6 +110,14 @@ class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
];
$path = \Drupal::service('path.alias_storage')->load($conditions);
$this->assertPath('3', $conditions, $path);
$path = \Drupal::service('path.alias_storage')->load(['alias' => '/source-noslash']);
$conditions = [
'source' => '/admin',
'alias' => '/source-noslash',
'langcode' => 'und',
];
$this->assertPath('2', $conditions, $path);
}
/**

View file

@ -18,6 +18,8 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
'content_translation',
'language',
'menu_ui',
// Required for translation migrations.
'migrate_drupal_multilingual',
'node',
'path',
'text',
@ -48,7 +50,9 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
* Test the URL alias migration.
*/
public function testUrlAlias() {
$path = \Drupal::service('path.alias_storage')->load([
$alias_storage = $this->container->get('path.alias_storage');
$path = $alias_storage->load([
'source' => '/taxonomy/term/4',
'alias' => '/term33',
'langcode' => 'und',
@ -56,6 +60,11 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
$this->assertIdentical('/taxonomy/term/4', $path['source']);
$this->assertIdentical('/term33', $path['alias']);
$this->assertIdentical('und', $path['langcode']);
// Alias with no slash.
$path = $alias_storage->load(['alias' => '/source-noslash']);
$this->assertSame('/admin', $path['source']);
$this->assertSame('und', $path['langcode']);
}
/**

View file

@ -0,0 +1,206 @@
<?php
namespace Drupal\Tests\path\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/**
* Tests loading and storing data using PathItem.
*
* @group path
*/
class PathItemTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['path', 'node', 'user', 'system', 'language', 'content_translation'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installSchema('node', ['node_access']);
$node_type = NodeType::create(['type' => 'foo']);
$node_type->save();
$this->installConfig(['language']);
ConfigurableLanguage::createFromLangcode('de')->save();
}
/**
* Test creating, loading, updating and deleting aliases through PathItem.
*/
public function testPathItem() {
/** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */
$alias_storage = \Drupal::service('path.alias_storage');
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node = Node::create([
'title' => 'Testing create()',
'type' => 'foo',
'path' => ['alias' => '/foo'],
]);
$this->assertFalse($node->get('path')->isEmpty());
$this->assertEquals('/foo', $node->get('path')->alias);
$node->save();
$this->assertFalse($node->get('path')->isEmpty());
$this->assertEquals('/foo', $node->get('path')->alias);
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
$this->assertEquals('/foo', $stored_alias);
$node_storage->resetCache();
/** @var \Drupal\node\NodeInterface $loaded_node */
$loaded_node = $node_storage->load($node->id());
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/foo', $loaded_node->get('path')->alias);
$node_storage->resetCache();
$loaded_node = $node_storage->load($node->id());
$this->assertEquals('/foo', $loaded_node->get('path')[0]->get('alias')->getValue());
$node_storage->resetCache();
$loaded_node = $node_storage->load($node->id());
$values = $loaded_node->get('path')->getValue();
$this->assertEquals('/foo', $values[0]['alias']);
$node_storage->resetCache();
$loaded_node = $node_storage->load($node->id());
$this->assertEquals('/foo', $loaded_node->path->alias);
// Add a translation, verify it is being saved as expected.
$translation = $loaded_node->addTranslation('de', $loaded_node->toArray());
$translation->get('path')->alias = '/furchtbar';
$translation->save();
// Assert the alias on the English node, the German translation, and the
// stored aliases.
$node_storage->resetCache();
$loaded_node = $node_storage->load($node->id());
$this->assertEquals('/foo', $loaded_node->path->alias);
$translation = $loaded_node->getTranslation('de');
$this->assertEquals('/furchtbar', $translation->path->alias);
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
$this->assertEquals('/foo', $stored_alias);
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $translation->language()->getId());
$this->assertEquals('/furchtbar', $stored_alias);
$loaded_node->get('path')->alias = '/bar';
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
$loaded_node->save();
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
$node_storage->resetCache();
$loaded_node = $node_storage->load($node->id());
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
$loaded_node->get('path')->alias = '/bar';
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
$loaded_node->save();
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
$this->assertEquals('/bar', $stored_alias);
$old_alias = $alias_storage->lookupPathSource('/foo', $node->language()->getId());
$this->assertFalse($old_alias);
// Reload the node to make sure that it is possible to set a value
// immediately after loading.
$node_storage->resetCache();
$loaded_node = $node_storage->load($node->id());
$loaded_node->get('path')->alias = '/foobar';
$loaded_node->save();
$node_storage->resetCache();
$loaded_node = $node_storage->load($node->id());
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/foobar', $loaded_node->get('path')->alias);
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
$this->assertEquals('/foobar', $stored_alias);
$old_alias = $alias_storage->lookupPathSource('/bar', $node->language()->getId());
$this->assertFalse($old_alias);
$loaded_node->get('path')->alias = '';
$this->assertEquals('', $loaded_node->get('path')->alias);
$loaded_node->save();
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
$this->assertFalse($stored_alias);
// Check that reading, updating and reading the computed alias again in the
// same request works without clearing any caches in between.
$loaded_node = $node_storage->load($node->id());
$loaded_node->get('path')->alias = '/foo';
$loaded_node->save();
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/foo', $loaded_node->get('path')->alias);
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
$this->assertEquals('/foo', $stored_alias);
$loaded_node->get('path')->alias = '/foobar';
$loaded_node->save();
$this->assertFalse($loaded_node->get('path')->isEmpty());
$this->assertEquals('/foobar', $loaded_node->get('path')->alias);
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
$this->assertEquals('/foobar', $stored_alias);
// Check that \Drupal\Core\Field\FieldItemList::equals() for the path field
// type.
$node = Node::create([
'title' => $this->randomString(),
'type' => 'foo',
'path' => ['alias' => '/foo'],
]);
$second_node = Node::create([
'title' => $this->randomString(),
'type' => 'foo',
'path' => ['alias' => '/foo'],
]);
$this->assertTrue($node->get('path')->equals($second_node->get('path')));
// Change the alias for the second node to a different one and try again.
$second_node->get('path')->alias = '/foobar';
$this->assertFalse($node->get('path')->equals($second_node->get('path')));
// Test the generateSampleValue() method.
$node = Node::create([
'title' => $this->randomString(),
'type' => 'foo',
'path' => ['alias' => '/foo'],
]);
$node->save();
$path_field = $node->get('path');
$path_field->generateSampleItems();
$node->save();
$this->assertStringStartsWith('/', $node->get('path')->alias);
}
}

View file

@ -42,7 +42,7 @@ class PathNoCanonicalLinkTest extends KernelTestBase {
public function testNoCanonicalLinkTemplate() {
$entity_type = EntityTestTranslatableUISkip::create([
'name' => 'name english',
'language' => 'en'
'language' => 'en',
]);
$entity_type->save();