Core and composer updates

This commit is contained in:
Rob Davies 2017-07-03 16:47:07 +01:00
parent a82634bb98
commit 62cac30480
1118 changed files with 21770 additions and 6306 deletions

View file

@ -296,7 +296,7 @@ display:
- user
- 'user.node_grants:view'
- user.permissions
max-age: 0
max-age: -1
tags: { }
block_1:
display_plugin: block
@ -312,5 +312,5 @@ display:
- user
- 'user.node_grants:view'
- user.permissions
max-age: 0
max-age: -1
tags: { }

View file

@ -1,6 +1,8 @@
langcode: en
status: false
dependencies:
config:
- system.menu.main
module:
- node
- user

View file

@ -25,7 +25,7 @@ process:
promote: promote
sticky: sticky
'body/format':
plugin: migration
plugin: migration_lookup
migration: d6_filter_format
source: format
'body/value': body

View file

@ -22,7 +22,7 @@ process:
promote: promote
sticky: sticky
'body/format':
plugin: migration
plugin: migration_lookup
migration: d6_filter_format
source: format
'body/value': body

View file

@ -23,7 +23,7 @@ process:
promote: promote
sticky: sticky
'body/format':
plugin: migration
plugin: migration_lookup
migration: d6_filter_format
source: format
'body/value': body

View file

@ -20,5 +20,7 @@ process:
'settings/node/options': options
create_body: has_body
create_body_label: body_label
'third_party_settings/menu_ui/available_menus': available_menus
'third_party_settings/menu_ui/parent': parent
destination:
plugin: entity:node_type

View file

@ -17,5 +17,7 @@ process:
new_revision: 'options/revision'
create_body: create_body
create_body_label: body_label
'third_party_settings/menu_ui/available_menus': available_menus
'third_party_settings/menu_ui/parent': parent
destination:
plugin: entity:node_type

View file

@ -113,6 +113,7 @@ entity.node_type.edit_form:
path: '/admin/structure/types/manage/{node_type}'
defaults:
_entity_form: 'node_type.edit'
_title_callback: '\Drupal\Core\Entity\Controller\EntityController::title'
requirements:
_permission: 'administer content types'

View file

@ -36,6 +36,13 @@ class NodeRevisionRevertForm extends ConfirmFormBase {
*/
protected $dateFormatter;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs a new NodeRevisionRevertForm.
*
@ -47,6 +54,7 @@ class NodeRevisionRevertForm extends ConfirmFormBase {
public function __construct(EntityStorageInterface $node_storage, DateFormatterInterface $date_formatter) {
$this->nodeStorage = $node_storage;
$this->dateFormatter = $date_formatter;
$this->time = \Drupal::service('datetime.time');
}
/**
@ -114,6 +122,8 @@ class NodeRevisionRevertForm extends ConfirmFormBase {
$this->revision = $this->prepareRevertedRevision($this->revision, $form_state);
$this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
$this->revision->setRevisionCreationTime($this->time->getRequestTime());
$this->revision->setChangedTime($this->time->getRequestTime());
$this->revision->save();
$this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);

View file

@ -9,6 +9,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationDeriverTrait;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -38,6 +39,20 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
*/
protected $cckPluginManager;
/**
* Already-instantiated field plugins, keyed by ID.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[]
*/
protected $fieldPluginCache;
/**
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $fieldPluginManager;
/**
* Whether or not to include translations.
*
@ -52,12 +67,15 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
* The base plugin ID for the plugin ID.
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager
* The CCK plugin manager.
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_manager
* The field plugin manager.
* @param bool $translations
* Whether or not to include translations.
*/
public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, $translations) {
public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager, $translations) {
$this->basePluginId = $base_plugin_id;
$this->cckPluginManager = $cck_manager;
$this->fieldPluginManager = $field_manager;
$this->includeTranslations = $translations;
}
@ -69,6 +87,7 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
return new static(
$base_plugin_id,
$container->get('plugin.manager.migrate.cckfield'),
$container->get('plugin.manager.migrate.field'),
$container->get('module_handler')->moduleExists('content_translation')
);
}
@ -100,7 +119,7 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
return $this->derivatives;
}
// Read all CCK field instance definitions in the source database.
// Read all field instance definitions in the source database.
$fields = [];
try {
$source_plugin = static::getSourcePlugin('d6_field_instance');
@ -112,7 +131,7 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
}
catch (RequirementsException $e) {
// If checkRequirements() failed then the content module did not exist and
// we do not have any CCK fields. Therefore, $fields will be empty and
// we do not have any fields. Therefore, $fields will be empty and
// below we'll create a migration just for the node properties.
}
@ -135,20 +154,31 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
$values['migration_dependencies']['required'][] = 'd6_node:' . $node_type;
}
/** @var \Drupal\migrate\Plugin\Migration $migration */
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
if (isset($fields[$node_type])) {
foreach ($fields[$node_type] as $field_name => $info) {
$field_type = $info['type'];
try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration);
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 6], $migration);
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration);
if (!isset($this->fieldPluginCache[$field_type])) {
$this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, ['core' => 6], $migration);
}
$this->cckPluginCache[$field_type]
->processCckFieldValues($migration, $field_name, $info);
$this->fieldPluginCache[$field_type]
->processFieldValues($migration, $field_name, $info);
}
catch (PluginNotFoundException $ex) {
$migration->setProcessOfProperty($field_name, $field_name);
try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration);
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 6], $migration);
}
$this->cckPluginCache[$field_type]
->processCckFieldValues($migration, $field_name, $info);
}
catch (PluginNotFoundException $ex) {
$migration->setProcessOfProperty($field_name, $field_name);
}
}
}
}

View file

@ -9,6 +9,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationDeriverTrait;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -38,6 +39,20 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
*/
protected $cckPluginManager;
/**
* Already-instantiated field plugins, keyed by ID.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[]
*/
protected $fieldPluginCache;
/**
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $fieldPluginManager;
/**
* Whether or not to include translations.
*
@ -52,12 +67,15 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
* The base plugin ID for the plugin ID.
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager
* The CCK plugin manager.
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_manager
* The field plugin manager.
* @param bool $translations
* Whether or not to include translations.
*/
public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, $translations) {
public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager, $translations) {
$this->basePluginId = $base_plugin_id;
$this->cckPluginManager = $cck_manager;
$this->fieldPluginManager = $field_manager;
$this->includeTranslations = $translations;
}
@ -69,6 +87,7 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
return new static(
$base_plugin_id,
$container->get('plugin.manager.migrate.cckfield'),
$container->get('plugin.manager.migrate.field'),
$container->get('module_handler')->moduleExists('content_translation')
);
}
@ -134,15 +153,25 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
foreach ($fields[$node_type] as $field_name => $info) {
$field_type = $info['type'];
try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration);
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 7], $migration);
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration);
if (!isset($this->fieldPluginCache[$field_type])) {
$this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, ['core' => 7], $migration);
}
$this->cckPluginCache[$field_type]
->processCckFieldValues($migration, $field_name, $info);
$this->fieldPluginCache[$field_type]
->processFieldValues($migration, $field_name, $info);
}
catch (PluginNotFoundException $ex) {
$migration->setProcessOfProperty($field_name, $field_name);
try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration);
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 7], $migration);
}
$this->cckPluginCache[$field_type]
->processCckFieldValues($migration, $field_name, $info);
}
catch (PluginNotFoundException $ex) {
$migration->setProcessOfProperty($field_name, $field_name);
}
}
}
}

View file

@ -107,6 +107,10 @@ class NodeType extends DrupalSqlBase {
$submitted = isset($this->themeSettings['toggle_node_info_' . $type]) ? $this->themeSettings['toggle_node_info_' . $type] : FALSE;
$row->setSourceProperty('display_submitted', $submitted);
if ($default_node_menu = $this->variableGet('menu_default_node_menu', NULL)) {
$row->setSourceProperty('available_menus', [$default_node_menu]);
$row->setSourceProperty('parent', $default_node_menu . ':');
}
return parent::prepareRow($row);
}

View file

@ -101,6 +101,12 @@ class NodeType extends DrupalSqlBase {
$row->setSourceProperty('display_submitted', $this->variableGet('node_submitted_' . $type, TRUE));
if ($menu_options = $this->variableGet('menu_options_' . $type, NULL)) {
$row->setSourceProperty('available_menus', $menu_options);
}
if ($parent = $this->variableGet('menu_parent_' . $type, NULL)) {
$row->setSourceProperty('parent', $parent . ':');
}
return parent::prepareRow($row);
}

View file

@ -15,7 +15,7 @@ class UidRevision extends Uid {
public function query($group_by = FALSE) {
$this->ensureMyTable();
$placeholder = $this->placeholder();
$this->query->addWhereExpression(0, "$this->tableAlias.revision_uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nfr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $this->argument]);
$this->query->addWhereExpression(0, "$this->tableAlias.uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $this->argument]);
}
}

View file

@ -2,8 +2,13 @@
namespace Drupal\node\Tests;
@trigger_error('\Drupal\Tests\node\Functional\AssertButtonsTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\node\Functional\AssertButtonsTrait', E_USER_DEPRECATED);
/**
* Asserts that buttons are present on a page.
*
* @deprecated Scheduled for removal before Drupal 9.0.0.
* Use \Drupal\Tests\node\Functional\AssertButtonsTrait instead.
*/
trait AssertButtonsTrait {

View file

@ -195,6 +195,7 @@ class NodeRevisionsTest extends NodeTestBase {
['%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
'@type' => 'Basic page', '%title' => $nodes[1]->label()]), 'Revision deleted.');
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Revision not found.');
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Field revision not found.');
// Set the revision timestamp to an older date to make sure that the
// confirmation message correctly displays the stored revision date.

View file

@ -5,6 +5,7 @@ namespace Drupal\node\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\Core\Url;
use Drupal\system\Tests\Menu\AssertBreadcrumbTrait;
/**
* Ensures that node type functions work correctly.
@ -13,12 +14,14 @@ use Drupal\Core\Url;
*/
class NodeTypeTest extends NodeTestBase {
use AssertBreadcrumbTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['field_ui'];
public static $modules = ['field_ui', 'block'];
/**
* Ensures that node type functions (node_type_get_*) work correctly.
@ -84,6 +87,7 @@ class NodeTypeTest extends NodeTestBase {
* Tests editing a node type using the UI.
*/
public function testNodeTypeEditing() {
$this->drupalPlaceBlock('system_breadcrumb_block');
$web_user = $this->drupalCreateUser(['bypass node access', 'administer content types', 'administer node fields']);
$this->drupalLogin($web_user);
@ -134,6 +138,12 @@ class NodeTypeTest extends NodeTestBase {
$this->drupalPostForm('admin/structure/types/manage/page/fields/node.page.body/delete', [], t('Delete'));
// Resave the settings for this type.
$this->drupalPostForm('admin/structure/types/manage/page', [], t('Save content type'));
$front_page_path = Url::fromRoute('<front>')->toString();
$this->assertBreadcrumb('admin/structure/types/manage/page/fields', [
$front_page_path => 'Home',
'admin/structure/types' => 'Content types',
'admin/structure/types/manage/page' => 'NewBar',
]);
// Check that the body field doesn't exist.
$this->drupalGet('node/add/page');
$this->assertNoRaw('Body', 'Body field was not found.');
@ -143,6 +153,7 @@ class NodeTypeTest extends NodeTestBase {
* Tests deleting a content type that still has content.
*/
public function testNodeTypeDeletion() {
$this->drupalPlaceBlock('page_title_block');
// Create a content type programmatically.
$type = $this->drupalCreateContentType();

View file

@ -2,11 +2,16 @@
namespace Drupal\node\Tests\Views;
@trigger_error('\Drupal\node\Tests\Views\NodeTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\node\Functional\Views\NodeTestBase', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Base class for all node tests.
*
* @deprecated Scheduled for removal before Drupal 9.0.0.
* Use \Drupal\Tests\node\Functional\Views\NodeTestBase instead.
*/
abstract class NodeTestBase extends ViewTestBase {

View file

@ -0,0 +1,106 @@
langcode: en
status: true
dependencies:
module:
- node
- user
id: test_argument_node_uid_revision
label: test_argument_node_uid_revision
module: views
description: ''
tag: default
base_table: node_field_data
base_field: nid
core: 8.0-dev
display:
default:
display_options:
access:
type: perm
cache:
type: tag
exposed_form:
type: basic
fields:
nid:
id: nid
table: node_field_data
field: nid
plugin_id: field
entity_type: node
entity_field: nid
filter_groups:
groups:
1: AND
operator: AND
filters: { }
sorts:
nid:
id: nid
table: node_field_data
field: nid
order: ASC
plugin_id: standard
relationship: none
entity_type: node
entity_field: nid
pager:
type: full
query:
type: views_query
style:
type: default
row:
type: fields
display_extenders: { }
arguments:
uid_revision:
id: uid_revision
table: node_field_data
field: uid_revision
relationship: none
group_type: group
admin_label: ''
default_action: empty
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
entity_type: node
plugin_id: node_uid_revision
display_plugin: default
display_title: Master
id: default
position: 0
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
- user.permissions
tags: { }

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\Tests\node\Functional;
/**
* Asserts that buttons are present on a page.
*/
trait AssertButtonsTrait {
/**
* Assert method to verify the buttons in the dropdown element.
*
* @param array $buttons
* A collection of buttons to assert for on the page.
* @param bool $dropbutton
* Whether to check if the buttons are in a dropbutton widget or not.
*/
public function assertButtons(array $buttons, $dropbutton = TRUE) {
// Try to find a Save button.
$save_button = $this->xpath('//input[@type="submit"][@value="Save"]');
// Verify that the number of buttons passed as parameters is
// available in the dropbutton widget.
if ($dropbutton) {
$i = 0;
$count = count($buttons);
// Assert there is no save button.
$this->assertTrue(empty($save_button));
// Dropbutton elements.
/** @var \Behat\Mink\Element\NodeElement[] $elements */
$elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]');
$this->assertEqual($count, count($elements));
foreach ($elements as $element) {
$value = $element->getValue() ?: '';
$this->assertEqual($buttons[$i], $value);
$i++;
}
}
else {
// Assert there is a save button.
$this->assertTrue(!empty($save_button));
$this->assertNoRaw('dropbutton-wrapper');
}
}
}

View file

@ -13,7 +13,7 @@ class MigrateNodeRevisionTest extends MigrateNodeTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'content_translation'];
public static $modules = ['language', 'content_translation', 'menu_ui'];
/**
* {@inheritdoc}

View file

@ -1,8 +1,9 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Url;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
/**
* Tests the node access automatic cacheability bubbling logic.
@ -13,6 +14,8 @@ use Drupal\Core\Url;
*/
class NodeAccessAutoBubblingTest extends NodeTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* Modules to enable.
*

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\node\Entity\NodeType;
@ -198,7 +198,7 @@ class NodeAccessBaseTableTest extends NodeTestBase {
$this->nidsVisible = [];
foreach ($this->xpath("//a[text()='Read more']") as $link) {
// See also testTranslationRendering() in NodeTranslationUITest.
$this->assertTrue(preg_match('|node/(\d+)$|', (string) $link['href'], $matches), 'Read more points to a node');
$this->assertTrue(preg_match('|node/(\d+)$|', $link->getAttribute('href'), $matches), 'Read more points to a node');
$this->nidsVisible[$matches[1]] = TRUE;
}
foreach ($this->nodesByUser as $uid => $data) {

View file

@ -1,18 +1,18 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\comment\CommentInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\Tests\BrowserTestBase;
/**
* Tests access controlled node views have the right amount of comment pages.
*
* @group node
*/
class NodeAccessPagerTest extends WebTestBase {
class NodeAccessPagerTest extends BrowserTestBase {
use CommentTestTrait;

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\node\Entity\NodeType;

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\user\RoleInterface;
@ -134,7 +134,7 @@ class NodeAdminTest extends NodeTestBase {
$this->assertLinkByHref('node/' . $node->id() . '/edit');
$this->assertLinkByHref('node/' . $node->id() . '/delete');
// Verify that we can see the content type label.
$this->assertEqual(trim((string) $node_type_labels[$delta]), $node->type->entity->label());
$this->assertEqual(trim($node_type_labels[$delta]->getText()), $node->type->entity->label());
$delta++;
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\block\Entity\Block;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\node\NodeInterface;
use Drupal\user\Entity\User;

View file

@ -1,8 +1,9 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\EntityViewTrait;
/**
* Tests changing view modes for nodes.
@ -11,6 +12,8 @@ use Drupal\Core\Cache\Cache;
*/
class NodeEntityViewModeAlterTest extends NodeTestBase {
use EntityViewTrait;
/**
* Enable dummy module that implements hook_ENTITY_TYPE_view() for nodes.
*/
@ -43,7 +46,7 @@ class NodeEntityViewModeAlterTest extends NodeTestBase {
$this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present');
// Test that the correct build mode has been set.
$build = $this->drupalBuildEntityView($node);
$build = $this->buildEntityView($node);
$this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.');
}

View file

@ -1,19 +1,19 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\BrowserTestBase;
/**
* Tests multilingual support for fields.
*
* @group node
*/
class NodeFieldMultilingualTest extends WebTestBase {
class NodeFieldMultilingualTest extends BrowserTestBase {
/**
* Modules to enable.
@ -123,7 +123,7 @@ class NodeFieldMultilingualTest extends WebTestBase {
':node-class' => ' node ',
':content-class' => 'node__content',
]);
$this->assertEqual(current($body), $node->body->value, 'Node body found.');
$this->assertEqual($body[0]->getText(), $node->body->value, 'Node body found.');
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
/**
* Tests all the different buttons on the node form.

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
/**
* Tests that node access queries are properly altered by the node module.

View file

@ -1,6 +1,8 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
/**
* Tests user permissions for node revisions.
@ -9,6 +11,8 @@ namespace Drupal\node\Tests;
*/
class NodeRevisionPermissionsTest extends NodeTestBase {
use GeneratePermutationsTrait;
/**
* The node revisions.
*

View file

@ -11,10 +11,24 @@ use Drupal\node\NodeInterface;
* @group node
*/
class NodeRevisionsAllTest extends NodeTestBase {
protected $nodes;
protected $revisionLogs;
protected $profile = "standard";
/**
* A list of nodes created to be used as starting point of different tests.
*
* @var Drupal\node\NodeInterface[]
*/
protected $nodes;
/**
* Revision logs of nodes created by the setup method.
*
* @var string[]
*/
protected $revisionLogs;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
@ -131,6 +145,11 @@ class NodeRevisionsAllTest extends NodeTestBase {
$node = node_revision_load($node->getRevisionId());
$this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the current one.');
// Confirm that the node can still be updated.
$this->drupalPostForm("node/" . $reverted_node->id() . "/edit", ['body[0][value]' => 'We are Drupal.'], t('Save'));
$this->assertText(t('Basic page @title has been updated.', ['@title' => $reverted_node->getTitle()]), 'Node was successfully saved after reverting a revision.');
$this->assertText('We are Drupal.', 'Node was correctly updated after reverting a revision.');
// Confirm revisions delete properly.
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete'));
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
/**
* Tests if the syndicate block is available.

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Component\Utility\Html;
@ -56,15 +56,15 @@ class NodeTitleTest extends NodeTestBase {
// Test <title> tag.
$this->drupalGet('node/' . $node->id());
$xpath = '//title';
$this->assertEqual(current($this->xpath($xpath)), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node');
$this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node');
// Test breadcrumb in comment preview.
$this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
$xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
$this->assertEqual(current($this->xpath($xpath)), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
$this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
// Test node title in comment preview.
$this->assertEqual(current($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])), $node->label(), 'Node preview title is equal to node title.', 'Node');
$this->assertEqual($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])[0]->getText(), $node->label(), 'Node preview title is equal to node title.', 'Node');
// Test node title is clickable on teaser list (/node).
$this->drupalGet('node');
@ -92,11 +92,11 @@ class NodeTitleTest extends NodeTestBase {
// the page.
$edge_case_title_escaped = Html::escape($edge_case_title);
$this->drupalGet('node/' . $node->id());
$this->assertTitle($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node');
$this->assertRaw('<title>' . $edge_case_title_escaped . ' | Drupal</title>', 'Page title is equal to article\'s "title".', 'Node');
// Test that the title appears as <title> when reloading the node page.
$this->drupalGet('node/' . $node->id());
$this->assertTitle($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node');
$this->assertRaw('<title>' . $edge_case_title_escaped . ' | Drupal</title>', 'Page title is equal to article\'s "title".', 'Node');
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Html;
@ -11,6 +11,7 @@ use Drupal\Component\Utility\Html;
* @group node
*/
class NodeTitleXSSTest extends NodeTestBase {
/**
* Tests XSS functionality with a node entity.
*/
@ -32,7 +33,7 @@ class NodeTitleXSSTest extends NodeTestBase {
$this->drupalGet('node/' . $node->id());
// Titles should be escaped.
$this->assertTitle(Html::escape($title) . ' | Drupal', 'Title is displayed when viewing a node.');
$this->assertRaw('<title>' . Html::escape($title) . ' | Drupal</title>', 'Title is displayed when viewing a node.');
$this->assertNoRaw($xss, 'Harmful tags are escaped when viewing a node.');
$this->drupalGet('node/' . $node->id() . '/edit');

View file

@ -1,9 +1,9 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
@ -82,7 +82,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
// Add a node.
$default_langcode = $this->langcodes[0];
$values[$default_langcode] = ['title' => [['value' => $this->randomMachineName()]]];
$entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
$this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
@ -327,7 +327,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
}
$pattern = '|^' . $expected_href . '$|';
foreach ($this->xpath("//a[text()='Read more']") as $link) {
if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) {
if (preg_match($pattern, $link->getAttribute('href'), $matches) == TRUE) {
$num_match_found++;
}
}
@ -349,7 +349,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
}
$pattern = '|^' . $expected_href . '$|';
foreach ($this->xpath("//a[text()='Add new comment']") as $link) {
if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) {
if (preg_match($pattern, $link->getAttribute('href'), $matches) == TRUE) {
$num_match_found++;
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Html;
@ -21,7 +21,7 @@ class NodeViewTest extends NodeTestBase {
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], $node->url());
$this->assertEqual($result[0]->getAttribute('href'), $node->url());
// Link relations are checked for access for anonymous users.
$result = $this->xpath('//link[@rel = "version-history"]');
@ -34,14 +34,14 @@ class NodeViewTest extends NodeTestBase {
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], $node->url());
$this->assertEqual($result[0]->getAttribute('href'), $node->url());
// Link relations are present regardless of access for authenticated users.
$result = $this->xpath('//link[@rel = "version-history"]');
$this->assertEqual($result[0]['href'], $node->url('version-history'));
$this->assertEqual($result[0]->getAttribute('href'), $node->url('version-history'));
$result = $this->xpath('//link[@rel = "edit-form"]');
$this->assertEqual($result[0]['href'], $node->url('edit-form'));
$this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form'));
// Give anonymous users access to edit the node. Do this through the UI to
// ensure caches are handled properly.
@ -56,13 +56,13 @@ class NodeViewTest extends NodeTestBase {
// version-history link.
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], $node->url());
$this->assertEqual($result[0]->getAttribute('href'), $node->url());
$result = $this->xpath('//link[@rel = "version-history"]');
$this->assertFalse($result, 'Version history not present for anonymous users without access.');
$result = $this->xpath('//link[@rel = "edit-form"]');
$this->assertEqual($result[0]['href'], $node->url('edit-form'));
$this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form'));
}
/**
@ -79,7 +79,7 @@ class NodeViewTest extends NodeTestBase {
$this->drupalGet($node->urlInfo());
$links = explode(',', $this->drupalGetHeader('Link'));
$links = $this->drupalGetHeaders()['Link'];
$this->assertEqual($links, $expected);
}
@ -92,7 +92,7 @@ class NodeViewTest extends NodeTestBase {
$node = $this->drupalCreateNode(['title' => $title]);
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//span[contains(@class, "field--name-title")]');
$this->assertEqual((string) $result[0], $title, 'The passed title was returned.');
$this->assertEqual($result[0]->getText(), $title, 'The passed title was returned.');
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\node\Entity\Node;
@ -41,8 +41,8 @@ class BulkFormAccessTest extends NodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create Article node type.
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\language\Entity\ConfigurableLanguage;

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\node\Entity\NodeType;
@ -31,8 +31,11 @@ class FilterNodeAccessTest extends NodeTestBase {
*/
public static $testViews = ['test_filter_node_access'];
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Views;

View file

@ -1,13 +1,13 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\AssertViewsCacheTagsTrait;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
@ -39,8 +39,11 @@ class FrontPageTest extends ViewTestBase {
*/
public static $modules = ['node', 'contextual'];
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->nodeStorage = $this->container->get('entity.manager')
->getStorage('node');

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\language\Entity\ConfigurableLanguage;
@ -30,8 +30,11 @@ class NodeFieldFilterTest extends NodeTestBase {
*/
public $nodeTitles = [];
public function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create Page content type.
if ($this->profile != 'standard') {

View file

@ -1,6 +1,7 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
/**
* Tests the node integration into views.
@ -59,7 +59,7 @@ class NodeIntegrationTest extends NodeTestBase {
$result = $this->xpath('//span[@class="field-content"]');
$nids = [];
foreach ($result as $element) {
$nids[] = (int) $element;
$nids[] = (int) $element->getText();
}
$this->assertEqual($nids, $expected_nids);
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldStorageConfig;
@ -38,7 +38,7 @@ class NodeLanguageTest extends NodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp($import_test_views = TRUE) {
parent::setUp(FALSE);
// Create Page content type.

View file

@ -1,8 +1,8 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Tests\Wizard\WizardTestBase;
use Drupal\Tests\views\Functional\Wizard\WizardTestBase;
use Drupal\views\Views;
/**

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Base class for all node Views tests.
*/
abstract class NodeTestBase extends ViewTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node_test_views'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['node_test_views']);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Views;
@ -32,8 +32,11 @@ class PathPluginTest extends NodeTestBase {
*/
protected $nodes;
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalCreateContentType(['type' => 'article']);

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
/**
* Tests the different revision link handlers.

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Views;
@ -33,8 +33,11 @@ class RowPluginTest extends NodeTestBase {
*/
protected $nodes;
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalCreateContentType(['type' => 'article']);

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\node\NodeInterface;

View file

@ -13,6 +13,11 @@ use Drupal\node\Entity\Node;
*/
class MigrateNodeBundleSettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_ui'];
/**
* {@inheritdoc}
*/

View file

@ -10,7 +10,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
*/
class MigrateNodeSettingPromoteTest extends MigrateDrupal6TestBase {
public static $modules = ['node', 'text'];
public static $modules = ['node', 'text', 'menu_ui'];
/**
* {@inheritdoc}

View file

@ -10,7 +10,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
*/
class MigrateNodeSettingStatusTest extends MigrateDrupal6TestBase {
public static $modules = ['node', 'text'];
public static $modules = ['node', 'text', 'menu_ui'];
/**
* {@inheritdoc}

View file

@ -10,7 +10,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
*/
class MigrateNodeSettingStickyTest extends MigrateDrupal6TestBase {
public static $modules = ['node', 'text'];
public static $modules = ['node', 'text', 'menu_ui'];
/**
* {@inheritdoc}

View file

@ -19,7 +19,7 @@ class MigrateNodeTest extends MigrateNodeTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'content_translation'];
public static $modules = ['language', 'content_translation', 'menu_ui'];
/**
* {@inheritdoc}
@ -72,6 +72,11 @@ class MigrateNodeTest extends MigrateNodeTestBase {
$this->assertIdentical('1', $node->field_test_identical2->value, 'Integer value is correct');
$this->assertIdentical('This is a field with exclude unset.', $node->field_test_exclude_unset->value, 'Field with exclude unset is correct.');
// Test that date fields are migrated.
$this->assertSame('2013-01-02T04:05:00', $node->field_test_date->value, 'Date field is correct');
$this->assertSame('1391357160', $node->field_test_datestamp->value, 'Datestamp field is correct');
$this->assertSame('2015-03-04T06:07:00', $node->field_test_datetime->value, 'Datetime field is correct');
// Test that link fields are migrated.
$this->assertIdentical('https://www.drupal.org/project/drupal', $node->field_test_link->uri);
$this->assertIdentical('Drupal project page', $node->field_test_link->title);
@ -81,6 +86,15 @@ class MigrateNodeTest extends MigrateNodeTestBase {
$this->assertIdentical('desc', $node->field_test_filefield->description);
$this->assertIdentical('4', $node->field_test_filefield->target_id);
// Test that an email field is migrated.
$this->assertSame('PrincessRuwenne@example.com', $node->field_test_email->value);
// Test that node reference field values were migrated.
$node = Node::load(18);
$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());
$node = Node::load(2);
$this->assertIdentical('Test title rev 3', $node->getTitle());
$this->assertIdentical('test rev 3', $node->body->value);

View file

@ -13,6 +13,11 @@ use Drupal\node\Entity\NodeType;
*/
class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_ui'];
/**
* {@inheritdoc}
*/
@ -39,6 +44,12 @@ class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
$field = FieldConfig::loadByName('node', 'test_page', 'body');
$this->assertIdentical('This is the body field label', $field->getLabel(), 'Body field was found.');
// Test default menus.
$expected_available_menus = ['navigation'];
$this->assertSame($expected_available_menus, $node_type_page->getThirdPartySetting('menu_ui', 'available_menus'));
$expected_parent = 'navigation:';
$this->assertSame($expected_parent, $node_type_page->getThirdPartySetting('menu_ui', 'parent'));
// Test the test_story content type.
$node_type_story = NodeType::load('test_story');
$this->assertIdentical('test_story', $node_type_story->id(), 'Node type test_story loaded');
@ -52,6 +63,12 @@ class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
$field = FieldConfig::loadByName('node', 'test_story', 'body');
$this->assertIdentical(NULL, $field, 'No body field found');
// Test default menus.
$expected_available_menus = ['navigation'];
$this->assertSame($expected_available_menus, $node_type_story->getThirdPartySetting('menu_ui', 'available_menus'));
$expected_parent = 'navigation:';
$this->assertSame($expected_parent, $node_type_story->getThirdPartySetting('menu_ui', 'parent'));
// Test the test_event content type.
$node_type_event = NodeType::load('test_event');
$this->assertIdentical('test_event', $node_type_event->id(), 'Node type test_event loaded');
@ -64,6 +81,11 @@ class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_event', 'body');
$this->assertIdentical('Body', $field->getLabel(), 'Body field was found.');
$expected_available_menus = ['navigation'];
$this->assertSame($expected_available_menus, $node_type_event->getThirdPartySetting('menu_ui', 'available_menus'));
$expected_parent = 'navigation:';
$this->assertSame($expected_parent, $node_type_event->getThirdPartySetting('menu_ui', 'parent'));
}
}

View file

@ -24,6 +24,7 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
'image',
'language',
'link',
'menu_ui',
'node',
'taxonomy',
'telephone',
@ -149,6 +150,9 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
$this->assertIdentical('93', $node->field_images->height);
$this->assertIdentical('http://google.com', $node->field_link->uri);
$this->assertIdentical('Click Here', $node->field_link->title);
// Test that an email field is migrated.
$this->assertSame('default@example.com', $node->field_email->value);
$this->assertSame('another@example.com', $node->field_email[1]->value);
$node = Node::load(2);
$this->assertSame('en', $node->langcode->value);

View file

@ -12,7 +12,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
*/
class MigrateNodeTitleLabelTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'text'];
public static $modules = ['node', 'text', 'menu_ui'];
/**
* {@inheritdoc}

View file

@ -20,7 +20,7 @@ class MigrateNodeTypeTest extends MigrateDrupal7TestBase {
*
* @var array
*/
public static $modules = ['node', 'text', 'filter'];
public static $modules = ['node', 'text', 'filter', 'menu_ui'];
/**
* {@inheritdoc}
@ -45,12 +45,13 @@ class MigrateNodeTypeTest extends MigrateDrupal7TestBase {
* @param string $help
* The expected help text.
*/
protected function assertEntity($id, $label, $description, $help, $display_submitted, $new_revision, $body_label = NULL) {
protected function assertEntity($id, $label, $description, $help, $display_submitted, $new_revision, $expected_available_menus, $expected_parent, $body_label = NULL) {
/** @var \Drupal\node\NodeTypeInterface $entity */
$entity = NodeType::load($id);
$this->assertTrue($entity instanceof NodeTypeInterface);
$this->assertIdentical($label, $entity->label());
$this->assertIdentical($description, $entity->getDescription());
$this->assertIdentical($help, $entity->getHelp());
$this->assertIdentical($display_submitted, $entity->displaySubmitted(), 'Submission info is displayed');
@ -62,20 +63,32 @@ class MigrateNodeTypeTest extends MigrateDrupal7TestBase {
$this->assertTrue($body instanceof FieldConfigInterface);
$this->assertIdentical($body_label, $body->label());
}
$this->assertSame($expected_available_menus, $entity->getThirdPartySetting('menu_ui', 'available_menus'));
$this->assertSame($expected_parent, $entity->getThirdPartySetting('menu_ui', 'parent'));
}
/**
* Tests Drupal 7 node type to Drupal 8 migration.
*/
public function testNodeType() {
$this->assertEntity('article', 'Article', 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.', 'Help text for articles', TRUE, FALSE, "Body");
$this->assertEntity('blog', 'Blog entry', 'Use for multi-user blogs. Every user gets a personal blog.', 'Blog away, good sir!', TRUE, FALSE, 'Body');
$expected_available_menus = ['main-menu'];
$expected_parent = 'main-menu:0:';
$this->assertEntity('article', 'Article', 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.', 'Help text for articles', TRUE, FALSE, $expected_available_menus, $expected_parent, "Body");
$this->assertEntity('blog', 'Blog entry', 'Use for multi-user blogs. Every user gets a personal blog.', 'Blog away, good sir!', TRUE, FALSE, $expected_available_menus, $expected_parent, 'Body');
// book's display_submitted flag is not set, so it will default to TRUE.
$this->assertEntity('book', 'Book page', '<em>Books</em> have a built-in hierarchical navigation. Use for handbooks or tutorials.', '', TRUE, TRUE, "Body");
$this->assertEntity('forum', 'Forum topic', 'A <em>forum topic</em> starts a new discussion thread within a forum.', 'No name-calling, no flame wars. Be nice.', TRUE, FALSE, 'Body');
$this->assertEntity('page', 'Basic page', "Use <em>basic pages</em> for your static content, such as an 'About us' page.", 'Help text for basic pages', FALSE, FALSE, "Body");
$this->assertEntity('book', 'Book page', '<em>Books</em> have a built-in hierarchical navigation. Use for handbooks or tutorials.', '', TRUE, TRUE, $expected_available_menus, $expected_parent, "Body");
$this->assertEntity('forum', 'Forum topic', 'A <em>forum topic</em> starts a new discussion thread within a forum.', 'No name-calling, no flame wars. Be nice.', TRUE, FALSE, $expected_available_menus, $expected_parent, 'Body');
$this->assertEntity('page', 'Basic page', "Use <em>basic pages</em> for your static content, such as an 'About us' page.", 'Help text for basic pages', FALSE, FALSE, $expected_available_menus, $expected_parent, "Body");
// This node type does not carry a body field.
$this->assertEntity('test_content_type', 'Test content type', 'This is the description of the test content type.', 'Help text for test content type', FALSE, TRUE);
$expected_available_menus = [
'main-menu',
'management',
'navigation',
'user-menu',
];
$this->assertEntity('test_content_type', 'Test content type', 'This is the description of the test content type.', 'Help text for test content type', FALSE, TRUE, $expected_available_menus, $expected_parent);
}
}

View file

@ -1,15 +1,82 @@
<?php
namespace Drupal\node\Tests;
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;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
use Drupal\simpletest\UserCreationTrait;
use Drupal\Tests\EntityViewTrait;
/**
* Tests summary length.
*
* @group node
*/
class SummaryLengthTest extends NodeTestBase {
class SummaryLengthTest extends KernelTestBase {
use NodeCreationTrait {
getNodeByTitle as drupalGetNodeByTitle;
createNode as drupalCreateNode;
}
use UserCreationTrait {
createUser as drupalCreateUser;
createRole as drupalCreateRole;
createAdminRole as drupalCreateAdminRole;
}
use ContentTypeCreationTrait {
createContentType as drupalCreateContentType;
}
use EntityViewTrait {
buildEntityView as drupalBuildEntityView;
}
/**
* {@inheritdoc}
*/
public static $modules = [
'node',
'datetime',
'user',
'system',
'filter',
'field',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'sequences');
$this->installSchema('node', 'node_access');
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installEntitySchema('date_format');
$this->installConfig('filter');
$this->installConfig('node');
// Create a node type.
$this->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
DateFormat::create([
'id' => 'fallback',
'label' => 'Fallback',
'pattern' => 'Y-m-d',
])->save();
// Enable multibyte support.
Unicode::setStatus(Unicode::STATUS_MULTIBYTE);
}
/**
* Tests the node summary length functionality.
*/

View file

@ -0,0 +1,93 @@
<?php
namespace Drupal\Tests\node\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\simpletest\UserCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests the argument_node_uid_revision handler.
*
* @group node
*/
class ArgumentUidRevisionTest extends ViewsKernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'field', 'text', 'user', 'node_test_views'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_argument_node_uid_revision'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('node');
$this->installSchema('node', ['node_access']);
$this->installEntitySchema('user');
$this->installConfig(['node', 'field']);
ViewTestData::createTestViews(get_class($this), ['node_test_views']);
}
/**
* Tests the node_uid_revision argument.
*/
public function testArgument() {
$expected_result = [];
$author = $this->createUser();
$no_author = $this->createUser();
// Create one node, with the author as the node author.
$node1 = Node::create([
'type' => 'default',
'title' => $this->randomMachineName(),
]);
$node1->setOwner($author);
$node1->save();
$expected_result[] = ['nid' => $node1->id()];
// Create one node of which an additional revision author will be the
// author.
$node2 = Node::create([
'type' => 'default',
'title' => $this->randomMachineName(),
]);
$node2->setRevisionAuthorId($no_author->id());
$node2->save();
$expected_result[] = ['nid' => $node2->id()];
// Force to add a new revision.
$node2->setNewRevision(TRUE);
$node2->setRevisionAuthorId($author->id());
$node2->save();
// Create one node on which the author has neither authorship of revisions
// or the main node.
$node3 = Node::create([
'type' => 'default',
'title' => $this->randomMachineName(),
]);
$node3->setOwner($no_author);
$node3->save();
$view = Views::getView('test_argument_node_uid_revision');
$view->initHandlers();
$view->setArguments(['uid_revision' => $author->id()]);
$this->executeView($view);
$this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid']);
}
}

View file

@ -1,9 +1,11 @@
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
@ -11,7 +13,7 @@ use Drupal\views\Tests\ViewTestData;
*
* @group node
*/
class RevisionRelationshipsTest extends ViewTestBase {
class RevisionRelationshipsTest extends ViewsKernelTestBase {
/**
* Modules to enable.
@ -20,8 +22,16 @@ class RevisionRelationshipsTest extends ViewTestBase {
*/
public static $modules = ['node' , 'node_test_views'];
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installSchema('node', 'node_access');
$this->installEntitySchema('user');
$this->installEntitySchema('node');
ViewTestData::createTestViews(get_class($this), ['node_test_views']);
}
@ -37,11 +47,13 @@ class RevisionRelationshipsTest extends ViewTestBase {
* Create a node with revision and rest result count for both views.
*/
public function testNodeRevisionRelationship() {
$node = $this->drupalCreateNode();
$type = NodeType::create(['type' => 'page', 'name' => 'page']);
$type->save();
$node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]);
$node->save();
// Create revision of the node.
$node_revision = clone $node;
$node_revision->setNewRevision();
$node_revision->save();
$node->setNewRevision(TRUE);
$node->save();
$column_map = [
'vid' => 'vid',
'node_field_data_node_field_revision_nid' => 'node_node_revision_nid',