Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateNodeBuilderTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateNodeBuilderTest extends MigrateDrupal6TestBase {
|
||||
|
||||
public static $modules = ['migrate', 'migrate_drupal', 'node'];
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a migration entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The migration ID.
|
||||
* @param string $label
|
||||
* The label.
|
||||
*/
|
||||
protected function assertEntity($id, $label) {
|
||||
$migration = Migration::load($id);
|
||||
$this->assertTrue($migration instanceof Migration);
|
||||
$this->assertIdentical($id, $migration->Id());
|
||||
$this->assertIdentical($label, $migration->label());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating migrations from a template, using a builder plugin.
|
||||
*/
|
||||
public function testCreateMigrations() {
|
||||
$templates = [
|
||||
'd6_node' => [
|
||||
'id' => 'd6_node',
|
||||
'label' => 'Drupal 6 nodes',
|
||||
'builder' => [
|
||||
'plugin' => 'd6_node',
|
||||
],
|
||||
'source' => [
|
||||
'plugin' => 'd6_node',
|
||||
],
|
||||
'process' => [
|
||||
'nid' => 'nid',
|
||||
'vid' => 'vid',
|
||||
'uid' => 'uid',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:node',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$migrations = \Drupal::service('migrate.migration_builder')->createMigrations($templates);
|
||||
$this->assertIdentical(11, count($migrations));
|
||||
$this->assertEntity('d6_node__article', 'Drupal 6 nodes (article)');
|
||||
$this->assertEntity('d6_node__company', 'Drupal 6 nodes (company)');
|
||||
$this->assertEntity('d6_node__employee', 'Drupal 6 nodes (employee)');
|
||||
$this->assertEntity('d6_node__event', 'Drupal 6 nodes (event)');
|
||||
$this->assertEntity('d6_node__page', 'Drupal 6 nodes (page)');
|
||||
$this->assertEntity('d6_node__sponsor', 'Drupal 6 nodes (sponsor)');
|
||||
$this->assertEntity('d6_node__story', 'Drupal 6 nodes (story)');
|
||||
$this->assertEntity('d6_node__test_event', 'Drupal 6 nodes (test_event)');
|
||||
$this->assertEntity('d6_node__test_page', 'Drupal 6 nodes (test_page)');
|
||||
$this->assertEntity('d6_node__test_planet', 'Drupal 6 nodes (test_planet)');
|
||||
$this->assertEntity('d6_node__test_story', 'Drupal 6 nodes (test_story)');
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
/**
|
||||
* Test migrating node settings into the base_field_bundle_override config entity.
|
||||
*
|
||||
* @group node
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateNodeBundleSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
|
@ -57,7 +57,6 @@ class MigrateNodeBundleSettingsTest extends MigrateDrupal6TestBase {
|
|||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
$this->loadDumps(['NodeType.php', 'Variable.php']);
|
||||
$this->executeMigration('d6_node_setting_promote');
|
||||
$this->executeMigration('d6_node_setting_status');
|
||||
$this->executeMigration('d6_node_setting_sticky');
|
||||
|
|
|
@ -13,7 +13,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
/**
|
||||
* Upgrade variables to node.settings.yml.
|
||||
*
|
||||
* @group node
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateNodeConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
|
@ -31,7 +31,6 @@ class MigrateNodeConfigsTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadDumps(['Variable.php']);
|
||||
$this->executeMigration('d6_node_settings');
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
|
||||
/**
|
||||
* Node content revisions migration.
|
||||
*
|
||||
* @group node
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateNodeRevisionTest extends MigrateNodeTestBase {
|
||||
|
||||
|
@ -23,14 +24,12 @@ class MigrateNodeRevisionTest extends MigrateNodeTestBase {
|
|||
parent::setUp();
|
||||
|
||||
$id_mappings = array(
|
||||
'd6_node' => array(
|
||||
'd6_node:*' => array(
|
||||
array(array(1), array(1)),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
$this->loadDumps(['Users.php']);
|
||||
|
||||
// Create our users for the node authors.
|
||||
$query = Database::getConnection('default', 'migrate')->query('SELECT * FROM {users} WHERE uid NOT IN (0, 1)');
|
||||
while(($row = $query->fetchAssoc()) !== FALSE) {
|
||||
|
@ -39,7 +38,8 @@ class MigrateNodeRevisionTest extends MigrateNodeTestBase {
|
|||
$user->save();
|
||||
}
|
||||
|
||||
$this->executeMigration('d6_node_revision');
|
||||
$migrations = Migration::loadMultiple(['d6_node_revision:*']);
|
||||
array_walk($migrations, [$this, 'executeMigration']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Node content migration.
|
||||
*
|
||||
* @group node
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateNodeTest extends MigrateNodeTestBase {
|
||||
|
||||
|
@ -23,13 +23,13 @@ class MigrateNodeTest extends MigrateNodeTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
/** @var \Drupal\migrate\entity\Migration $migration */
|
||||
$migration = entity_load('migration', 'd6_node');
|
||||
$executable = new MigrateExecutable($migration, $this);
|
||||
$executable->import();
|
||||
// Each node type is imported separately. In this test, we're asserting
|
||||
// on story and test_planet nodes.
|
||||
$this->executeMigration('d6_node__test_planet');
|
||||
$this->executeMigration('d6_node__story');
|
||||
|
||||
// This is required for the second import below.
|
||||
db_truncate($migration->getIdMap()->mapTableName())->execute();
|
||||
\Drupal::database()->truncate(Migration::load('d6_node__story')->getIdMap()->mapTableName())->execute();
|
||||
$this->standalone = TRUE;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ class MigrateNodeTest extends MigrateNodeTestBase {
|
|||
$this->assertIdentical('Test title', $node_revision->getTitle());
|
||||
$this->assertIdentical('1', $node_revision->getRevisionAuthor()->id(), 'Node revision has the correct user');
|
||||
// This is empty on the first revision.
|
||||
$this->assertIdentical('', $node_revision->revision_log->value);
|
||||
$this->assertIdentical(NULL, $node_revision->revision_log->value);
|
||||
|
||||
// It is pointless to run the second half from MigrateDrupal6Test.
|
||||
if (empty($this->standalone)) {
|
||||
|
@ -75,10 +75,8 @@ class MigrateNodeTest extends MigrateNodeTestBase {
|
|||
->condition('delta', 1)
|
||||
->execute();
|
||||
|
||||
/** @var \Drupal\migrate\entity\Migration $migration */
|
||||
$migration = entity_load('migration', 'd6_node');
|
||||
$executable = new MigrateExecutable($migration, $this);
|
||||
$executable->import();
|
||||
$migration = Migration::load('d6_node__story');
|
||||
$this->executeMigration($migration);
|
||||
|
||||
$node = Node::load(1);
|
||||
$this->assertIdentical('New node title', $node->getTitle());
|
||||
|
|
|
@ -82,6 +82,7 @@ abstract class MigrateNodeTestBase extends MigrateDrupal6TestBase {
|
|||
'nid' => 1,
|
||||
'vid' => 1,
|
||||
'revision_log' => '',
|
||||
'title' => $this->randomString(),
|
||||
));
|
||||
$node->enforceIsNew();
|
||||
$node->save();
|
||||
|
@ -91,23 +92,10 @@ abstract class MigrateNodeTestBase extends MigrateDrupal6TestBase {
|
|||
'nid' => 3,
|
||||
'vid' => 4,
|
||||
'revision_log' => '',
|
||||
'title' => $this->randomString(),
|
||||
));
|
||||
$node->enforceIsNew();
|
||||
$node->save();
|
||||
|
||||
$this->loadDumps([
|
||||
'Node.php',
|
||||
'NodeRevisions.php',
|
||||
'ContentTypeStory.php',
|
||||
'ContentTypeTestPlanet.php',
|
||||
'NodeType.php',
|
||||
'Variable.php',
|
||||
'ContentNodeFieldInstance.php',
|
||||
'ContentNodeField.php',
|
||||
'ContentFieldTest.php',
|
||||
'ContentFieldTestTwo.php',
|
||||
'ContentFieldMultivalue.php',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use Drupal\node\Entity\NodeType;
|
|||
/**
|
||||
* Upgrade node types to node.type.*.yml.
|
||||
*
|
||||
* @group node
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
|
||||
|
||||
|
@ -30,9 +30,7 @@ class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('node'));
|
||||
$this->loadDumps(['NodeType.php', 'Variable.php']);
|
||||
$this->executeMigration('d6_node_type');
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
/**
|
||||
* Migrate view modes.
|
||||
*
|
||||
* @group node
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateViewModesTest extends MigrateDrupal6TestBase {
|
||||
|
||||
|
@ -29,13 +29,6 @@ class MigrateViewModesTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadDumps([
|
||||
'ContentNodeFieldInstance.php',
|
||||
'ContentNodeField.php',
|
||||
'ContentFieldTest.php',
|
||||
'ContentFieldTestTwo.php',
|
||||
'ContentFieldMultivalue.php',
|
||||
]);
|
||||
$this->executeMigration('d6_view_modes');
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d7\MigrateNodeSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade variables to node.settings config object.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d7_node_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of node variables to node.settings config object.
|
||||
*/
|
||||
public function testAggregatorSettings() {
|
||||
$config = $this->config('node.settings');
|
||||
$this->assertEqual(1, $config->get('use_admin_theme'));
|
||||
}
|
||||
|
||||
}
|
112
core/modules/node/src/Tests/Migrate/d7/MigrateNodeTest.php
Normal file
112
core/modules/node/src/Tests/Migrate/d7/MigrateNodeTest.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d7\MigrateNodeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Tests node migration.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeTest extends MigrateDrupal7TestBase {
|
||||
|
||||
static $modules = array('node', 'text', 'filter', 'entity_reference');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installConfig(['node']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
|
||||
$this->executeMigration('d7_user_role');
|
||||
$this->executeMigration('d7_user');
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_node__test_content_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a node.
|
||||
*
|
||||
* @param string $id
|
||||
* The node ID.
|
||||
* @param string $type
|
||||
* The node type.
|
||||
* @param string $langcode
|
||||
* The expected language code.
|
||||
* @param string $title
|
||||
* The expected title.
|
||||
* @param int $uid
|
||||
* The expected author ID.
|
||||
* @param bool $status
|
||||
* The expected status of the node.
|
||||
* @param int $created
|
||||
* The expected creation time.
|
||||
* @param int $changed
|
||||
* The expected modification time.
|
||||
* @param bool $promoted
|
||||
* Whether the node is expected to be promoted to the front page.
|
||||
* @param bool $sticky
|
||||
* Whether the node is expected to be sticky.
|
||||
*/
|
||||
protected function assertEntity($id, $type, $langcode, $title, $uid, $status, $created, $changed, $promoted, $sticky) {
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$node = Node::load($id);
|
||||
$this->assertTrue($node instanceof NodeInterface);
|
||||
$this->assertIdentical($type, $node->getType());
|
||||
$this->assertIdentical($langcode, $node->langcode->value);
|
||||
$this->assertIdentical($title, $node->getTitle());
|
||||
$this->assertIdentical($uid, $node->getOwnerId());
|
||||
$this->assertIdentical($status, $node->isPublished());
|
||||
$this->assertIdentical($created, $node->getCreatedTime());
|
||||
if (isset($changed)) {
|
||||
$this->assertIdentical($changed, $node->getChangedTime());
|
||||
}
|
||||
$this->assertIdentical($promoted, $node->isPromoted());
|
||||
$this->assertIdentical($sticky, $node->isSticky());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a node revision.
|
||||
*
|
||||
* @param int $id
|
||||
* The revision ID.
|
||||
* @param string $title
|
||||
* The expected title.
|
||||
* @param int $uid
|
||||
* The revision author ID.
|
||||
* @param string $log
|
||||
* The revision log message.
|
||||
* @param int $timestamp
|
||||
* The revision's time stamp.
|
||||
*/
|
||||
protected function assertRevision($id, $title, $uid, $log, $timestamp) {
|
||||
$revision = \Drupal::entityManager()->getStorage('node')->loadRevision($id);
|
||||
$this->assertTrue($revision instanceof NodeInterface);
|
||||
$this->assertIdentical($title, $revision->getTitle());
|
||||
$this->assertIdentical($uid, $revision->getRevisionAuthor()->id());
|
||||
$this->assertIdentical($log, $revision->revision_log->value);
|
||||
$this->assertIdentical($timestamp, $revision->getRevisionCreationTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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', '2', NULL, '1441032132');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d7\MigrateNodeTitleLabelTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Field\Entity\BaseFieldOverride;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of the title field label for node types.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeTitleLabelTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installEntitySchema('node');
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_node_title_label');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a base_field_override entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The override ID.
|
||||
* @param string $label
|
||||
* The label's expected (overridden) value.
|
||||
*/
|
||||
protected function assertEntity($id, $label) {
|
||||
$override = BaseFieldOverride::load($id);
|
||||
$this->assertTrue($override instanceof BaseFieldOverride);
|
||||
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $override */
|
||||
$this->assertIdentical($label, $override->getLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of node title field overrides.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertEntity('node.article.title', 'Title');
|
||||
$this->assertEntity('node.blog.title', 'Title');
|
||||
$this->assertEntity('node.book.title', 'Title');
|
||||
$this->assertEntity('node.forum.title', 'Subject');
|
||||
$this->assertEntity('node.page.title', 'Title');
|
||||
$this->assertEntity('node.test_content_type.title', 'Title');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d7\MigrateNodeTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\node\NodeTypeInterface;
|
||||
|
||||
/**
|
||||
* Upgrade node types to node.type.*.yml.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeTypeTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'text', 'filter');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(array('node'));
|
||||
$this->executeMigration('d7_node_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a single node type.
|
||||
*
|
||||
* @dataProvider testNodeTypeDataProvider
|
||||
* @param string $id
|
||||
* The node type ID.
|
||||
* @param string $label
|
||||
* The expected label.
|
||||
* @param string $description
|
||||
* The expected node type description.
|
||||
* @param string $help
|
||||
* The expected help text.
|
||||
*/
|
||||
protected function assertEntity($id, $label, $description, $help, $display_submitted, $new_revision, $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');
|
||||
$this->assertIdentical($new_revision, $entity->isNewRevision(), 'Is a new revision');
|
||||
|
||||
if ($body_label) {
|
||||
/** @var \Drupal\field\FieldConfigInterface $body */
|
||||
$body = FieldConfig::load('node.' . $id . '.body');
|
||||
$this->assertTrue($body instanceof FieldConfigInterface);
|
||||
$this->assertIdentical($body_label, $body->label());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
// 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 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);
|
||||
}
|
||||
|
||||
}
|
41
core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php
Normal file
41
core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d7\NodeBuilderTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the d7_node builder.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeBuilderTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node'];
|
||||
|
||||
public function testBuilder() {
|
||||
$process = Migration::load('d7_node__test_content_type')->getProcess();
|
||||
$this->assertIdentical('field_boolean', $process['field_boolean'][0]['source']);
|
||||
$this->assertIdentical('field_email', $process['field_email'][0]['source']);
|
||||
$this->assertIdentical('field_phone', $process['field_phone'][0]['source']);
|
||||
$this->assertIdentical('field_date', $process['field_date'][0]['source']);
|
||||
$this->assertIdentical('field_date_with_end_time', $process['field_date_with_end_time'][0]['source']);
|
||||
$this->assertIdentical('field_file', $process['field_file'][0]['source']);
|
||||
$this->assertIdentical('field_float', $process['field_float'][0]['source']);
|
||||
$this->assertIdentical('field_images', $process['field_images'][0]['source']);
|
||||
$this->assertIdentical('field_integer', $process['field_integer'][0]['source']);
|
||||
$this->assertIdentical('field_link', $process['field_link'][0]['source']);
|
||||
$this->assertIdentical('field_text_list', $process['field_text_list'][0]['source']);
|
||||
$this->assertIdentical('field_integer_list', $process['field_integer_list'][0]['source']);
|
||||
$this->assertIdentical('field_long_text', $process['field_long_text'][0]['source']);
|
||||
$this->assertIdentical('field_term_reference', $process['field_term_reference'][0]['source']);
|
||||
$this->assertIdentical('field_text', $process['field_text'][0]['source']);
|
||||
}
|
||||
|
||||
}
|
|
@ -111,6 +111,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
|
|||
'private' => FALSE,
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 0;
|
||||
$node->save();
|
||||
|
||||
|
@ -121,6 +122,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
|
|||
'private' => TRUE,
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 0;
|
||||
$node->save();
|
||||
|
||||
|
@ -131,6 +133,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
|
|||
'private' => FALSE,
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 0;
|
||||
$node->save();
|
||||
|
||||
|
@ -141,6 +144,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
|
|||
'private' => FALSE,
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 1;
|
||||
$node->save();
|
||||
|
||||
|
@ -151,6 +155,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
|
|||
'private' => FALSE,
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 1;
|
||||
$node->save();
|
||||
|
||||
|
@ -161,6 +166,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
|
|||
'private' => TRUE,
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 1;
|
||||
$node->save();
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
|
|||
'field_private' => array(array('value' => 0)),
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 0;
|
||||
$node->save();
|
||||
|
||||
|
@ -113,6 +114,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
|
|||
'field_private' => array(array('value' => 0)),
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 1;
|
||||
$node->save();
|
||||
|
||||
|
@ -122,6 +124,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
|
|||
'field_private' => array(array('value' => 1)),
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 0;
|
||||
$node->save();
|
||||
|
||||
|
@ -131,6 +134,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
|
|||
'field_private' => array(array('value' => 1)),
|
||||
));
|
||||
$translation = $node->getTranslation('ca');
|
||||
$translation->title->value = $this->randomString();
|
||||
$translation->field_private->value = 1;
|
||||
$node->save();
|
||||
|
||||
|
|
77
core/modules/node/src/Tests/NodeAccessMenuLinkTest.php
Normal file
77
core/modules/node/src/Tests/NodeAccessMenuLinkTest.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\NodeAccessMenuLinkTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the interaction of the node access system with menu links.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeAccessMenuLinkTest extends NodeTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('menu_ui', 'block');
|
||||
|
||||
/**
|
||||
* A user with permission to manage menu links and create nodes.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $contentAdminUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('system_menu_block:main');
|
||||
|
||||
$this->contentAdminUser = $this->drupalCreateUser(array(
|
||||
'access content',
|
||||
'administer content types',
|
||||
'administer menu'
|
||||
));
|
||||
|
||||
$this->config('user.role.' . RoleInterface::ANONYMOUS_ID)->set('permissions', array())->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* SA-CORE-2015-003: Tests menu links to nodes when node access is restricted.
|
||||
*/
|
||||
function testNodeAccessMenuLink() {
|
||||
|
||||
$menu_link_title = $this->randomString();
|
||||
|
||||
$this->drupalLogin($this->contentAdminUser);
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomString(),
|
||||
'body[0][value]' => $this->randomString(),
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $menu_link_title,
|
||||
];
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
||||
$this->assertLink($menu_link_title);
|
||||
|
||||
// Ensure anonymous users without "access content" permission do not see
|
||||
// this menu link.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('');
|
||||
$this->assertNoLink($menu_link_title);
|
||||
|
||||
// Ensure anonymous users with "access content" permission see this menu
|
||||
// link.
|
||||
$this->config('user.role.' . RoleInterface::ANONYMOUS_ID)->set('permissions', array('access content'))->save();
|
||||
$this->drupalGet('');
|
||||
$this->assertLink($menu_link_title);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
|
@ -100,17 +101,11 @@ class NodeBlockFunctionalTest extends NodeTestBase {
|
|||
$this->assertText($node3->label(), 'Node found in block.');
|
||||
|
||||
// Check to make sure nodes are in the right order.
|
||||
$this->assertTrue($this->xpath('//div[@id="block-test-block"]//table/tbody/tr[position() = 1]/td/a[text() = "' . $node3->label() . '"]'), 'Nodes were ordered correctly in block.');
|
||||
$this->assertTrue($this->xpath('//div[@id="block-test-block"]//div[@class="item-list"]/ul/li[1]/div/span/a[text() = "' . $node3->label() . '"]'), 'Nodes were ordered correctly in block.');
|
||||
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Verify that the More link is shown and leads to the admin content page.
|
||||
$this->drupalGet('');
|
||||
$this->clickLink('More');
|
||||
$this->assertResponse('200');
|
||||
$this->assertUrl('admin/content');
|
||||
|
||||
// Set the number of recent nodes to show to 10.
|
||||
$block->getPlugin()->setConfigurationValue('items_per_page', 10);
|
||||
$block->save();
|
||||
|
@ -125,7 +120,7 @@ class NodeBlockFunctionalTest extends NodeTestBase {
|
|||
$this->assertText($node3->label(), 'Node found in block.');
|
||||
$this->assertText($node4->label(), 'Node found in block.');
|
||||
|
||||
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'user']);
|
||||
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user']);
|
||||
|
||||
// Enable the "Powered by Drupal" block only on article nodes.
|
||||
$edit = [
|
||||
|
@ -150,16 +145,16 @@ class NodeBlockFunctionalTest extends NodeTestBase {
|
|||
$this->drupalGet('');
|
||||
$label = $block->label();
|
||||
$this->assertNoText($label, 'Block was not displayed on the front page.');
|
||||
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'user', 'route']);
|
||||
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route']);
|
||||
$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', 'theme', 'user', 'route']);
|
||||
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.path', 'url.query_args', 'user', 'route']);
|
||||
$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', 'user', 'route', 'timezone']);
|
||||
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route', 'timezone']);
|
||||
$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', 'user', 'route', 'timezone']);
|
||||
$this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route', 'timezone']);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('admin/structure/block');
|
||||
|
|
|
@ -203,7 +203,7 @@ class NodeCreationTest extends NodeTestBase {
|
|||
$query = db_query("SELECT wid, variables FROM {watchdog}");
|
||||
foreach ($query as $row) {
|
||||
$variables = (array) unserialize($row->variables);
|
||||
if (isset($variables['!message']) && $variables['!message'] === 'Test exception for rollback.') {
|
||||
if (isset($variables['@message']) && $variables['@message'] === 'Test exception for rollback.') {
|
||||
$matches[] = $row->wid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Component\Utility\Html;
|
||||
|
||||
/**
|
||||
* Tests node title.
|
||||
|
@ -85,5 +86,22 @@ class NodeTitleTest extends NodeTestBase {
|
|||
// Test that 0 appears in the template <h1>.
|
||||
$xpath = '//h1';
|
||||
$this->assertEqual(current($this->xpath($xpath)), 0, 'Node title is displayed as 0.', 'Node');
|
||||
|
||||
// Test edge case where node title contains special characters.
|
||||
$edge_case_title = 'article\'s "title".';
|
||||
$settings = array(
|
||||
'title' => $edge_case_title,
|
||||
);
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
// Test that the title appears as <title>. The title will be escaped on the
|
||||
// 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');
|
||||
|
||||
// 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');
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
|
||||
/**
|
||||
* Create a node with dangerous tags in its title and test that they are
|
||||
* escaped.
|
||||
|
@ -34,8 +36,8 @@ class NodeTitleXSSTest extends NodeTestBase {
|
|||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
// assertTitle() decodes HTML-entities inside the <title> element.
|
||||
$this->assertTitle($title . ' | Drupal', 'Title is displayed when viewing a node.');
|
||||
// Titles should be escaped.
|
||||
$this->assertTitle(Html::escape($title) . ' | Drupal', 'Title is displayed when viewing a node.');
|
||||
$this->assertNoRaw($xss, 'Harmful tags are escaped when viewing a node.');
|
||||
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\system\Tests\System\TokenReplaceUnitTestBase;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
/**
|
||||
* Generates text using placeholders for dummy content to check node token
|
||||
|
@ -65,15 +65,15 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
|||
$tests['[node:vid]'] = $node->getRevisionId();
|
||||
$tests['[node:type]'] = 'article';
|
||||
$tests['[node:type-name]'] = 'Article';
|
||||
$tests['[node:title]'] = SafeMarkup::checkPlain($node->getTitle());
|
||||
$tests['[node:title]'] = Html::escape($node->getTitle());
|
||||
$tests['[node:body]'] = $node->body->processed;
|
||||
$tests['[node:summary]'] = $node->body->summary_processed;
|
||||
$tests['[node:langcode]'] = SafeMarkup::checkPlain($node->language()->getId());
|
||||
$tests['[node:langcode]'] = Html::escape($node->language()->getId());
|
||||
$tests['[node:url]'] = $node->url('canonical', $url_options);
|
||||
$tests['[node:edit-url]'] = $node->url('edit-form', $url_options);
|
||||
$tests['[node:author]'] = SafeMarkup::checkPlain($account->getUsername());
|
||||
$tests['[node:author]'] = Html::escape($account->getUsername());
|
||||
$tests['[node:author:uid]'] = $node->getOwnerId();
|
||||
$tests['[node:author:name]'] = SafeMarkup::checkPlain($account->getUsername());
|
||||
$tests['[node:author:name]'] = Html::escape($account->getUsername());
|
||||
$tests['[node:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getCreatedTime(), array('langcode' => $this->interfaceLanguage->getId()));
|
||||
$tests['[node:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime(), array('langcode' => $this->interfaceLanguage->getId()));
|
||||
|
||||
|
|
|
@ -27,13 +27,14 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'theme',
|
||||
'user.permissions',
|
||||
'route.name',
|
||||
'route.menu_active_trails:account',
|
||||
'route.menu_active_trails:footer',
|
||||
'route.menu_active_trails:main',
|
||||
'route.menu_active_trails:tools',
|
||||
'timezone',
|
||||
'user.roles'
|
||||
'url',
|
||||
'user'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,6 +55,11 @@ class NodeValidationTest extends EntityUnitTestBase {
|
|||
$this->assertEqual($violations[0]->getPropertyPath(), 'title');
|
||||
$this->assertEqual($violations[0]->getMessage(), 'This value should not be null.');
|
||||
|
||||
$node->set('title', '');
|
||||
$violations = $node->validate();
|
||||
$this->assertEqual(count($violations), 1, 'Violation found when title is set to an empty string.');
|
||||
$this->assertEqual($violations[0]->getPropertyPath(), 'title');
|
||||
|
||||
// Make the title valid again.
|
||||
$node->set('title', $this->randomString());
|
||||
// Save the node so that it gets an ID and a changed date.
|
||||
|
|
|
@ -41,7 +41,7 @@ class NodeViewTest extends NodeTestBase {
|
|||
$this->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.');
|
||||
$node = $this->drupalCreateNode(array('title' => $title));
|
||||
$this->drupalGet($node->urlInfo());
|
||||
$result = $this->xpath('//span[contains(@class, "field-name-title")]');
|
||||
$result = $this->xpath('//span[contains(@class, "field--name-title")]');
|
||||
$this->assertEqual((string) $result[0], $title, 'The passed title was returned.');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,19 @@ class PageEditTest extends NodeTestBase {
|
|||
protected $webUser;
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['block', 'node', 'datetime'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->webUser = $this->drupalCreateUser(array('edit own page content', 'create page content'));
|
||||
$this->adminUser = $this->drupalCreateUser(array('bypass node access', 'administer nodes'));
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
|
@ -21,13 +22,14 @@ use Drupal\node\Entity\NodeType;
|
|||
class PagePreviewTest extends NodeTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
use CommentTestTrait;
|
||||
|
||||
/**
|
||||
* Enable the node and taxonomy modules to test both on the preview.
|
||||
* Enable the comment, node and taxonomy modules to test on the preview.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'taxonomy');
|
||||
public static $modules = array('node', 'taxonomy', 'comment');
|
||||
|
||||
/**
|
||||
* The name of the created field.
|
||||
|
@ -38,6 +40,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
|
||||
$web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
|
||||
$this->drupalLogin($web_user);
|
||||
|
@ -139,6 +142,14 @@ class PagePreviewTest extends NodeTestBase {
|
|||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
$this->assertFieldByName($term_key, $edit[$term_key] . ' (' . $this->term->id() . ')', 'Term field displayed.');
|
||||
|
||||
// Return to page preview to check everything is as expected.
|
||||
$this->drupalPostForm(NULL, array(), t('Preview'));
|
||||
$this->assertTitle(t('@title | Drupal', array('@title' => $edit[$title_key])), 'Basic page title is preview.');
|
||||
$this->assertText($edit[$title_key], 'Title displayed.');
|
||||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
$this->assertText($edit[$term_key], 'Term displayed.');
|
||||
$this->assertLink(t('Back to content editing'));
|
||||
|
||||
// Assert the content is kept when reloading the page.
|
||||
$this->drupalGet('node/add/page', array('query' => array('uuid' => $uuid)));
|
||||
$this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
|
||||
|
|
68
core/modules/node/src/Tests/Views/NodeFieldTokensTest.php
Normal file
68
core/modules/node/src/Tests/Views/NodeFieldTokensTest.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\NodeFieldTokensTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
use Drupal\node\Tests\Views\NodeTestBase;
|
||||
|
||||
/**
|
||||
* Tests replacement of Views tokens supplied by the Node module.
|
||||
*
|
||||
* @group node
|
||||
* @see \Drupal\node\Tests\NodeTokenReplaceTest
|
||||
*/
|
||||
class NodeFieldTokensTest extends NodeTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_node_tokens');
|
||||
|
||||
/**
|
||||
* Tests token replacement for Views tokens supplied by the Node module.
|
||||
*/
|
||||
public function testViewsTokenReplacement() {
|
||||
// Create the Article content type with a standard body field.
|
||||
/* @var $node_type \Drupal\node\NodeTypeInterface */
|
||||
$node_type = entity_create('node_type', ['type' => 'article', 'name' => 'Article']);
|
||||
$node_type->save();
|
||||
node_add_body_field($node_type);
|
||||
|
||||
// Create a user and a node.
|
||||
$account = $this->createUser();
|
||||
$body = $this->randomMachineName(32);
|
||||
$summary = $this->randomMachineName(16);
|
||||
|
||||
/** @var $node \Drupal\node\NodeInterface */
|
||||
$node = entity_create('node', [
|
||||
'type' => 'article',
|
||||
'tnid' => 0,
|
||||
'uid' => $account->id(),
|
||||
'title' => 'Testing Views tokens',
|
||||
'body' => [['value' => $body, 'summary' => $summary, 'format' => 'plain_text']],
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
$this->drupalGet('test_node_tokens');
|
||||
|
||||
// Body: {{ body }}<br />
|
||||
$this->assertRaw("Body: <p>$body</p>");
|
||||
|
||||
// Raw value: {{ body__value }}<br />
|
||||
$this->assertRaw("Raw value: $body");
|
||||
|
||||
// Raw summary: {{ body__summary }}<br />
|
||||
$this->assertRaw("Raw summary: $summary");
|
||||
|
||||
// Raw format: {{ body__format }}<br />
|
||||
$this->assertRaw("Raw format: plain_text");
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\node\Tests\Views;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\views\Plugin\views\PluginBase;
|
||||
|
@ -65,6 +66,9 @@ class NodeLanguageTest extends NodeTestBase {
|
|||
// "English", or "Spanish", as there is a language field in the view
|
||||
// that prints out those words.
|
||||
$this->nodeTitles = array(
|
||||
LanguageInterface::LANGCODE_NOT_SPECIFIED => array(
|
||||
'First node und',
|
||||
),
|
||||
'es' => array(
|
||||
'Primero nodo es',
|
||||
'Segundo nodo es',
|
||||
|
@ -90,6 +94,13 @@ class NodeLanguageTest extends NodeTestBase {
|
|||
}
|
||||
$node->save();
|
||||
}
|
||||
// Create non-translatable nodes.
|
||||
foreach ($this->nodeTitles[LanguageInterface::LANGCODE_NOT_SPECIFIED] as $index => $title) {
|
||||
$node = $this->drupalCreateNode(array('title' => $title, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'type' => 'page', 'promote' => 1));
|
||||
$node->body->value = $this->randomMachineName(32);
|
||||
$node->save();
|
||||
}
|
||||
|
||||
$this->container->get('router.builder')->rebuild();
|
||||
|
||||
$user = $this->drupalCreateUser(array('access content overview', 'access content'));
|
||||
|
@ -146,6 +157,10 @@ class NodeLanguageTest extends NodeTestBase {
|
|||
// Test the front page view filter. Only node titles in the current language
|
||||
// should be displayed on the front page by default.
|
||||
foreach ($this->nodeTitles as $langcode => $titles) {
|
||||
// The frontpage view does not display content without a language.
|
||||
if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
|
||||
continue;
|
||||
}
|
||||
$this->drupalGet(($langcode == 'en' ? '' : "$langcode/") . 'node');
|
||||
foreach ($titles as $title) {
|
||||
$this->assertText($title);
|
||||
|
@ -188,6 +203,9 @@ class NodeLanguageTest extends NodeTestBase {
|
|||
$config->set('display.default.display_options.filters.langcode.value', array(PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT));
|
||||
$config->save();
|
||||
foreach ($this->nodeTitles as $langcode => $titles) {
|
||||
if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
|
||||
continue;
|
||||
}
|
||||
$this->drupalGet(($langcode == 'en' ? '' : "$langcode/") . 'node');
|
||||
foreach ($this->nodeTitles as $control_langcode => $control_titles) {
|
||||
foreach ($control_titles as $title) {
|
||||
|
|
|
@ -26,7 +26,7 @@ class NodeRevisionWizardTest extends WizardTestBase {
|
|||
// Create two nodes with two revision.
|
||||
$node_storage = \Drupal::entityManager()->getStorage('node');
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$node = $node_storage->create(array('type' => 'article', 'created' => REQUEST_TIME + 40));
|
||||
$node = $node_storage->create(array('title' => $this->randomString(), 'type' => 'article', 'created' => REQUEST_TIME + 40));
|
||||
$node->save();
|
||||
|
||||
$node = $node->createDuplicate();
|
||||
|
@ -34,7 +34,7 @@ class NodeRevisionWizardTest extends WizardTestBase {
|
|||
$node->created->value = REQUEST_TIME + 20;
|
||||
$node->save();
|
||||
|
||||
$node = $node_storage->create(array('type' => 'article', 'created' => REQUEST_TIME + 30));
|
||||
$node = $node_storage->create(array('title' => $this->randomString(), 'type' => 'article', 'created' => REQUEST_TIME + 30));
|
||||
$node->save();
|
||||
|
||||
$node = $node->createDuplicate();
|
||||
|
|
Reference in a new issue