updated core to 8.6.1 via composer

This commit is contained in:
2018-09-12 13:58:26 +02:00
parent a9a219f2ed
commit ea56b9fba3
4443 changed files with 112098 additions and 40708 deletions
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- options
- drupal:options
@@ -182,10 +182,10 @@ function node_test_node_insert(NodeInterface $node) {
*/
function node_test_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (!$form_state->get('node_test_form_alter')) {
drupal_set_message('Storage is not set');
\Drupal::messenger()->addStatus('Storage is not set');
$form_state->set('node_test_form_alter', TRUE);
}
else {
drupal_set_message('Storage is set');
\Drupal::messenger()->addStatus('Storage is set');
}
}
@@ -5,6 +5,6 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- node
- views
- language
- drupal:node
- drupal:views
- drupal:language
@@ -202,7 +202,7 @@ display:
hide_empty: false
empty_zero: false
hide_alter_empty: true
text: 'Link to delete revision'
text: 'Link to revert revision'
entity_type: node
plugin_id: node_revision_link_revert
filters: { }
@@ -0,0 +1,124 @@
<?php
namespace Drupal\Tests\node\Functional\Hal;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\node\Functional\Rest\NodeResourceTestBase;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\user\Entity\User;
/**
* @group hal
*/
class NodeHalJsonAnonTest extends NodeResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [
'revision_timestamp' => NULL,
'created' => "The 'administer nodes' permission is required.",
'changed' => NULL,
'promote' => "The 'administer nodes' permission is required.",
'sticky' => "The 'administer nodes' permission is required.",
'path' => "The following permissions are required: 'create url aliases' OR 'administer url aliases'.",
'revision_uid' => NULL,
];
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
$author = User::load($this->entity->getOwnerId());
return $normalization + [
'_links' => [
'self' => [
'href' => $this->baseUrl . '/llama?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/node/camelids',
],
$this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
[
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
],
],
$this->baseUrl . '/rest/relation/node/camelids/uid' => [
[
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
'lang' => 'en',
],
],
],
'_embedded' => [
$this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/user/user',
],
],
'uuid' => [
['value' => $author->uuid()],
],
],
],
$this->baseUrl . '/rest/relation/node/camelids/uid' => [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/user/user',
],
],
'uuid' => [
['value' => $author->uuid()],
],
'lang' => 'en',
],
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/node/camelids',
],
],
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\node\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class NodeHalJsonBasicAuthTest extends NodeHalJsonAnonTest {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,19 @@
<?php
namespace Drupal\Tests\node\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class NodeHalJsonCookieTest extends NodeHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,30 @@
<?php
namespace Drupal\Tests\node\Functional\Hal;
use Drupal\Tests\node\Functional\Rest\NodeTypeResourceTestBase;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group hal
*/
class NodeTypeHalJsonAnonTest extends NodeTypeResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\node\Functional\Hal;
use Drupal\Tests\node\Functional\Rest\NodeTypeResourceTestBase;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class NodeTypeHalJsonBasicAuthTest extends NodeTypeResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal', 'basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\node\Functional\Hal;
use Drupal\Tests\node\Functional\Rest\NodeTypeResourceTestBase;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class NodeTypeHalJsonCookieTest extends NodeTypeResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -28,10 +28,10 @@ class MigrateNodeRevisionTest extends MigrateNodeTestBase {
* Test node revisions migration from Drupal 6 to 8.
*/
public function testNodeRevision() {
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2);
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2001);
/** @var \Drupal\node\NodeInterface $node */
$this->assertIdentical('1', $node->id());
$this->assertIdentical('2', $node->getRevisionId());
$this->assertIdentical('2001', $node->getRevisionId());
$this->assertIdentical('und', $node->langcode->value);
$this->assertIdentical('Test title rev 2', $node->getTitle());
$this->assertIdentical('body test rev 2', $node->body->value);
@@ -2,7 +2,6 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
@@ -29,7 +28,7 @@ class MultiStepNodeFormBasicOptionsTest extends NodeTestBase {
$this->drupalLogin($web_user);
// Create an unlimited cardinality field.
$this->fieldName = Unicode::strtolower($this->randomMachineName());
$this->fieldName = mb_strtolower($this->randomMachineName());
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
@@ -2,7 +2,6 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
@@ -51,11 +50,11 @@ class NodeAccessFieldTest extends NodeTestBase {
$this->contentAdminUser = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields']);
// Add a custom field to the page content type.
$this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
$this->fieldName = mb_strtolower($this->randomMachineName() . '_field_name');
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'text'
'type' => 'text',
])->save();
FieldConfig::create([
'field_name' => $this->fieldName,
@@ -34,14 +34,14 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
/**
* A normal authenticated user.
*
* @var \Drupal\user\UserInterface.
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* User 1.
*
* @var \Drupal\user\UserInterface.
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
@@ -33,7 +33,7 @@ class NodeAccessMenuLinkTest extends NodeTestBase {
$this->contentAdminUser = $this->drupalCreateUser([
'access content',
'administer content types',
'administer menu'
'administer menu',
]);
$this->config('user.role.' . RoleInterface::ANONYMOUS_ID)->set('permissions', [])->save();
@@ -52,7 +52,7 @@ class NodeAccessRebuildNodeGrantsTest extends NodeTestBase {
for ($i = 0; $i < 30; $i++) {
$nodes[] = $this->drupalCreateNode([
'uid' => $this->webUser->id(),
'private' => [['value' => 1]]
'private' => [['value' => 1]],
]);
}
@@ -141,15 +141,32 @@ class NodeBlockFunctionalTest extends NodeTestBase {
$label = $block->label();
$this->assertNoText($label, 'Block was not displayed on the front page.');
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route']);
// Ensure that a page that does not have a node context can still be cached,
// the front page is the user page which is already cached from the login
// request above.
$this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
$this->drupalGet('node/add/article');
$this->assertText($label, 'Block was displayed on the node/add/article page.');
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'session', 'theme', 'url.path', 'url.query_args', 'user', 'route']);
// The node/add/article page is an admin path and currently uncacheable.
$this->assertSame('UNCACHEABLE', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
$this->drupalGet('node/' . $node1->id());
$this->assertText($label, 'Block was displayed on the node/N when node is of type article.');
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route', 'timezone']);
$this->assertSame('MISS', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
$this->drupalGet('node/' . $node1->id());
$this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
$this->drupalGet('node/' . $node5->id());
$this->assertNoText($label, 'Block was not displayed on nodes of type page.');
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route', 'timezone']);
$this->assertSame('MISS', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
$this->drupalGet('node/' . $node5->id());
$this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/structure/block');
@@ -5,7 +5,7 @@ namespace Drupal\Tests\node\Functional;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
/**
* Tests the Node entity's cache tags.
@@ -32,7 +32,7 @@ class NodeCacheTagsTest extends EntityWithUriCacheTagsTestBase {
// Create a "Llama" node.
$node = Node::create(['type' => 'camelids']);
$node->setTitle('Llama')
->setPublished(TRUE)
->setPublished()
->save();
return $node;
@@ -14,7 +14,7 @@ class NodeHelpTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array.
* @var array
*/
public static $modules = ['block', 'node', 'help'];
@@ -0,0 +1,62 @@
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the node entity preview functionality for anonymous user.
*
* @group node
*/
class NodePreviewAnonymousTest extends BrowserTestBase {
/**
* Enable node module to test on the preview.
*
* @var array
*/
public static $modules = ['node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create Basic page node type.
$this->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
// Grant create and editing permissions to anonymous user:
$anonymous_role = Role::load(AccountInterface::ANONYMOUS_ROLE);
$anonymous_role->grantPermission('create page content');
$anonymous_role->save();
}
/**
* Checks the node preview functionality for anonymous users.
*/
public function testAnonymousPagePreview() {
$title_key = 'title[0][value]';
$body_key = 'body[0][value]';
// Fill in node creation form and preview node.
$edit = [
$title_key => $this->randomMachineName(),
$body_key => $this->randomMachineName(),
];
$this->drupalPostForm('node/add/page', $edit, t('Preview'));
// Check that the preview is displaying the title, body and term.
$this->assertSession()->linkExists(t('Back to content editing'));
$this->assertSession()->responseContains($edit[$body_key]);
$this->assertSession()->titleEquals($edit[$title_key] . ' | Drupal');
}
}
@@ -26,6 +26,13 @@ class NodeRevisionsAllTest extends NodeTestBase {
*/
protected $revisionLogs;
/**
* An arbitrary user for revision authoring.
*
* @var \Drupal\user\UserInterface
*/
protected $revisionUser;
/**
* {@inheritdoc}
*/
@@ -39,7 +46,7 @@ class NodeRevisionsAllTest extends NodeTestBase {
'revert page revisions',
'delete page revisions',
'edit any page content',
'delete any page content'
'delete any page content',
]
);
$this->drupalLogin($web_user);
@@ -47,6 +54,10 @@ class NodeRevisionsAllTest extends NodeTestBase {
// Create an initial node.
$node = $this->drupalCreateNode();
// Create a user for revision authoring.
// This must be different from user performing revert.
$this->revisionUser = $this->drupalCreateUser();
$settings = get_object_vars($node);
$settings['revision'] = 1;
@@ -86,6 +97,8 @@ class NodeRevisionsAllTest extends NodeTestBase {
'format' => filter_default_format(),
];
$node->setNewRevision();
// Ensure the revision author is a different user.
$node->setRevisionUserId($this->revisionUser->id());
$node->save();
return $node;
@@ -109,7 +122,7 @@ class NodeRevisionsAllTest extends NodeTestBase {
'revert all revisions',
'delete all revisions',
'edit any page content',
'delete any page content'
'delete any page content',
]
);
$this->drupalLogin($content_admin);
@@ -134,13 +147,18 @@ class NodeRevisionsAllTest extends NodeTestBase {
[
'@type' => 'Basic page',
'%title' => $nodes[1]->getTitle(),
'%revision-date' => format_date($nodes[1]->getRevisionCreationTime())
'%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
]),
'Revision reverted.');
$node_storage->resetCache([$node->id()]);
$reverted_node = $node_storage->load($node->id());
$this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.');
// Confirm the revision author is the user performing the revert.
$this->assertTrue($reverted_node->getRevisionUserId() == $this->loggedInUser->id(), 'Node revision author is user performing revert.');
// And that its not the revision author.
$this->assertTrue($reverted_node->getRevisionUserId() != $this->revisionUser->id(), 'Node revision author is not original revision author.');
// Confirm that this is not the current version.
$node = node_revision_load($node->getRevisionId());
$this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the current one.');
@@ -102,7 +102,7 @@ abstract class NodeTestBase extends BrowserTestBase {
[
'@result' => $result ? 'true' : 'false',
'%op' => $operation,
'%langcode' => !empty($langcode) ? $langcode : 'empty'
'%langcode' => !empty($langcode) ? $langcode : 'empty',
]
);
}
@@ -99,7 +99,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
$add_url = Url::fromRoute("entity.$entity_type_id.content_translation_add", [
$entity->getEntityTypeId() => $entity->id(),
'source' => $default_langcode,
'target' => $langcode
'target' => $langcode,
], ['language' => $language]);
$edit = $this->getEditValues($values, $langcode);
$edit['status[value]'] = FALSE;
@@ -284,7 +284,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
$translation = $node->addTranslation($langcode, $values[$langcode]);
// Publish and promote the translation to frontpage.
$translation->setPromoted(TRUE);
$translation->setPublished(TRUE);
$translation->setPublished();
}
$node->save();
@@ -501,4 +501,28 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
$this->assertNoText('First rev en title');
}
/**
* Test that title is not escaped (but XSS-filtered) for details form element.
*/
public function testDetailsTitleIsNotEscaped() {
$this->drupalLogin($this->administrator);
// Make the image field a multi-value field in order to display a
// details form element.
$edit = ['cardinality_number' => 2];
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/storage', $edit, t('Save field settings'));
// Make the image field non-translatable.
$edit = ['settings[node][article][fields][field_image]' => FALSE];
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
// Create a node.
$nid = $this->createEntity(['title' => 'Node with multi-value image field en title'], 'en');
// Add a French translation and assert the title markup is not escaped.
$this->drupalGet("node/$nid/translations/add/en/fr");
$markup = 'Image <span class="translation-entity-all-languages">(all languages)</span>';
$this->assertSession()->assertNoEscaped($markup);
$this->assertSession()->responseContains($markup);
}
}
@@ -2,7 +2,6 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
@@ -83,6 +82,11 @@ class NodeTypeTranslationTest extends BrowserTestBase {
protected function installParameters() {
$parameters = parent::installParameters();
$parameters['parameters']['langcode'] = $this->defaultLangcode;
// Create an empty po file so we don't attempt to download one from
// localize.drupal.org. It does not need to match the version exactly as the
// multi-lingual system will fallback.
\Drupal::service('file_system')->mkdir($this->publicFilesDirectory . '/translations', NULL, TRUE);
file_put_contents($this->publicFilesDirectory . "/translations/drupal-8.0.0.{$this->defaultLangcode}.po", '');
return $parameters;
}
@@ -90,7 +94,7 @@ class NodeTypeTranslationTest extends BrowserTestBase {
* Tests the node type translation.
*/
public function testNodeTypeTranslation() {
$type = Unicode::strtolower($this->randomMachineName(16));
$type = mb_strtolower($this->randomMachineName(16));
$name = $this->randomString();
$this->drupalLogin($this->adminUser);
$this->drupalCreateContentType(['type' => $type, 'name' => $name]);
@@ -124,7 +128,7 @@ class NodeTypeTranslationTest extends BrowserTestBase {
* Tests the node type title label translation.
*/
public function testNodeTypeTitleLabelTranslation() {
$type = Unicode::strtolower($this->randomMachineName(16));
$type = mb_strtolower($this->randomMachineName(16));
$name = $this->randomString();
$this->drupalLogin($this->adminUser);
$this->drupalCreateContentType(['type' => $type, 'name' => $name]);
@@ -154,7 +158,7 @@ class NodeTypeTranslationTest extends BrowserTestBase {
$this->drupalPostForm(NULL, [], 'Save field settings');
$this->drupalPostForm(NULL, [], 'Save settings');
$type = Unicode::strtolower($this->randomMachineName(16));
$type = mb_strtolower($this->randomMachineName(16));
$name = $this->randomString();
$this->drupalCreateContentType(['type' => $type, 'name' => $name]);
@@ -47,7 +47,7 @@ class NodeViewTest extends NodeTestBase {
// ensure caches are handled properly.
$this->drupalLogin($this->rootUser);
$edit = [
'anonymous[edit own ' . $node->bundle() . ' content]' => TRUE
'anonymous[edit own ' . $node->bundle() . ' content]' => TRUE,
];
$this->drupalPostForm('admin/people/permissions', $edit, 'Save permissions');
$this->drupalLogout();
@@ -10,6 +10,7 @@ use Drupal\node\Entity\Node;
* @group node
*/
class PageViewTest extends NodeTestBase {
/**
* Tests an anonymous and unpermissioned user attempting to edit the node.
*/
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class NodeJsonAnonTest extends NodeResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
@@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class NodeJsonBasicAuthTest extends NodeResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class NodeJsonCookieTest extends NodeResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,264 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\user\Entity\User;
use GuzzleHttp\RequestOptions;
abstract class NodeResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'path'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'node';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [
'revision_timestamp' => NULL,
'revision_uid' => NULL,
'created' => "The 'administer nodes' permission is required.",
'changed' => NULL,
'promote' => "The 'administer nodes' permission is required.",
'sticky' => "The 'administer nodes' permission is required.",
'path' => "The following permissions are required: 'create url aliases' OR 'administer url aliases'.",
];
/**
* @var \Drupal\node\NodeInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access content']);
break;
case 'POST':
$this->grantPermissionsToTestedRole(['access content', 'create camelids content']);
break;
case 'PATCH':
// Do not grant the 'create url aliases' permission to test the case
// when the path field is protected/not accessible, see
// \Drupal\Tests\rest\Functional\EntityResource\Term\TermResourceTestBase
// for a positive test.
$this->grantPermissionsToTestedRole(['access content', 'edit any camelids content']);
break;
case 'DELETE':
$this->grantPermissionsToTestedRole(['access content', 'delete any camelids content']);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
if (!NodeType::load('camelids')) {
// Create a "Camelids" node type.
NodeType::create([
'name' => 'Camelids',
'type' => 'camelids',
])->save();
}
// Create a "Llama" node.
$node = Node::create(['type' => 'camelids']);
$node->setTitle('Llama')
->setOwnerId(static::$auth ? $this->account->id() : 0)
->setPublished()
->setCreatedTime(123456789)
->setChangedTime(123456789)
->setRevisionCreationTime(123456789)
->set('path', '/llama')
->save();
return $node;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$author = User::load($this->entity->getOwnerId());
return [
'nid' => [
['value' => 1],
],
'uuid' => [
['value' => $this->entity->uuid()],
],
'vid' => [
['value' => 1],
],
'langcode' => [
[
'value' => 'en',
],
],
'type' => [
[
'target_id' => 'camelids',
'target_type' => 'node_type',
'target_uuid' => NodeType::load('camelids')->uuid(),
],
],
'title' => [
[
'value' => 'Llama',
],
],
'status' => [
[
'value' => TRUE,
],
],
'created' => [
$this->formatExpectedTimestampItemValues(123456789),
],
'changed' => [
$this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
],
'promote' => [
[
'value' => TRUE,
],
],
'sticky' => [
[
'value' => FALSE,
],
],
'revision_timestamp' => [
$this->formatExpectedTimestampItemValues(123456789),
],
'revision_translation_affected' => [
[
'value' => TRUE,
],
],
'default_langcode' => [
[
'value' => TRUE,
],
],
'uid' => [
[
'target_id' => (int) $author->id(),
'target_type' => 'user',
'target_uuid' => $author->uuid(),
'url' => base_path() . 'user/' . $author->id(),
],
],
'revision_uid' => [
[
'target_id' => (int) $author->id(),
'target_type' => 'user',
'target_uuid' => $author->uuid(),
'url' => base_path() . 'user/' . $author->id(),
],
],
'revision_log' => [],
'path' => [
[
'alias' => '/llama',
'pid' => 1,
'langcode' => 'en',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'type' => [
[
'target_id' => 'camelids',
],
],
'title' => [
[
'value' => 'Dramallama',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
if ($method === 'GET' || $method == 'PATCH' || $method == 'DELETE') {
return "The 'access content' permission is required.";
}
return parent::getExpectedUnauthorizedAccessMessage($method);
}
/**
* Tests PATCHing a node's path with and without 'create url aliases'.
*
* For a positive test, see the similar test coverage for Term.
*
* @see \Drupal\Tests\rest\Functional\EntityResource\Term\TermResourceTestBase::testPatchPath()
*/
public function testPatchPath() {
$this->initAuthentication();
$this->provisionEntityResource();
$this->setUpAuthorization('GET');
$this->setUpAuthorization('PATCH');
$url = $this->getEntityResourceUrl()->setOption('query', ['_format' => static::$format]);
// GET node's current normalization.
$response = $this->request('GET', $url, $this->getAuthenticationRequestOptions('GET'));
$normalization = $this->serializer->decode((string) $response->getBody(), static::$format);
// Change node's path alias.
$normalization['path'][0]['alias'] .= 's-rule-the-world';
// Create node PATCH request.
$request_options = [];
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
$request_options = array_merge_recursive($request_options, $this->getAuthenticationRequestOptions('PATCH'));
$request_options[RequestOptions::BODY] = $this->serializer->encode($normalization, static::$format);
// PATCH request: 403 when creating URL aliases unauthorized. Before
// asserting the 403 response, assert that the stored path alias remains
// unchanged.
$response = $this->request('PATCH', $url, $request_options);
$this->assertSame('/llama', $this->entityStorage->loadUnchanged($this->entity->id())->get('path')->alias);
$this->assertResourceErrorResponse(403, "Access denied on updating field 'path'. " . static::$patchProtectedFieldNames['path'], $response);
// Grant permission to create URL aliases.
$this->grantPermissionsToTestedRole(['create url aliases']);
// Repeat PATCH request: 200.
$response = $this->request('PATCH', $url, $request_options);
$this->assertResourceResponse(200, FALSE, $response);
$updated_normalization = $this->serializer->decode((string) $response->getBody(), static::$format);
$this->assertSame($normalization['path'], $updated_normalization['path']);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class NodeTypeJsonAnonTest extends NodeTypeResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
@@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class NodeTypeJsonBasicAuthTest extends NodeTypeResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class NodeTypeJsonCookieTest extends NodeTypeResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,90 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
/**
* ResourceTestBase for NodeType entity.
*/
abstract class NodeTypeResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'node_type';
/**
* The NodeType entity.
*
* @var \Drupal\node\NodeTypeInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer content types', 'access content']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create a "Camelids" node type.
$camelids = NodeType::create([
'name' => 'Camelids',
'type' => 'camelids',
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
]);
$camelids->save();
return $camelids;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [],
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
'display_submitted' => TRUE,
'help' => NULL,
'langcode' => 'en',
'name' => 'Camelids',
'new_revision' => TRUE,
'preview_mode' => 1,
'status' => TRUE,
'type' => 'camelids',
'uuid' => $this->entity->uuid(),
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
return "The 'access content' permission is required.";
}
}
@@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class NodeTypeXmlAnonTest extends NodeTypeResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}
@@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class NodeTypeXmlBasicAuthTest extends NodeTypeResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class NodeTypeXmlCookieTest extends NodeTypeResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class NodeXmlAnonTest extends NodeResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
public function testPatchPath() {
// Deserialization of the XML format is not supported.
$this->markTestSkipped();
}
}
@@ -0,0 +1,44 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class NodeXmlBasicAuthTest extends NodeResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
/**
* {@inheritdoc}
*/
public function testPatchPath() {
// Deserialization of the XML format is not supported.
$this->markTestSkipped();
}
}
@@ -0,0 +1,39 @@
<?php
namespace Drupal\Tests\node\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class NodeXmlCookieTest extends NodeResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
/**
* {@inheritdoc}
*/
public function testPatchPath() {
// Deserialization of the XML format is not supported.
$this->markTestSkipped();
}
}
@@ -9,6 +9,7 @@ use Drupal\FunctionalTests\Update\UpdatePathTestBase;
* Tests that node settings are properly updated during database updates.
*
* @group node
* @group legacy
*/
class NodeUpdateTest extends UpdatePathTestBase {
@@ -2,7 +2,7 @@
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
@@ -88,7 +88,7 @@ class BulkFormAccessTest extends NodeTestBase {
'action' => 'node_unpublish_action',
];
$this->drupalPostForm('test-node-bulk-form', $edit, t('Apply to selected items'));
$this->assertRaw(SafeMarkup::format('No access to execute %action on the @entity_type_label %entity_label.', [
$this->assertRaw(new FormattableMarkup('No access to execute %action on the @entity_type_label %entity_label.', [
'%action' => 'Unpublish content',
'@entity_type_label' => 'Content',
'%entity_label' => $node->label(),
@@ -117,7 +117,7 @@ class BulkFormAccessTest extends NodeTestBase {
];
$this->drupalPostForm('test-node-bulk-form', $edit, t('Apply to selected items'));
// Test that the action message isn't shown.
$this->assertNoRaw(SafeMarkup::format('%action was applied to 1 item.', [
$this->assertNoRaw(new FormattableMarkup('%action was applied to 1 item.', [
'%action' => 'Unpublish content',
]));
// Re-load the node and check the status.
@@ -2,7 +2,7 @@
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\views\Views;
@@ -55,7 +55,7 @@ class BulkFormTest extends NodeTestBase {
'promote' => FALSE,
];
$node = $this->drupalCreateNode($values);
$this->pass(SafeMarkup::format('Node %title created with language %langcode.', ['%title' => $node->label(), '%langcode' => $node->language()->getId()]));
$this->pass(new FormattableMarkup('Node %title created with language %langcode.', ['%title' => $node->label(), '%langcode' => $node->language()->getId()]));
$this->nodes[] = $node;
}
@@ -66,7 +66,7 @@ class BulkFormTest extends NodeTestBase {
if (!$node->hasTranslation($langcode)) {
$title = $this->randomMachineName() . ' [' . $node->id() . ':' . $langcode . ']';
$translation = $node->addTranslation($langcode, ['title' => $title, 'promote' => FALSE]);
$this->pass(SafeMarkup::format('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
$this->pass(new FormattableMarkup('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
}
}
$node->save();
@@ -77,7 +77,7 @@ class BulkFormTest extends NodeTestBase {
$langcode = 'en';
$title = $this->randomMachineName() . ' [' . $node->id() . ':' . $langcode . ']';
$translation = $node->addTranslation($langcode, ['title' => $title]);
$this->pass(SafeMarkup::format('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
$this->pass(new FormattableMarkup('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
$node->save();
// Check that all created translations are selected by the test view.
@@ -249,15 +249,15 @@ class BulkFormTest extends NodeTestBase {
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
$label = $this->loadNode(1)->label();
$this->assertText("$label (Original translation) - The following content translations will be deleted:");
$this->assertText("$label (Original translation) - The following content item translations will be deleted:");
$label = $this->loadNode(2)->label();
$this->assertText("$label (Original translation) - The following content translations will be deleted:");
$this->assertText("$label (Original translation) - The following content item translations will be deleted:");
$label = $this->loadNode(3)->getTranslation('en')->label();
$this->assertText($label);
$this->assertNoText("$label (Original translation) - The following content translations will be deleted:");
$this->assertNoText("$label (Original translation) - The following content item translations will be deleted:");
$label = $this->loadNode(4)->label();
$this->assertText($label);
$this->assertNoText("$label (Original translation) - The following content translations will be deleted:");
$this->assertNoText("$label (Original translation) - The following content item translations will be deleted:");
$this->drupalPostForm(NULL, [], t('Delete'));
@@ -273,7 +273,7 @@ class BulkFormTest extends NodeTestBase {
$node = $this->loadNode(5);
$this->assertTrue($node, '5: Node has not been deleted');
$this->assertText('Deleted 8 posts.');
$this->assertText('Deleted 8 content items.');
}
/**
@@ -284,7 +284,7 @@ class FrontPageTest extends ViewTestBase {
[
'value' => $this->randomMachineName(32),
'format' => filter_default_format(),
]
],
],
'type' => 'article',
'created' => $i,
@@ -75,7 +75,7 @@ class NodeLanguageTest extends NodeTestBase {
],
'fr' => [
'Premier nœud fr',
]
],
];
// Create nodes with translations.
@@ -0,0 +1,60 @@
<?php
namespace Drupal\Tests\node\FunctionalJavascript;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests the JavaScript prevention of navigation away from node previews.
*
* @group node
*/
class NodePreviewLinkTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'filter'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
]);
$filtered_html_format->save();
$this->drupalCreateContentType(['type' => 'test']);
$user = $this->drupalCreateUser([
'access content',
'edit own test content',
'create test content',
$filtered_html_format->getPermissionName(),
]);
$this->drupalLogin($user);
}
/**
* Test the behavior of clicking preview links.
*/
public function testPreviewLinks() {
$assertSession = $this->assertSession();
$this->drupalPostForm('node/add/test', [
'title[0][value]' => 'Test node',
'body[0][value]' => '<a href="#foo">Anchor link</a><a href="/foo">Normal link</a>',
], t('Preview'));
$this->clickLink('Anchor link');
$assertSession->pageTextNotContains('Leave preview?');
$this->clickLink('Normal link');
$assertSession->pageTextContains('Leave preview?');
$this->click('button:contains("Leave preview")');
$this->assertStringEndsWith('/foo', $this->getUrl());
}
}
@@ -2,14 +2,14 @@
namespace Drupal\Tests\node\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests the JavaScript updating of summaries on content type form.
*
* @group node
*/
class TestSettingSummariesContentType extends JavascriptTestBase {
class TestSettingSummariesContentType extends WebDriverTestBase {
/**
* {@inheritdoc}
@@ -33,6 +33,8 @@ class TestSettingSummariesContentType extends JavascriptTestBase {
public function testWorkflowSummary() {
$this->drupalGet('admin/structure/types/manage/test');
$page = $this->getSession()->getPage();
$page->find('css', 'a[href="#edit-workflow"]')->click();
$this->assertSession()->waitForElementVisible('css', '[name="options[status]"]');
$page->findField('options[status]')->uncheck();
$page->findField('options[sticky]')->check();
$page->findField('options[promote]')->check();
@@ -26,7 +26,7 @@ class NodeImportChangeTest extends KernelTestBase {
parent::setUp();
// Set default storage backend.
$this->installConfig(['field', 'node_test_config']);
$this->installConfig(['system', 'field', 'node_test_config']);
}
/**
@@ -28,7 +28,7 @@ class NodeImportCreateTest extends KernelTestBase {
$this->installEntitySchema('user');
// Set default storage backend.
$this->installConfig(['field']);
$this->installConfig(['system', 'field']);
}
/**
@@ -36,7 +36,7 @@ class MigrateNodeBundleSettingsTest extends MigrateDrupal6TestBase {
$this->executeMigrations([
'd6_node_setting_promote',
'd6_node_setting_status',
'd6_node_setting_sticky'
'd6_node_setting_sticky',
]);
}
@@ -19,7 +19,13 @@ class MigrateNodeTest extends MigrateNodeTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'content_translation', 'menu_ui'];
public static $modules = [
'language',
'content_translation',
'menu_ui',
// Required for translation migrations.
'migrate_drupal_multilingual',
];
/**
* {@inheritdoc}
@@ -94,6 +100,10 @@ class MigrateNodeTest extends MigrateNodeTestBase {
$this->assertCount(2, $node->field_company);
$this->assertSame('Klingon Empire', $node->field_company[0]->entity->label());
$this->assertSame('Romulan Empire', $node->field_company[1]->entity->label());
$this->assertCount(1, $node->field_company_2);
$this->assertSame('Klingon Empire', $node->field_company_2[0]->entity->label());
$this->assertCount(1, $node->field_company_3);
$this->assertSame('Romulan Empire', $node->field_company_3[0]->entity->label());
// Test that user reference field values were migrated.
$this->assertCount(1, $node->field_commander);
@@ -223,7 +233,7 @@ class MigrateNodeTest extends MigrateNodeTestBase {
$default_connection = \Drupal::database();
$default_connection->truncate($table_name)->execute();
if ($new_row) {
$hash = $migration->getIdMap()->getSourceIDsHash(['nid' => $new_row['sourceid1']]);
$hash = $migration->getIdMap()->getSourceIdsHash(['nid' => $new_row['sourceid1']]);
$new_row['source_ids_hash'] = $hash;
$default_connection->insert($table_name)
->fields($new_row)
@@ -38,7 +38,7 @@ class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
$this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_page->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationID(['test_page']), ['test_page']);
$this->assertIdentical($id_map->lookupDestinationId(['test_page']), ['test_page']);
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_page', 'body');
@@ -57,7 +57,7 @@ class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
$this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_story->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationID(['test_story']), ['test_story']);
$this->assertIdentical($id_map->lookupDestinationId(['test_story']), ['test_story']);
// Test we don't have a body field.
$field = FieldConfig::loadByName('node', 'test_story', 'body');
@@ -76,7 +76,7 @@ class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
$this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
$this->assertIdentical(TRUE, $node_type_event->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationID(['test_event']), ['test_event']);
$this->assertIdentical($id_map->lookupDestinationId(['test_event']), ['test_event']);
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_event', 'body');
@@ -29,7 +29,7 @@ class MigrateViewModesTest extends MigrateDrupal6TestBase {
$this->assertIdentical(FALSE, is_null($view_mode), 'Preview view mode loaded.');
$this->assertIdentical('Preview', $view_mode->label(), 'View mode has correct label.');
// Test the ID map.
$this->assertIdentical(['node', 'preview'], $this->getMigration('d6_view_modes')->getIdMap()->lookupDestinationID([1]));
$this->assertIdentical(['node', 'preview'], $this->getMigration('d6_view_modes')->getIdMap()->lookupDestinationId([1]));
}
}
@@ -20,6 +20,8 @@ class NodeTranslationRedirectTest extends MigrateDrupal6TestBase {
'content_translation',
'language',
'menu_ui',
// Required for translation migrations.
'migrate_drupal_multilingual',
];
/**
@@ -31,6 +31,8 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
'language',
'link',
'menu_ui',
// Required for translation migrations.
'migrate_drupal_multilingual',
'node',
'taxonomy',
'telephone',
@@ -68,9 +70,22 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
'd7_field_instance',
'd7_node',
'd7_node_translation',
'd7_node_entity_translation',
]);
}
/**
* {@inheritdoc}
*/
protected function getFileMigrationInfo() {
return [
'path' => 'public://sites/default/files/cube.jpeg',
'size' => '3620',
'base_path' => 'public://',
'plugin_id' => 'd7_file',
];
}
/**
* Asserts various aspects of a node.
*
@@ -139,8 +154,8 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
* Test node migration from Drupal 7 to 8.
*/
public function testNode() {
$this->assertEntity(1, 'test_content_type', 'en', 'A Node', '2', TRUE, '1421727515', '1441032132', TRUE, FALSE);
$this->assertRevision(1, 'A Node', '1', NULL, '1441032132');
$this->assertEntity(1, 'test_content_type', 'en', 'An English Node', '2', TRUE, '1421727515', '1441032132', TRUE, FALSE);
$this->assertRevision(1, 'An English Node', '1', NULL, '1441032132');
$node = Node::load(1);
$this->assertTrue($node->field_boolean->value);
@@ -164,6 +179,15 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
$this->assertEquals('default@example.com', $node->field_email->value);
$this->assertEquals('another@example.com', $node->field_email[1]->value);
$this->assertEquals(CommentItemInterface::OPEN, $node->comment_node_test_content_type->status);
$this->assertEquals('3.1416', $node->field_float_list[0]->value);
// Test that fields translated with Entity Translation are migrated.
$node_fr = $node->getTranslation('fr');
$this->assertEquals('A French Node', $node_fr->getTitle());
$this->assertEquals('6', $node_fr->field_integer->value);
$node_is = $node->getTranslation('is');
$this->assertEquals('An Icelandic Node', $node_is->getTitle());
$this->assertEquals('7', $node_is->field_integer->value);
$node = Node::load(2);
$this->assertEquals('en', $node->langcode->value);
@@ -20,6 +20,8 @@ class NodeTranslationRedirectTest extends MigrateDrupal7TestBase {
'content_translation',
'language',
'menu_ui',
// Required for translation migrations.
'migrate_drupal_multilingual',
'node',
'text',
];
@@ -2,7 +2,7 @@
namespace Drupal\Tests\node\Kernel;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
@@ -101,35 +101,35 @@ class NodeFieldAccessTest extends EntityKernelTestBase {
// Checks on view operations.
foreach ($test_users as $account) {
$may_view = $node1->{$field}->access('view', $account);
$this->assertTrue($may_view, SafeMarkup::format('Any user may view the field @name.', ['@name' => $field]));
$this->assertTrue($may_view, new FormattableMarkup('Any user may view the field @name.', ['@name' => $field]));
}
// Checks on edit operations.
$may_update = $node1->{$field}->access('edit', $page_creator_user);
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field]));
$this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field]));
$may_update = $node2->{$field}->access('edit', $page_creator_user);
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field]));
$this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field]));
$may_update = $node2->{$field}->access('edit', $page_manager_user);
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
$this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
$may_update = $node1->{$field}->access('edit', $page_manager_user);
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
$this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
$may_update = $node2->{$field}->access('edit', $page_unrelated_user);
$this->assertFalse($may_update, SafeMarkup::format('Users not having permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
$this->assertFalse($may_update, new FormattableMarkup('Users not having permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
$may_update = $node1->{$field}->access('edit', $content_admin_user) && $node3->status->access('edit', $content_admin_user);
$this->assertTrue($may_update, SafeMarkup::format('Users with permission "administer nodes" may edit @name fields on all nodes.', ['@name' => $field]));
$this->assertTrue($may_update, new FormattableMarkup('Users with permission "administer nodes" may edit @name fields on all nodes.', ['@name' => $field]));
}
foreach ($this->readOnlyFields as $field) {
// Check view operation.
foreach ($test_users as $account) {
$may_view = $node1->{$field}->access('view', $account);
$this->assertTrue($may_view, SafeMarkup::format('Any user may view the field @name.', ['@name' => $field]));
$this->assertTrue($may_view, new FormattableMarkup('Any user may view the field @name.', ['@name' => $field]));
}
// Check edit operation.
foreach ($test_users as $account) {
$may_view = $node1->{$field}->access('edit', $account);
$this->assertFalse($may_view, SafeMarkup::format('No user is not allowed to edit the field @name.', ['@name' => $field]));
$this->assertFalse($may_view, new FormattableMarkup('No user is not allowed to edit the field @name.', ['@name' => $field]));
}
}
@@ -23,7 +23,6 @@ class NodeListBuilderTest extends KernelTestBase {
$this->installEntitySchema('node');
}
/**
* Tests that the correct cache contexts are set.
*/
@@ -0,0 +1,357 @@
<?php
namespace Drupal\Tests\node\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests Drupal 7 node entity translations source plugin.
*
* @covers \Drupal\node\Plugin\migrate\source\d7\NodeEntityTranslation
*
* @group node
*/
class NodeEntityTranslationTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'user', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['entity_translation'] = [
[
'entity_type' => 'node',
'entity_id' => 2,
'revision_id' => 2,
'language' => 'en',
'source' => '',
'uid' => 1,
'status' => 1,
'translate' => 0,
'created' => 1531343498,
'changed' => 1531343498,
],
[
'entity_type' => 'node',
'entity_id' => 2,
'revision_id' => 2,
'language' => 'fr',
'source' => 'en',
'uid' => 1,
'status' => 1,
'translate' => 0,
'created' => 1531343508,
'changed' => 1531343508,
],
[
'entity_type' => 'node',
'entity_id' => 2,
'revision_id' => 2,
'language' => 'es',
'source' => 'en',
'uid' => 1,
'status' => 1,
'translate' => 0,
'created' => 1531343528,
'changed' => 1531343528,
],
];
$tests[0]['source_data']['field_config'] = [
[
'id' => 1,
'field_name' => 'body',
'type' => 'text_with_summary',
'module' => 'text',
'active' => 1,
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => 1,
'locked' => 1,
'data' => 'a:0:{}',
'cardinality' => 1,
'translatable' => 1,
'deleted' => 0,
],
[
'id' => 2,
'field_name' => 'title_field',
'type' => 'text',
'module' => 'text',
'active' => 1,
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => 1,
'locked' => 1,
'data' => 'a:0:{}',
'cardinality' => 1,
'translatable' => 1,
'deleted' => 0,
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
'id' => 1,
'field_id' => 1,
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'article',
'data' => 'a:0:{}',
'deleted' => 0,
],
[
'id' => 2,
'field_id' => 1,
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:0:{}',
'deleted' => 0,
],
[
'id' => 3,
'field_id' => 2,
'field_name' => 'title_field',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:0:{}',
'deleted' => 0,
],
];
$tests[0]['source_data']['field_revision_body'] = [
[
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => 0,
'entity_id' => 1,
'revision_id' => 1,
'language' => 'en',
'delta' => 0,
'body_value' => 'Untranslated body',
'body_summary' => 'Untranslated summary',
'body_format' => 'filtered_html',
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => 0,
'entity_id' => 2,
'revision_id' => 2,
'language' => 'en',
'delta' => 0,
'body_value' => 'English body',
'body_summary' => 'English summary',
'body_format' => 'filtered_html',
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => 0,
'entity_id' => 2,
'revision_id' => 2,
'language' => 'fr',
'delta' => 0,
'body_value' => 'French body',
'body_summary' => 'French summary',
'body_format' => 'filtered_html',
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => 0,
'entity_id' => 2,
'revision_id' => 2,
'language' => 'es',
'delta' => 0,
'body_value' => 'Spanish body',
'body_summary' => 'Spanish summary',
'body_format' => 'filtered_html',
],
];
$tests[0]['source_data']['field_revision_title_field'] = [
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'English Source',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'fr',
'delta' => '0',
'title_field_value' => 'French Translation',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'es',
'delta' => '0',
'title_field_value' => 'Spanish Translation',
'title_field_format' => NULL,
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => 1,
'vid' => 1,
'type' => 'article',
'language' => 'en',
'title' => 'Untranslated article',
'uid' => 1,
'status' => 1,
'created' => 1531343456,
'changed' => 1531343456,
'comment' => 2,
'promote' => 1,
'sticky' => 0,
'tnid' => 0,
'translate' => 0,
],
[
'nid' => 2,
'vid' => 2,
'type' => 'page',
'language' => 'en',
'title' => 'Translated page',
'uid' => 1,
'status' => 1,
'created' => 1531343528,
'changed' => 1531343528,
'comment' => 1,
'promote' => 0,
'sticky' => 0,
'tnid' => 0,
'translate' => 0,
],
];
$tests[0]['source_data']['node_revision'] = [
[
'nid' => 1,
'vid' => 1,
'uid' => 1,
'title' => 'Untranslated article',
'log' => '',
'timestamp' => 1531343456,
'status' => 1,
'comment' => 2,
'promote' => 1,
'sticky' => 0,
],
[
'nid' => 2,
'vid' => 2,
'uid' => 1,
'title' => 'Translated page',
'log' => '',
'timestamp' => 1531343528,
'status' => 1,
'comment' => 1,
'promote' => 0,
'sticky' => 0,
],
];
$tests[0]['source_data']['system'] = [
[
'name' => 'title',
'type' => 'module',
'status' => 1,
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'entity_id' => 2,
'revision_id' => 2,
'language' => 'fr',
'source' => 'en',
'uid' => 1,
'status' => 1,
'created' => 1531343508,
'changed' => 1531343508,
'type' => 'page',
'title' => 'French Translation',
'promote' => 0,
'sticky' => 0,
'log' => '',
'timestamp' => 1531343528,
'revision_uid' => 1,
'body' => [
[
'value' => 'French body',
'summary' => 'French summary',
'format' => 'filtered_html',
],
],
],
[
'entity_id' => 2,
'revision_id' => 2,
'language' => 'es',
'source' => 'en',
'uid' => 1,
'status' => 1,
'created' => 1531343528,
'changed' => 1531343528,
'type' => 'page',
'title' => 'Spanish Translation',
'promote' => 0,
'sticky' => 0,
'log' => '',
'timestamp' => 1531343528,
'revision_uid' => 1,
'body' => [
[
'value' => 'Spanish body',
'summary' => 'Spanish summary',
'format' => 'filtered_html',
],
],
],
];
// Do an automatic count.
$tests[0]['expected_count'] = NULL;
// Set up source plugin configuration.
$tests[0]['configuration'] = [
'node_type' => 'page',
];
// The source data.
$tests[1]['source_data'] = $tests[0]['source_data'];
// The expected results.
$tests[1]['expected_data'] = [];
// Do an automatic count.
$tests[1]['expected_count'] = NULL;
// Set up source plugin configuration.
$tests[1]['configuration'] = [
'node_type' => 'article',
];
return $tests;
}
}
@@ -170,6 +170,16 @@ class NodeTest extends MigrateSqlSourceTestBase {
'sticky' => 0,
],
];
$tests[0]['source_data']['field_config'] = [
[
'id' => '2',
'translatable' => '0',
],
[
'id' => '3',
'translatable' => '1',
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
'id' => '2',
@@ -189,6 +199,15 @@ class NodeTest extends MigrateSqlSourceTestBase {
'data' => 'a:0:{}',
'deleted' => '0',
],
[
'id' => '4',
'field_id' => '3',
'field_name' => 'title_field',
'entity_type' => 'node',
'bundle' => 'article',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$tests[0]['source_data']['field_revision_body'] = [
[
@@ -252,6 +271,48 @@ class NodeTest extends MigrateSqlSourceTestBase {
'body_format' => 'filtered_html',
],
];
$tests[0]['source_data']['field_revision_title_field'] = [
[
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '5',
'revision_id' => '5',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'node title 5 (title_field)',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '6',
'revision_id' => '6',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'node title 5 (title_field)',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '7',
'revision_id' => '7',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'node title 5 (title_field)',
'title_field_format' => NULL,
],
];
$tests[0]['source_data']['system'] = [
[
'name' => 'title',
'type' => 'module',
'status' => 1,
],
];
// The expected results.
$tests[0]['expected_data'] = [
@@ -312,7 +373,7 @@ class NodeTest extends MigrateSqlSourceTestBase {
'vid' => 5,
'type' => 'article',
'language' => 'en',
'title' => 'node title 5',
'title' => 'node title 5 (title_field)',
'node_uid' => 1,
'revision_uid' => 2,
'status' => 1,
@@ -338,7 +399,7 @@ class NodeTest extends MigrateSqlSourceTestBase {
'vid' => 6,
'type' => 'article',
'language' => 'en',
'title' => 'node title 5',
'title' => 'node title 5 (title_field)',
'node_uid' => 1,
'revision_uid' => 1,
'status' => 1,
@@ -31,7 +31,7 @@ class NodeTranslationTest extends NodeTest {
'vid' => 7,
'type' => 'article',
'language' => 'fr',
'title' => 'fr - node title 5',
'title' => 'node title 5 (title_field)',
'node_uid' => 1,
'revision_uid' => 1,
'status' => 1,
@@ -2,7 +2,6 @@
namespace Drupal\Tests\node\Kernel;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
@@ -72,9 +71,6 @@ class SummaryLengthTest extends KernelTestBase {
'label' => 'Fallback',
'pattern' => 'Y-m-d',
])->save();
// Enable multibyte support.
Unicode::setStatus(Unicode::STATUS_MULTIBYTE);
}
/**
@@ -54,6 +54,8 @@ class NodeBulkFormTest extends UnitTestCase {
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$messenger = $this->getMock('Drupal\Core\Messenger\MessengerInterface');
$views_data = $this->getMockBuilder('Drupal\views\ViewsData')
->disableOriginalConstructor()
->getMock();
@@ -84,7 +86,7 @@ class NodeBulkFormTest extends UnitTestCase {
$definition['title'] = '';
$options = [];
$node_bulk_form = new NodeBulkForm([], 'node_bulk_form', $definition, $entity_manager, $language_manager);
$node_bulk_form = new NodeBulkForm([], 'node_bulk_form', $definition, $entity_manager, $language_manager, $messenger);
$node_bulk_form->init($executable, $display, $options);
$this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $node_bulk_form);