Update to Drupal 8.1.1. For more information, see https://www.drupal.org/node/2718713
This commit is contained in:
parent
c0a0d5a94c
commit
9eae24d844
669 changed files with 3873 additions and 1553 deletions
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests\Condition;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests that conditions, provided by the node module, are working properly.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeConditionTest extends EntityUnitTestBase {
|
||||
|
||||
public static $modules = array('node');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create the node bundles required for testing.
|
||||
$type = NodeType::create(['type' => 'page', 'name' => 'page']);
|
||||
$type->save();
|
||||
$type = NodeType::create(['type' => 'article', 'name' => 'article']);
|
||||
$type->save();
|
||||
$type = NodeType::create(['type' => 'test', 'name' => 'test']);
|
||||
$type->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests conditions.
|
||||
*/
|
||||
function testConditions() {
|
||||
$manager = $this->container->get('plugin.manager.condition', $this->container->get('container.namespaces'));
|
||||
$this->createUser();
|
||||
|
||||
// Get some nodes of various types to check against.
|
||||
$page = Node::create(['type' => 'page', 'title' => $this->randomMachineName(), 'uid' => 1]);
|
||||
$page->save();
|
||||
$article = Node::create(['type' => 'article', 'title' => $this->randomMachineName(), 'uid' => 1]);
|
||||
$article->save();
|
||||
$test = Node::create(['type' => 'test', 'title' => $this->randomMachineName(), 'uid' => 1]);
|
||||
$test->save();
|
||||
|
||||
// Grab the node type condition and configure it to check against node type
|
||||
// of 'article' and set the context to the page type node.
|
||||
$condition = $manager->createInstance('node_type')
|
||||
->setConfig('bundles', array('article' => 'article'))
|
||||
->setContextValue('node', $page);
|
||||
$this->assertFalse($condition->execute(), 'Page type nodes fail node type checks for articles.');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual('The node bundle is article', $condition->summary());
|
||||
|
||||
// Set the node type check to page.
|
||||
$condition->setConfig('bundles', array('page' => 'page'));
|
||||
$this->assertTrue($condition->execute(), 'Page type nodes pass node type checks for pages');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual('The node bundle is page', $condition->summary());
|
||||
|
||||
// Set the node type check to page or article.
|
||||
$condition->setConfig('bundles', array('page' => 'page', 'article' => 'article'));
|
||||
$this->assertTrue($condition->execute(), 'Page type nodes pass node type checks for pages or articles');
|
||||
// Check for the proper summary.
|
||||
$this->assertEqual('The node bundle is page or article', $condition->summary());
|
||||
|
||||
// Set the context to the article node.
|
||||
$condition->setContextValue('node', $article);
|
||||
$this->assertTrue($condition->execute(), 'Article type nodes pass node type checks for pages or articles');
|
||||
|
||||
// Set the context to the test node.
|
||||
$condition->setContextValue('node', $test);
|
||||
$this->assertFalse($condition->execute(), 'Test type nodes pass node type checks for pages or articles');
|
||||
|
||||
// Check a greater than 2 bundles summary scenario.
|
||||
$condition->setConfig('bundles', array('page' => 'page', 'article' => 'article', 'test' => 'test'));
|
||||
$this->assertEqual('The node bundle is page, article or test', $condition->summary());
|
||||
|
||||
// Test Constructor injection.
|
||||
$condition = $manager->createInstance('node_type', array('bundles' => array('article' => 'article'), 'context' => array('node' => $article)));
|
||||
$this->assertTrue($condition->execute(), 'Constructor injection of context and configuration working as anticipated.');
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests\Config;
|
||||
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Change content types during config create method invocation.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeImportChangeTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'field', 'text', 'system', 'node_test_config', 'user'];
|
||||
|
||||
/**
|
||||
* Set the default field storage backend for fields created during tests.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Set default storage backend.
|
||||
$this->installConfig(array('field', 'node_test_config'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests importing an updated content type.
|
||||
*/
|
||||
public function testImportChange() {
|
||||
$node_type_id = 'default';
|
||||
$node_type_config_name = "node.type.$node_type_id";
|
||||
|
||||
// Simulate config data to import:
|
||||
// - a modified version (modified label) of the node type config.
|
||||
$active = $this->container->get('config.storage');
|
||||
$sync = $this->container->get('config.storage.sync');
|
||||
$this->copyConfig($active, $sync);
|
||||
|
||||
$node_type = $active->read($node_type_config_name);
|
||||
$new_label = 'Test update import field';
|
||||
$node_type['name'] = $new_label;
|
||||
// Save as files in the sync directory.
|
||||
$sync->write($node_type_config_name, $node_type);
|
||||
|
||||
// Import the content of the sync directory.
|
||||
$this->configImporter()->import();
|
||||
|
||||
// Check that the updated config was correctly imported.
|
||||
$node_type = NodeType::load($node_type_id);
|
||||
$this->assertEqual($node_type->label(), $new_label, 'Node type name has been updated.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests\Config;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Create content types during config create method invocation.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeImportCreateTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'field', 'text', 'system', 'user');
|
||||
|
||||
/**
|
||||
* Set the default field storage backend for fields created during tests.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
// Set default storage backend.
|
||||
$this->installConfig(array('field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a content type during default config import.
|
||||
*/
|
||||
public function testImportCreateDefault() {
|
||||
$node_type_id = 'default';
|
||||
|
||||
// Check that the content type does not exist yet.
|
||||
$this->assertFalse(NodeType::load($node_type_id));
|
||||
|
||||
// Enable node_test_config module and check that the content type
|
||||
// shipped in the module's default config is created.
|
||||
$this->container->get('module_installer')->install(array('node_test_config'));
|
||||
$node_type = NodeType::load($node_type_id);
|
||||
$this->assertTrue($node_type, 'The default content type was created.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a content type during config import.
|
||||
*/
|
||||
public function testImportCreate() {
|
||||
$node_type_id = 'import';
|
||||
$node_type_config_name = "node.type.$node_type_id";
|
||||
|
||||
// Simulate config data to import.
|
||||
$active = $this->container->get('config.storage');
|
||||
$sync = $this->container->get('config.storage.sync');
|
||||
$this->copyConfig($active, $sync);
|
||||
// Manually add new node type.
|
||||
$src_dir = drupal_get_path('module', 'node_test_config') . '/sync';
|
||||
$target_dir = $this->configDirectories[CONFIG_SYNC_DIRECTORY];
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$node_type_config_name.yml", "$target_dir/$node_type_config_name.yml"));
|
||||
|
||||
// Import the content of the sync directory.
|
||||
$this->configImporter()->import();
|
||||
|
||||
// Check that the content type was created.
|
||||
$node_type = NodeType::load($node_type_id);
|
||||
$this->assertTrue($node_type, 'Import node type from sync was created.');
|
||||
$this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body'));
|
||||
}
|
||||
|
||||
}
|
84
core/modules/node/src/Tests/NodeActionsConfigurationTest.php
Normal file
84
core/modules/node/src/Tests/NodeActionsConfigurationTest.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\system\Entity\Action;
|
||||
|
||||
/**
|
||||
* Tests configuration of actions provided by the Node module.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeActionsConfigurationTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['action', 'node'];
|
||||
|
||||
/**
|
||||
* Tests configuration of the node_assign_owner_action action.
|
||||
*/
|
||||
public function testAssignOwnerNodeActionConfiguration() {
|
||||
// Create a user with permission to view the actions administration pages.
|
||||
$user = $this->drupalCreateUser(['administer actions']);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Make a POST request to admin/config/system/actions.
|
||||
$edit = [];
|
||||
$edit['action'] = Crypt::hashBase64('node_assign_owner_action');
|
||||
$this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Make a POST request to the individual action configuration page.
|
||||
$edit = [];
|
||||
$action_label = $this->randomMachineName();
|
||||
$edit['label'] = $action_label;
|
||||
$edit['id'] = strtolower($action_label);
|
||||
$edit['owner_uid'] = $user->id();
|
||||
$this->drupalPostForm('admin/config/system/actions/add/' . Crypt::hashBase64('node_assign_owner_action'), $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Make sure that the new action was saved properly.
|
||||
$this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully saved.');
|
||||
$this->assertText($action_label, 'The label of the node_assign_owner_action action appears on the actions administration page after saving.');
|
||||
|
||||
// Make another POST request to the action edit page.
|
||||
$this->clickLink(t('Configure'));
|
||||
preg_match('|admin/config/system/actions/configure/(.+)|', $this->getUrl(), $matches);
|
||||
$aid = $matches[1];
|
||||
$edit = [];
|
||||
$new_action_label = $this->randomMachineName();
|
||||
$edit['label'] = $new_action_label;
|
||||
$edit['owner_uid'] = $user->id();
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Make sure that the action updated properly.
|
||||
$this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully updated.');
|
||||
$this->assertNoText($action_label, 'The old label for the node_assign_owner_action action does not appear on the actions administration page after updating.');
|
||||
$this->assertText($new_action_label, 'The new label for the node_assign_owner_action action appears on the actions administration page after updating.');
|
||||
|
||||
// Make sure that deletions work properly.
|
||||
$this->drupalGet('admin/config/system/actions');
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertResponse(200);
|
||||
$edit = [];
|
||||
$this->drupalPostForm("admin/config/system/actions/configure/$aid/delete", $edit, t('Delete'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Make sure that the action was actually deleted.
|
||||
$this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]), 'The delete confirmation message appears after deleting the node_assign_owner_action action.');
|
||||
$this->drupalGet('admin/config/system/actions');
|
||||
$this->assertResponse(200);
|
||||
$this->assertNoText($new_action_label, 'The label for the node_assign_owner_action action does not appear on the actions administration page after deleting.');
|
||||
|
||||
$action = Action::load($aid);
|
||||
$this->assertFalse($action, 'The node_assign_owner_action action is not available after being deleted.');
|
||||
}
|
||||
|
||||
}
|
|
@ -123,7 +123,7 @@ class NodeBlockFunctionalTest extends NodeTestBase {
|
|||
'region' => 'sidebar_first',
|
||||
'visibility[node_type][bundles][article]' => 'article',
|
||||
];
|
||||
$theme = \Drupal::service('theme_handler')->getDefault();
|
||||
$theme = \Drupal::service('theme_handler')->getDefault();
|
||||
$this->drupalPostForm("admin/structure/block/add/system_powered_by_block/$theme", $edit, t('Save block'));
|
||||
|
||||
$block = Block::load($edit['id']);
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests node body field storage.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeBodyFieldStorageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['user', 'system', 'field', 'node', 'text', 'filter'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', 'sequences');
|
||||
// Necessary for module uninstall.
|
||||
$this->installSchema('user', 'users_data');
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('node');
|
||||
$this->installConfig(array('field', 'node'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests node body field storage persistence even if there are no instances.
|
||||
*/
|
||||
public function testFieldOverrides() {
|
||||
$field_storage = FieldStorageConfig::loadByName('node', 'body');
|
||||
$this->assertTrue($field_storage, 'Node body field storage exists.');
|
||||
$type = NodeType::create(['name' => 'Ponies', 'type' => 'ponies']);
|
||||
$type->save();
|
||||
node_add_body_field($type);
|
||||
$field_storage = FieldStorageConfig::loadByName('node', 'body');
|
||||
$this->assertTrue(count($field_storage->getBundles()) == 1, 'Node body field storage is being used on the new node type.');
|
||||
$field = FieldConfig::loadByName('node', 'ponies', 'body');
|
||||
$field->delete();
|
||||
$field_storage = FieldStorageConfig::loadByName('node', 'body');
|
||||
$this->assertTrue(count($field_storage->getBundles()) == 0, 'Node body field storage exists after deleting the only instance of a field.');
|
||||
\Drupal::service('module_installer')->uninstall(array('node'));
|
||||
$field_storage = FieldStorageConfig::loadByName('node', 'body');
|
||||
$this->assertFalse($field_storage, 'Node body field storage does not exist after uninstalling the Node module.');
|
||||
}
|
||||
|
||||
}
|
|
@ -91,7 +91,7 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
$this->assertText($edit[$title_key], 'Title displayed.');
|
||||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
|
||||
// Login as a second administrator user.
|
||||
// Log in as a second administrator user.
|
||||
$second_web_user = $this->drupalCreateUser(array('administer nodes', 'edit any page content'));
|
||||
$this->drupalLogin($second_web_user);
|
||||
// Edit the same node, creating a new revision.
|
||||
|
|
|
@ -1,149 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests node field level access.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeFieldAccessTest extends EntityUnitTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node');
|
||||
|
||||
/**
|
||||
* Fields that only users with administer nodes permissions can change.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $administrativeFields = array(
|
||||
'status',
|
||||
'promote',
|
||||
'sticky',
|
||||
'created',
|
||||
'uid',
|
||||
);
|
||||
|
||||
/**
|
||||
* These fields are automatically managed and can not be changed by any user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $readOnlyFields = array('changed', 'revision_uid', 'revision_timestamp');
|
||||
|
||||
/**
|
||||
* Test permissions on nodes status field.
|
||||
*/
|
||||
function testAccessToAdministrativeFields() {
|
||||
|
||||
// Create the page node type with revisions disabled.
|
||||
$page = NodeType::create([
|
||||
'type' => 'page',
|
||||
'new_revision' => FALSE,
|
||||
]);
|
||||
$page->save();
|
||||
|
||||
// Create the article node type with revisions disabled.
|
||||
$article = NodeType::create([
|
||||
'type' => 'article',
|
||||
'new_revision' => TRUE,
|
||||
]);
|
||||
$article->save();
|
||||
|
||||
// An administrator user. No user exists yet, ensure that the first user
|
||||
// does not have UID 1.
|
||||
$content_admin_user = $this->createUser(array('uid' => 2), array('administer nodes'));
|
||||
|
||||
// Two different editor users.
|
||||
$page_creator_user = $this->createUser(array(), array('create page content', 'edit own page content', 'delete own page content'));
|
||||
$page_manager_user = $this->createUser(array(), array('create page content', 'edit any page content', 'delete any page content'));
|
||||
|
||||
// An unprivileged user.
|
||||
$page_unrelated_user = $this->createUser(array(), array('access content'));
|
||||
|
||||
// List of all users
|
||||
$test_users = array(
|
||||
$content_admin_user,
|
||||
$page_creator_user,
|
||||
$page_manager_user,
|
||||
$page_unrelated_user,
|
||||
);
|
||||
|
||||
// Create three "Basic pages". One is owned by our test-user
|
||||
// "page_creator", one by "page_manager", and one by someone else.
|
||||
$node1 = Node::create(array(
|
||||
'title' => $this->randomMachineName(8),
|
||||
'uid' => $page_creator_user->id(),
|
||||
'type' => 'page',
|
||||
));
|
||||
$node2 = Node::create(array(
|
||||
'title' => $this->randomMachineName(8),
|
||||
'uid' => $page_manager_user->id(),
|
||||
'type' => 'article',
|
||||
));
|
||||
$node3 = Node::create(array(
|
||||
'title' => $this->randomMachineName(8),
|
||||
'type' => 'page',
|
||||
));
|
||||
|
||||
foreach ($this->administrativeFields as $field) {
|
||||
|
||||
// Checks on view operations.
|
||||
foreach ($test_users as $account) {
|
||||
$may_view = $node1->{$field}->access('view', $account);
|
||||
$this->assertTrue($may_view, SafeMarkup::format('Any user may view the field @name.', array('@name' => $field)));
|
||||
}
|
||||
|
||||
// Checks on edit operations.
|
||||
$may_update = $node1->{$field}->access('edit', $page_creator_user);
|
||||
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit own page content" is not allowed to the field @name.', array('@name' => $field)));
|
||||
$may_update = $node2->{$field}->access('edit', $page_creator_user);
|
||||
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit own page content" is not allowed to the field @name.', array('@name' => $field)));
|
||||
$may_update = $node2->{$field}->access('edit', $page_manager_user);
|
||||
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit any page content" is not allowed to the field @name.', array('@name' => $field)));
|
||||
$may_update = $node1->{$field}->access('edit', $page_manager_user);
|
||||
$this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit any page content" is not allowed to the field @name.', array('@name' => $field)));
|
||||
$may_update = $node2->{$field}->access('edit', $page_unrelated_user);
|
||||
$this->assertFalse($may_update, SafeMarkup::format('Users not having permission "edit any page content" is not allowed to the field @name.', array('@name' => $field)));
|
||||
$may_update = $node1->{$field}->access('edit', $content_admin_user) && $node3->status->access('edit', $content_admin_user);
|
||||
$this->assertTrue($may_update, SafeMarkup::format('Users with permission "administer nodes" may edit @name fields on all nodes.', array('@name' => $field)));
|
||||
}
|
||||
|
||||
foreach ($this->readOnlyFields as $field) {
|
||||
// Check view operation.
|
||||
foreach ($test_users as $account) {
|
||||
$may_view = $node1->{$field}->access('view', $account);
|
||||
$this->assertTrue($may_view, SafeMarkup::format('Any user may view the field @name.', array('@name' => $field)));
|
||||
}
|
||||
|
||||
// Check edit operation.
|
||||
foreach ($test_users as $account) {
|
||||
$may_view = $node1->{$field}->access('edit', $account);
|
||||
$this->assertFalse($may_view, SafeMarkup::format('No user is not allowed to edit the field @name.', array('@name' => $field)));
|
||||
}
|
||||
}
|
||||
|
||||
// Check the revision_log field on node 1 which has revisions disabled.
|
||||
$may_update = $node1->revision_log->access('edit', $content_admin_user);
|
||||
$this->assertTrue($may_update, 'A user with permission "administer nodes" can edit the revision_log field when revisions are disabled.');
|
||||
$may_update = $node1->revision_log->access('edit', $page_creator_user);
|
||||
$this->assertFalse($may_update, 'A user without permission "administer nodes" can not edit the revision_log field when revisions are disabled.');
|
||||
|
||||
// Check the revision_log field on node 2 which has revisions enabled.
|
||||
$may_update = $node2->revision_log->access('edit', $content_admin_user);
|
||||
$this->assertTrue($may_update, 'A user with permission "administer nodes" can edit the revision_log field when revisions are enabled.');
|
||||
$may_update = $node2->revision_log->access('edit', $page_creator_user);
|
||||
$this->assertTrue($may_update, 'A user without permission "administer nodes" can edit the revision_log field when revisions are enabled.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Core\Field\Entity\BaseFieldOverride;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests node field overrides.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeFieldOverridesTest extends EntityUnitTestBase {
|
||||
|
||||
/**
|
||||
* Current logged in user.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user', 'system', 'field', 'node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(array('user'));
|
||||
$this->user = $this->createUser();
|
||||
\Drupal::service('current_user')->setAccount($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that field overrides work as expected.
|
||||
*/
|
||||
public function testFieldOverrides() {
|
||||
if (!NodeType::load('ponies')) {
|
||||
NodeType::create(['name' => 'Ponies', 'type' => 'ponies'])->save();
|
||||
}
|
||||
$override = BaseFieldOverride::loadByName('node', 'ponies', 'uid');
|
||||
if ($override) {
|
||||
$override->delete();
|
||||
}
|
||||
$uid_field = \Drupal::entityManager()->getBaseFieldDefinitions('node')['uid'];
|
||||
$config = $uid_field->getConfig('ponies');
|
||||
$config->save();
|
||||
$this->assertEqual($config->get('default_value_callback'), 'Drupal\node\Entity\Node::getCurrentUserId');
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$node = Node::create(['type' => 'ponies']);
|
||||
$owner = $node->getOwner();
|
||||
$this->assertTrue($owner instanceof \Drupal\user\UserInterface);
|
||||
$this->assertEqual($owner->id(), $this->user->id());
|
||||
}
|
||||
|
||||
}
|
|
@ -39,7 +39,7 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
*/
|
||||
function testNodeFormButtons() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
// Login as administrative user.
|
||||
// Log in as administrative user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Verify the buttons on a node add form.
|
||||
|
@ -91,7 +91,7 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
$node_2 = $node_storage->load(2);
|
||||
$this->assertTrue($node_2->isPublished(), 'Node is published');
|
||||
|
||||
// Login as an administrator and unpublish the node that just
|
||||
// Log in as an administrator and unpublish the node that just
|
||||
// was created by the normal user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
@ -100,7 +100,7 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
$node_2 = $node_storage->load(2);
|
||||
$this->assertFalse($node_2->isPublished(), 'Node is unpublished');
|
||||
|
||||
// Login again as the normal user, save the node and verify
|
||||
// Log in again as the normal user, save the node and verify
|
||||
// it's still unpublished.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->webUser);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the admin listing fallback when views is not enabled.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeListBuilderTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'user'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the correct cache contexts are set.
|
||||
*/
|
||||
public function testCacheContexts() {
|
||||
/** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */
|
||||
$list_builder = $this->container->get('entity.manager')->getListBuilder('node');
|
||||
|
||||
$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', 'user.permissions'], $build['#cache']['contexts']);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests node owner functionality.
|
||||
*
|
||||
* @group Entity
|
||||
*/
|
||||
class NodeOwnerTest extends EntityUnitTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'language');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create the node bundles required for testing.
|
||||
$type = NodeType::create(array(
|
||||
'type' => 'page',
|
||||
'name' => 'page',
|
||||
));
|
||||
$type->save();
|
||||
|
||||
// Enable two additional languages.
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
ConfigurableLanguage::createFromLangcode('it')->save();
|
||||
|
||||
$this->installSchema('node', 'node_access');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests node owner functionality.
|
||||
*/
|
||||
public function testOwner() {
|
||||
$user = $this->createUser();
|
||||
|
||||
$container = \Drupal::getContainer();
|
||||
$container->get('current_user')->setAccount($user);
|
||||
|
||||
// Create a test node.
|
||||
$english = Node::create(array(
|
||||
'type' => 'page',
|
||||
'title' => $this->randomMachineName(),
|
||||
'language' => 'en',
|
||||
));
|
||||
$english->save();
|
||||
|
||||
$this->assertEqual($user->id(), $english->getOwnerId());
|
||||
|
||||
$german = $english->addTranslation('de');
|
||||
$german->title = $this->randomString();
|
||||
$italian = $english->addTranslation('it');
|
||||
$italian->title = $this->randomString();
|
||||
|
||||
// Node::preSave() sets owner to anonymous user if owner is nor set.
|
||||
$english->set('uid', ['target_id' => NULL]);
|
||||
$german->set('uid', ['target_id' => NULL]);
|
||||
$italian->set('uid', ['target_id' => NULL]);
|
||||
|
||||
// Entity::save() saves all translations!
|
||||
$italian->save();
|
||||
|
||||
$this->assertEqual(0, $english->getOwnerId());
|
||||
$this->assertEqual(0, $german->getOwnerId());
|
||||
$this->assertEqual(0, $italian->getOwnerId());
|
||||
}
|
||||
|
||||
}
|
|
@ -74,7 +74,7 @@ class NodeRevisionsAllTest extends NodeTestBase {
|
|||
// Get last node for simple checks.
|
||||
$node = $nodes[3];
|
||||
|
||||
// Create and login user.
|
||||
// Create and log in user.
|
||||
$content_admin = $this->drupalCreateUser(
|
||||
array(
|
||||
'view all revisions',
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\system\Tests\System\TokenReplaceUnitTestBase;
|
||||
|
||||
/**
|
||||
* Generates text using placeholders for dummy content to check node token
|
||||
* replacement.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'filter');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(array('filter', 'node'));
|
||||
|
||||
$node_type = NodeType::create(['type' => 'article', 'name' => 'Article']);
|
||||
$node_type->save();
|
||||
node_add_body_field($node_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node, then tests the tokens generated from it.
|
||||
*/
|
||||
function testNodeTokenReplacement() {
|
||||
$url_options = array(
|
||||
'absolute' => TRUE,
|
||||
'language' => $this->interfaceLanguage,
|
||||
);
|
||||
|
||||
// Create a user and a node.
|
||||
$account = $this->createUser();
|
||||
/* @var $node \Drupal\node\NodeInterface */
|
||||
$node = Node::create([
|
||||
'type' => 'article',
|
||||
'tnid' => 0,
|
||||
'uid' => $account->id(),
|
||||
'title' => '<blink>Blinking Text</blink>',
|
||||
'body' => [['value' => 'Regular NODE body for the test.', 'summary' => 'Fancy NODE summary.', 'format' => 'plain_text']],
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Generate and test tokens.
|
||||
$tests = array();
|
||||
$tests['[node:nid]'] = $node->id();
|
||||
$tests['[node:vid]'] = $node->getRevisionId();
|
||||
$tests['[node:type]'] = 'article';
|
||||
$tests['[node:type-name]'] = 'Article';
|
||||
$tests['[node:title]'] = Html::escape($node->getTitle());
|
||||
$tests['[node:body]'] = $node->body->processed;
|
||||
$tests['[node:summary]'] = $node->body->summary_processed;
|
||||
$tests['[node:langcode]'] = $node->language()->getId();
|
||||
$tests['[node:url]'] = $node->url('canonical', $url_options);
|
||||
$tests['[node:edit-url]'] = $node->url('edit-form', $url_options);
|
||||
$tests['[node:author]'] = $account->getUsername();
|
||||
$tests['[node:author:uid]'] = $node->getOwnerId();
|
||||
$tests['[node:author:name]'] = $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()));
|
||||
|
||||
$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) {
|
||||
$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('Node token %token replaced.', ['%token' => $input]));
|
||||
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
|
||||
}
|
||||
|
||||
// Repeat for a node without a summary.
|
||||
$node = Node::create([
|
||||
'type' => 'article',
|
||||
'uid' => $account->id(),
|
||||
'title' => '<blink>Blinking Text</blink>',
|
||||
'body' => [['value' => 'A string that looks random like TR5c2I', 'format' => 'plain_text']],
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Generate and test token - use full body as expected value.
|
||||
$tests = array();
|
||||
$tests['[node:summary]'] = $node->body->processed;
|
||||
|
||||
// Test to make sure that we generated something for each token.
|
||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.');
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $this->tokenService->replace($input, array('node' => $node), array('language' => $this->interfaceLanguage));
|
||||
$this->assertEqual($output, $expected, new FormattableMarkup('Node token %token replaced for node without a summary.', ['%token' => $input]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
'theme',
|
||||
'route',
|
||||
'timezone',
|
||||
'url.path',
|
||||
'url.path.parent',
|
||||
'url.query_args:_wrapper_format',
|
||||
'user'
|
||||
];
|
||||
|
|
|
@ -49,7 +49,7 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$type_exists = (bool) NodeType::load($type->id());
|
||||
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
|
||||
|
||||
// Login a test user.
|
||||
// Log in a test user.
|
||||
$web_user = $this->drupalCreateUser(array('create ' . $type->label() . ' content'));
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class NodeTypeTranslationTest extends WebTestBase {
|
|||
'translate configuration',
|
||||
);
|
||||
|
||||
// Create and login user.
|
||||
// Create and log in user.
|
||||
$this->adminUser = $this->drupalCreateUser($admin_permissions);
|
||||
|
||||
// Add languages.
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests node validation constraints.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeValidationTest extends EntityUnitTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node');
|
||||
|
||||
/**
|
||||
* Set the default field storage backend for fields created during tests.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a node type for testing.
|
||||
$type = NodeType::create(['type' => 'page', 'name' => 'page']);
|
||||
$type->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the node validation constraints.
|
||||
*/
|
||||
public function testValidation() {
|
||||
$this->createUser();
|
||||
$node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]);
|
||||
$violations = $node->validate();
|
||||
$this->assertEqual(count($violations), 0, 'No violations when validating a default node.');
|
||||
|
||||
$node->set('title', $this->randomString(256));
|
||||
$violations = $node->validate();
|
||||
$this->assertEqual(count($violations), 1, 'Violation found when title is too long.');
|
||||
$this->assertEqual($violations[0]->getPropertyPath(), 'title.0.value');
|
||||
$this->assertEqual($violations[0]->getMessage(), '<em class="placeholder">Title</em>: may not be longer than 255 characters.');
|
||||
|
||||
$node->set('title', NULL);
|
||||
$violations = $node->validate();
|
||||
$this->assertEqual(count($violations), 1, 'Violation found when title is not set.');
|
||||
$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.
|
||||
$node->save();
|
||||
// Set the changed date to something in the far past.
|
||||
$node->set('changed', 433918800);
|
||||
$violations = $node->validate();
|
||||
$this->assertEqual(count($violations), 1, 'Violation found when changed date is before the last changed date.');
|
||||
$this->assertEqual($violations[0]->getPropertyPath(), '');
|
||||
$this->assertEqual($violations[0]->getMessage(), 'The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
|
||||
}
|
||||
}
|
|
@ -172,7 +172,7 @@ class FrontPageTest extends ViewTestBase {
|
|||
// When a user with sufficient permissions is logged in, views_ui adds
|
||||
// contextual links to the homepage view. This verifies there are no errors.
|
||||
\Drupal::service('module_installer')->install(array('views_ui'));
|
||||
// Login root user with sufficient permissions.
|
||||
// Log in root user with sufficient permissions.
|
||||
$this->drupalLogin($this->rootUser);
|
||||
// Test frontpage view.
|
||||
$this->drupalGet('node');
|
||||
|
|
|
@ -59,4 +59,3 @@ class NodeRevisionWizardTest extends WizardTestBase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue