Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
52
core/modules/node/src/Tests/AssertButtonsTrait.php
Normal file
52
core/modules/node/src/Tests/AssertButtonsTrait.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\AssertButtonsTrait.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
/**
|
||||
* 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($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.
|
||||
$elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]');
|
||||
$this->assertEqual($count, count($elements));
|
||||
foreach ($elements as $element) {
|
||||
$value = isset($element['value']) ? (string) $element['value'] : '';
|
||||
$this->assertEqual($buttons[$i], $value);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Assert there is a save button.
|
||||
$this->assertTrue(!empty($save_button));
|
||||
$this->assertNoRaw('dropbutton-wrapper');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateNodeBundleSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Test migrating node settings into the base_field_bundle_override config entity.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeBundleSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Setup the bundles.
|
||||
entity_create('node_type', array('type' => 'test_page'))->save();
|
||||
entity_create('node_type', array('type' => 'test_planet'))->save();
|
||||
entity_create('node_type', array('type' => 'test_story'))->save();
|
||||
entity_create('node_type', array('type' => 'test_event'))->save();
|
||||
entity_create('node_type', array('type' => 'story'))->save();
|
||||
entity_create('node_type', array('type' => 'article'))->save();
|
||||
entity_create('node_type', array('type' => 'company'))->save();
|
||||
entity_create('node_type', array('type' => 'employee'))->save();
|
||||
entity_create('node_type', array('type' => 'page'))->save();
|
||||
entity_create('node_type', array('type' => 'sponsor'))->save();
|
||||
entity_create('node_type', array('type' => 'event'))->save();
|
||||
entity_create('node_type', array('type' => 'book'))->save();
|
||||
|
||||
// Create a config entity that already exists.
|
||||
entity_create('base_field_override', array('field_name' => 'promote', 'entity_type' => 'node', 'bundle' => 'page',))->save();
|
||||
|
||||
$id_mappings = array(
|
||||
'd6_node_type' => array(
|
||||
array(array('test_page'), array('test_page')),
|
||||
array(array('test_planet'), array('test_planet')),
|
||||
array(array('test_story'), array('test_story')),
|
||||
array(array('test_event'), array('test_event')),
|
||||
array(array('story'), array('story')),
|
||||
),
|
||||
);
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Drupal 6 node type settings to Drupal 8 migration.
|
||||
*/
|
||||
public function testNodeBundleSettings() {
|
||||
|
||||
// Test settings on test_page bundle.
|
||||
$node = entity_create('node', array('type' => 'test_page'));
|
||||
$this->assertIdentical(1, $node->status->value);
|
||||
$this->assertIdentical(1, $node->promote->value);
|
||||
$this->assertIdentical(1, $node->sticky->value);
|
||||
|
||||
// Test settings for test_story bundle.
|
||||
$node = entity_create('node', array('type' => 'test_story'));
|
||||
$this->assertIdentical(1, $node->status->value);
|
||||
$this->assertIdentical(1, $node->promote->value);
|
||||
$this->assertIdentical(0, $node->sticky->value);
|
||||
|
||||
// Test settings for the test_event bundle.
|
||||
$node = entity_create('node', array('type' => 'test_event'));
|
||||
$this->assertIdentical(0, $node->status->value);
|
||||
$this->assertIdentical(0, $node->promote->value);
|
||||
$this->assertIdentical(1, $node->sticky->value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateNodeConfigsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade variables to node.settings.yml.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadDumps(['Variable.php']);
|
||||
$this->executeMigration('d6_node_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Drupal 6 node settings to Drupal 8 migration.
|
||||
*/
|
||||
public function testNodeSettings() {
|
||||
$config = $this->config('node.settings');
|
||||
$this->assertIdentical(FALSE, $config->get('use_admin_theme'));
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), 'node.settings', $config->get());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateNodeRevisionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Node content revisions migration.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeRevisionTest extends MigrateNodeTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$id_mappings = 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) {
|
||||
$user = entity_create('user', $row);
|
||||
$user->enforceIsNew();
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$this->executeMigration('d6_node_revision');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test node revisions migration from Drupal 6 to 8.
|
||||
*/
|
||||
public function testNodeRevision() {
|
||||
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2);
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$this->assertIdentical('1', $node->id());
|
||||
$this->assertIdentical('2', $node->getRevisionId());
|
||||
$this->assertIdentical('und', $node->langcode->value);
|
||||
$this->assertIdentical('Test title rev 2', $node->getTitle());
|
||||
$this->assertIdentical('body test rev 2', $node->body->value);
|
||||
$this->assertIdentical('teaser test rev 2', $node->body->summary);
|
||||
$this->assertIdentical('2', $node->getRevisionAuthor()->id());
|
||||
$this->assertIdentical('modified rev 2', $node->revision_log->value);
|
||||
$this->assertIdentical('1390095702', $node->getRevisionCreationTime());
|
||||
|
||||
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(5);
|
||||
$this->assertIdentical('1', $node->id());
|
||||
$this->assertIdentical('body test rev 3', $node->body->value);
|
||||
$this->assertIdentical('1', $node->getRevisionAuthor()->id());
|
||||
$this->assertIdentical('modified rev 3', $node->revision_log->value);
|
||||
$this->assertIdentical('1390095703', $node->getRevisionCreationTime());
|
||||
}
|
||||
|
||||
}
|
94
core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php
Normal file
94
core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php
Normal file
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateNodeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Node content migration.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeTest extends MigrateNodeTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
/** @var \Drupal\migrate\entity\Migration $migration */
|
||||
$migration = entity_load('migration', 'd6_node');
|
||||
$executable = new MigrateExecutable($migration, $this);
|
||||
$executable->import();
|
||||
|
||||
// This is required for the second import below.
|
||||
db_truncate($migration->getIdMap()->mapTableName())->execute();
|
||||
$this->standalone = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test node migration from Drupal 6 to 8.
|
||||
*/
|
||||
public function testNode() {
|
||||
$node = Node::load(1);
|
||||
$this->assertIdentical('1', $node->id(), 'Node 1 loaded.');
|
||||
$this->assertIdentical('und', $node->langcode->value);
|
||||
$this->assertIdentical('test', $node->body->value);
|
||||
$this->assertIdentical('test', $node->body->summary);
|
||||
$this->assertIdentical('filtered_html', $node->body->format);
|
||||
$this->assertIdentical('story', $node->getType(), 'Node has the correct bundle.');
|
||||
$this->assertIdentical('Test title', $node->getTitle(), 'Node has the correct title.');
|
||||
$this->assertIdentical('1388271197', $node->getCreatedTime(), 'Node has the correct created time.');
|
||||
$this->assertIdentical(FALSE, $node->isSticky());
|
||||
$this->assertIdentical('1', $node->getOwnerId());
|
||||
$this->assertIdentical('1420861423', $node->getRevisionCreationTime());
|
||||
|
||||
/** @var \Drupal\node\NodeInterface $node_revision */
|
||||
$node_revision = \Drupal::entityManager()->getStorage('node')->loadRevision(1);
|
||||
$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);
|
||||
|
||||
// It is pointless to run the second half from MigrateDrupal6Test.
|
||||
if (empty($this->standalone)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Test that we can re-import using the EntityContentBase destination.
|
||||
$connection = Database::getConnection('default', 'migrate');
|
||||
$connection->update('node_revisions')
|
||||
->fields(array(
|
||||
'title' => 'New node title',
|
||||
'format' => 2,
|
||||
))
|
||||
->condition('vid', 1)
|
||||
->execute();
|
||||
$connection->delete('content_field_test_two')
|
||||
->condition('delta', 1)
|
||||
->execute();
|
||||
|
||||
/** @var \Drupal\migrate\entity\Migration $migration */
|
||||
$migration = entity_load('migration', 'd6_node');
|
||||
$executable = new MigrateExecutable($migration, $this);
|
||||
$executable->import();
|
||||
|
||||
$node = Node::load(1);
|
||||
$this->assertIdentical('New node title', $node->getTitle());
|
||||
// Test a multi-column fields are correctly upgraded.
|
||||
$this->assertIdentical('test', $node->body->value);
|
||||
$this->assertIdentical('full_html', $node->body->format);
|
||||
|
||||
$node = Node::load(3);
|
||||
// Test that format = 0 from source maps to filtered_html.
|
||||
$this->assertIdentical('filtered_html', $node->body->format);
|
||||
}
|
||||
|
||||
}
|
113
core/modules/node/src/Tests/Migrate/d6/MigrateNodeTestBase.php
Normal file
113
core/modules/node/src/Tests/Migrate/d6/MigrateNodeTestBase.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateNodeTestBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Base class for Node migration tests.
|
||||
*/
|
||||
abstract class MigrateNodeTestBase extends MigrateDrupal6TestBase {
|
||||
|
||||
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']);
|
||||
|
||||
// Create a new user which needs to have UID 1, because that is expected by
|
||||
// the assertions from
|
||||
// \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
|
||||
User::create([
|
||||
'uid' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
'status' => 1,
|
||||
])->enforceIsNew(TRUE)->save();
|
||||
|
||||
|
||||
$node_type = entity_create('node_type', array('type' => 'test_planet'));
|
||||
$node_type->save();
|
||||
node_add_body_field($node_type);
|
||||
$node_type = entity_create('node_type', array('type' => 'story'));
|
||||
$node_type->save();
|
||||
node_add_body_field($node_type);
|
||||
|
||||
$id_mappings = array(
|
||||
'd6_node_type' => array(
|
||||
array(array('test_story'), array('story')),
|
||||
),
|
||||
'd6_filter_format' => array(
|
||||
array(array(1), array('filtered_html')),
|
||||
array(array(2), array('full_html')),
|
||||
),
|
||||
'd6_user' => array(
|
||||
array(array(1), array(1)),
|
||||
array(array(2), array(2)),
|
||||
),
|
||||
'd6_field_instance_widget_settings' => array(
|
||||
array(
|
||||
array('page', 'field_test'),
|
||||
array('node', 'page', 'default', 'test'),
|
||||
),
|
||||
),
|
||||
'd6_field_formatter_settings' => array(
|
||||
array(
|
||||
array('page', 'default', 'node', 'field_test'),
|
||||
array('node', 'page', 'default', 'field_test'),
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
$migration = entity_load('migration', 'd6_node_settings');
|
||||
$migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
// Create a test node.
|
||||
$node = entity_create('node', array(
|
||||
'type' => 'story',
|
||||
'nid' => 1,
|
||||
'vid' => 1,
|
||||
'revision_log' => '',
|
||||
));
|
||||
$node->enforceIsNew();
|
||||
$node->save();
|
||||
|
||||
$node = entity_create('node', array(
|
||||
'type' => 'test_planet',
|
||||
'nid' => 3,
|
||||
'vid' => 4,
|
||||
'revision_log' => '',
|
||||
));
|
||||
$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',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateNodeTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Upgrade node types to node.type.*.yml.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateNodeTypeTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'text', 'filter');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('node'));
|
||||
$this->loadDumps(['NodeType.php', 'Variable.php']);
|
||||
$this->executeMigration('d6_node_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Drupal 6 node type to Drupal 8 migration.
|
||||
*/
|
||||
public function testNodeType() {
|
||||
$migration = entity_load('migration', 'd6_node_type');
|
||||
// Test the test_page content type.
|
||||
$node_type_page = NodeType::load('test_page');
|
||||
$this->assertIdentical('test_page', $node_type_page->id(), 'Node type test_page loaded');
|
||||
$this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
|
||||
$this->assertIdentical(FALSE, $node_type_page->isNewRevision());
|
||||
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
|
||||
$this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_page')), array('test_page'));
|
||||
|
||||
// Test we have a body field.
|
||||
$field = FieldConfig::loadByName('node', 'test_page', 'body');
|
||||
$this->assertIdentical('This is the body field label', $field->getLabel(), 'Body field was found.');
|
||||
|
||||
// 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');
|
||||
|
||||
$this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
|
||||
$this->assertIdentical(FALSE, $node_type_story->isNewRevision());
|
||||
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
|
||||
$this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_story')), array('test_story'));
|
||||
|
||||
// Test we don't have a body field.
|
||||
$field = FieldConfig::loadByName('node', 'test_story', 'body');
|
||||
$this->assertIdentical(NULL, $field, 'No body field found');
|
||||
|
||||
// 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');
|
||||
|
||||
$this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
|
||||
$this->assertIdentical(TRUE, $node_type_event->isNewRevision());
|
||||
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
|
||||
$this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_event')), array('test_event'));
|
||||
|
||||
// Test we have a body field.
|
||||
$field = FieldConfig::loadByName('node', 'test_event', 'body');
|
||||
$this->assertIdentical('Body', $field->getLabel(), 'Body field was found.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\node\Tests\Migrate\d6\MigrateViewModesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\node\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewMode;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Migrate view modes.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class MigrateViewModesTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadDumps([
|
||||
'ContentNodeFieldInstance.php',
|
||||
'ContentNodeField.php',
|
||||
'ContentFieldTest.php',
|
||||
'ContentFieldTestTwo.php',
|
||||
'ContentFieldMultivalue.php',
|
||||
]);
|
||||
$this->executeMigration('d6_view_modes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Drupal 6 view modes to Drupal 8 migration.
|
||||
*/
|
||||
public function testViewModes() {
|
||||
// Test a new view mode.
|
||||
$view_mode = EntityViewMode::load('node.preview');
|
||||
$this->assertIdentical(FALSE, is_null($view_mode), 'Preview view mode loaded.');
|
||||
$this->assertIdentical('Preview', $view_mode->label(), 'View mode has correct label.');
|
||||
// Test the Id Map.
|
||||
$this->assertIdentical(array('node', 'preview'), entity_load('migration', 'd6_view_modes')->getIdMap()->lookupDestinationID(array(1)));
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
|
@ -17,6 +18,8 @@ use Drupal\user\RoleInterface;
|
|||
*/
|
||||
class NodeBlockFunctionalTest extends NodeTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* An administrative user for testing.
|
||||
*
|
||||
|
@ -122,6 +125,8 @@ 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']);
|
||||
|
||||
// Enable the "Powered by Drupal" block only on article nodes.
|
||||
$edit = [
|
||||
'id' => strtolower($this->randomMachineName()),
|
||||
|
@ -145,12 +150,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->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->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->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->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('admin/structure/block');
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
|
||||
/**
|
||||
* Tests changing view modes for nodes.
|
||||
*
|
||||
|
@ -37,6 +39,7 @@ class NodeEntityViewModeAlterTest extends NodeTestBase {
|
|||
|
||||
// Set the flag to alter the view mode and view the node.
|
||||
\Drupal::state()->set('node_test_change_view_mode', 'teaser');
|
||||
Cache::invalidateTags(['rendered']);
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
||||
// Check that teaser mode is viewed.
|
||||
|
|
|
@ -14,6 +14,8 @@ namespace Drupal\node\Tests;
|
|||
*/
|
||||
class NodeFormButtonsTest extends NodeTestBase {
|
||||
|
||||
use AssertButtonsTrait;
|
||||
|
||||
/**
|
||||
* A normal logged in user.
|
||||
*
|
||||
|
@ -134,42 +136,4 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
$node_3 = $node_storage->load(3);
|
||||
$this->assertFalse($node_3->isPublished(), 'Node is unpublished');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($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.
|
||||
$elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]');
|
||||
$this->assertEqual($count, count($elements));
|
||||
foreach ($elements as $element) {
|
||||
$value = isset($element['value']) ? (string) $element['value'] : '';
|
||||
$this->assertEqual($buttons[$i], $value);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Assert there is a save button.
|
||||
$this->assertTrue(!empty($save_button));
|
||||
$this->assertNoRaw('dropbutton-wrapper');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class NodeListBuilderTest extends KernelTestBase {
|
|||
$build = $list_builder->render();
|
||||
$this->container->get('renderer')->renderRoot($build);
|
||||
|
||||
$this->assertEqual(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url.query_args.pagers:0', 'user.node_grants:view'], $build['#cache']['contexts']);
|
||||
$this->assertEqual(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url.query_args.pagers:0', 'user.node_grants:view', 'user.permissions'], $build['#cache']['contexts']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
|
@ -16,27 +18,31 @@ use Drupal\node\Entity\NodeType;
|
|||
*/
|
||||
class NodeRevisionsUiTest extends NodeTestBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\Entity\User
|
||||
*/
|
||||
protected $editor;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$web_user = $this->drupalCreateUser(
|
||||
array(
|
||||
'administer nodes',
|
||||
'edit any page content'
|
||||
)
|
||||
);
|
||||
|
||||
$this->drupalLogin($web_user);
|
||||
// Create users.
|
||||
$this->editor = $this->drupalCreateUser([
|
||||
'administer nodes',
|
||||
'edit any page content',
|
||||
'view page revisions',
|
||||
'access user profiles',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that unchecking 'Create new revision' works when editing a node.
|
||||
*/
|
||||
function testNodeFormSaveWithoutRevision() {
|
||||
$this->drupalLogin($this->editor);
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
|
||||
// Set page revision setting 'create new revision'. This will mean new
|
||||
|
@ -73,6 +79,60 @@ class NodeRevisionsUiTest extends NodeTestBase {
|
|||
$node_storage->resetCache(array($node->id()));
|
||||
$node_revision = $node_storage->load($node->id());
|
||||
$this->assertNotEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' checked, a new revision is created.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks HTML double escaping of revision logs.
|
||||
*/
|
||||
public function testNodeRevisionDoubleEscapeFix() {
|
||||
$this->drupalLogin($this->editor);
|
||||
$nodes = [];
|
||||
|
||||
// Create the node.
|
||||
$node = $this->drupalCreateNode();
|
||||
|
||||
$username = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $this->editor,
|
||||
];
|
||||
$editor = \Drupal::service('renderer')->renderPlain($username);
|
||||
|
||||
// Get original node.
|
||||
$nodes[] = clone $node;
|
||||
|
||||
// Create revision with a random title and body and update variables.
|
||||
$node->title = $this->randomMachineName();
|
||||
$node->body = [
|
||||
'value' => $this->randomMachineName(32),
|
||||
'format' => filter_default_format(),
|
||||
];
|
||||
$node->setNewRevision();
|
||||
$revision_log = 'Revision <em>message</em> with markup.';
|
||||
$node->revision_log->value = $revision_log;
|
||||
$node->save();
|
||||
// Make sure we get revision information.
|
||||
$node = Node::load($node->id());
|
||||
$nodes[] = clone $node;
|
||||
|
||||
$this->drupalGet('node/' . $node->id() . '/revisions');
|
||||
|
||||
// Assert the old revision message.
|
||||
$date = format_date($nodes[0]->revision_timestamp->value, 'short');
|
||||
$url = new Url('entity.node.revision', ['node' => $nodes[0]->id(), 'node_revision' => $nodes[0]->getRevisionId()]);
|
||||
$old_revision_message = t('!date by !username', [
|
||||
'!date' => \Drupal::l($date, $url),
|
||||
'!username' => $editor,
|
||||
]);
|
||||
$this->assertRaw($old_revision_message);
|
||||
|
||||
// Assert the current revision message.
|
||||
$date = format_date($nodes[1]->revision_timestamp->value, 'short');
|
||||
$current_revision_message = t('!date by !username', [
|
||||
'!date' => $nodes[1]->link($date),
|
||||
'!username' => $editor,
|
||||
]);
|
||||
$current_revision_message .= '<p class="revision-log">' . $revision_log . '</p>';
|
||||
$this->assertRaw($current_revision_message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\system\Tests\System\TokenReplaceUnitTestBase;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
|
@ -76,12 +77,35 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
|||
$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()));
|
||||
|
||||
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($node);
|
||||
|
||||
$metadata_tests = [];
|
||||
$metadata_tests['[node:nid]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:vid]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:type]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:type-name]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:title]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:body]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:summary]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:langcode]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:url]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:edit-url]'] = $base_bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:author]'] = $bubbleable_metadata->addCacheTags(['user:1']);
|
||||
$metadata_tests['[node:author:uid]'] = $bubbleable_metadata;
|
||||
$metadata_tests['[node:author:name]'] = $bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[node:created:since]'] = $bubbleable_metadata->setCacheMaxAge(0);
|
||||
$metadata_tests['[node:changed:since]'] = $bubbleable_metadata;
|
||||
|
||||
// Test to make sure that we generated something for each token.
|
||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->getId()));
|
||||
$bubbleable_metadata = new BubbleableMetadata();
|
||||
$output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->getId()), $bubbleable_metadata);
|
||||
$this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input)));
|
||||
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
|
||||
}
|
||||
|
||||
// Generate and test unsanitized tokens.
|
||||
|
|
|
@ -12,6 +12,7 @@ use Drupal\content_translation\Tests\ContentTranslationUITestBase;
|
|||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the Node Translation UI.
|
||||
|
@ -20,6 +21,21 @@ use Drupal\node\Entity\Node;
|
|||
*/
|
||||
class NodeTranslationUITest extends ContentTranslationUITestBase {
|
||||
|
||||
/**
|
||||
* {inheritdoc}
|
||||
*/
|
||||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'theme',
|
||||
'user.permissions',
|
||||
'route.menu_active_trails:account',
|
||||
'route.menu_active_trails:footer',
|
||||
'route.menu_active_trails:main',
|
||||
'route.menu_active_trails:tools',
|
||||
'timezone',
|
||||
'user.roles'
|
||||
];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
|
@ -57,6 +73,42 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
$this->doUninstallTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests changing the published status on a node without fields.
|
||||
*/
|
||||
function testPublishedStatusNoFields() {
|
||||
// Test changing the published status of an article without fields.
|
||||
$this->drupalLogin($this->administrator);
|
||||
// Delete all fields.
|
||||
$this->drupalGet('admin/structure/types/manage/article/fields');
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', array(), t('Delete'));
|
||||
|
||||
// Add a node.
|
||||
$default_langcode = $this->langcodes[0];
|
||||
$values[$default_langcode] = array('title' => array(array('value' => $this->randomMachineName())));
|
||||
$entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
|
||||
$entity = entity_load($this->entityTypeId, $entity_id, TRUE);
|
||||
|
||||
// Add a content translation.
|
||||
$langcode = 'fr';
|
||||
$language = ConfigurableLanguage::load($langcode);
|
||||
$values[$langcode] = array('title' => array(array('value' => $this->randomMachineName())));
|
||||
|
||||
$add_url = Url::fromRoute('content_translation.translation_add_' . $entity->getEntityTypeId(), [
|
||||
$entity->getEntityTypeId() => $entity->id(),
|
||||
'source' => $default_langcode,
|
||||
'target' => $langcode
|
||||
], array('language' => $language));
|
||||
$this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), t('Save and unpublish (this translation)'));
|
||||
|
||||
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
|
||||
$translation = $entity->getTranslation($langcode);
|
||||
// Make sure we unpublished the node correctly.
|
||||
$this->assertFalse($this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITestBase::getTranslatorPermission().
|
||||
*/
|
||||
|
|
|
@ -191,7 +191,7 @@ class FrontPageTest extends ViewTestBase {
|
|||
*/
|
||||
public function testCacheTagsWithCachePluginNone() {
|
||||
$this->enablePageCaching();
|
||||
$this->assertFrontPageViewCacheTags(FALSE);
|
||||
$this->doTestFrontPageViewCacheTags(FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +207,7 @@ class FrontPageTest extends ViewTestBase {
|
|||
]);
|
||||
$view->save();
|
||||
|
||||
$this->assertFrontPageViewCacheTags(TRUE);
|
||||
$this->doTestFrontPageViewCacheTags(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,7 +227,7 @@ class FrontPageTest extends ViewTestBase {
|
|||
]);
|
||||
$view->save();
|
||||
|
||||
$this->assertFrontPageViewCacheTags(TRUE);
|
||||
$this->doTestFrontPageViewCacheTags(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,7 +236,7 @@ class FrontPageTest extends ViewTestBase {
|
|||
* @param bool $do_assert_views_caches
|
||||
* Whether to check Views' result & output caches.
|
||||
*/
|
||||
protected function assertFrontPageViewCacheTags($do_assert_views_caches) {
|
||||
protected function doTestFrontPageViewCacheTags($do_assert_views_caches) {
|
||||
$view = Views::getView('frontpage');
|
||||
$view->setDisplay('page_1');
|
||||
|
||||
|
@ -248,24 +248,33 @@ class FrontPageTest extends ViewTestBase {
|
|||
'user.permissions',
|
||||
// Default cache contexts of the renderer.
|
||||
'theme',
|
||||
'url.query_args.pagers:0',
|
||||
'url.query_args',
|
||||
// Attached feed.
|
||||
'url.site',
|
||||
];
|
||||
|
||||
$cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)->getCacheTags();
|
||||
|
||||
// Test before there are any nodes.
|
||||
$empty_node_listing_cache_tags = [
|
||||
'config:views.view.frontpage',
|
||||
'node_list',
|
||||
];
|
||||
|
||||
$render_cache_tags = Cache::mergeTags($empty_node_listing_cache_tags, $cache_context_tags);
|
||||
$render_cache_tags = Cache::mergeTags($render_cache_tags, ['config:system.site']);
|
||||
$this->assertViewsCacheTags(
|
||||
$view,
|
||||
$empty_node_listing_cache_tags,
|
||||
$do_assert_views_caches,
|
||||
$empty_node_listing_cache_tags
|
||||
$render_cache_tags
|
||||
);
|
||||
$expected_tags = Cache::mergeTags($empty_node_listing_cache_tags, $cache_context_tags);
|
||||
$expected_tags = Cache::mergeTags($expected_tags, ['rendered', 'config:user.role.anonymous', 'config:system.site']);
|
||||
$this->assertPageCacheContextsAndTags(
|
||||
Url::fromRoute('view.frontpage.page_1'),
|
||||
$cache_contexts,
|
||||
Cache::mergeTags($empty_node_listing_cache_tags, ['rendered', 'config:user.role.anonymous'])
|
||||
$expected_tags
|
||||
);
|
||||
|
||||
// Create some nodes on the frontpage view. Add more than 10 nodes in order
|
||||
|
@ -307,12 +316,15 @@ class FrontPageTest extends ViewTestBase {
|
|||
'node:14',
|
||||
'node:15',
|
||||
];
|
||||
$first_page_output_cache_tags = Cache::mergeTags($first_page_result_cache_tags, [
|
||||
'config:filter.format.plain_text',
|
||||
'node_view',
|
||||
'user_view',
|
||||
'user:0',
|
||||
]);
|
||||
$cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)->getCacheTags();
|
||||
$first_page_output_cache_tags = Cache::mergeTags($first_page_result_cache_tags, $cache_context_tags);
|
||||
$first_page_output_cache_tags = Cache::mergeTags($first_page_output_cache_tags, [
|
||||
'config:filter.format.plain_text',
|
||||
'node_view',
|
||||
'user_view',
|
||||
'user:0',
|
||||
]
|
||||
);
|
||||
$view->setDisplay('page_1');
|
||||
$view->setCurrentPage(0);
|
||||
$this->assertViewsCacheTags(
|
||||
|
|
Reference in a new issue