Issue #2380773 by tibbsa, hussainweb, Mile23: Clean-up Node module test members - ensure property definition and use of camelCase naming convention

8.0.x
webchick 2015-01-06 11:25:22 -08:00
parent cc14b667ca
commit 8d3a5f7d69
11 changed files with 188 additions and 139 deletions

View File

@ -27,21 +27,21 @@ class NodeAccessFieldTest extends NodeTestBase {
*
* @var \Drupal\user\UserInterface
*/
protected $admin_user;
protected $adminUser;
/**
* A user with permission to manage content types and fields.
*
* @var \Drupal\user\UserInterface
*/
protected $content_admin_user;
protected $contentAdminUser;
/**
* The name of the created field.
*
* @var string
*/
protected $field_name;
protected $fieldName;
protected function setUp() {
parent::setUp();
@ -49,26 +49,26 @@ class NodeAccessFieldTest extends NodeTestBase {
node_access_rebuild();
// Create some users.
$this->admin_user = $this->drupalCreateUser(array('access content', 'bypass node access'));
$this->content_admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields'));
$this->adminUser = $this->drupalCreateUser(array('access content', 'bypass node access'));
$this->contentAdminUser = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields'));
// Add a custom field to the page content type.
$this->field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
$this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
entity_create('field_storage_config', array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'text'
))->save();
entity_create('field_config', array(
'field_name' => $this->field_name,
'field_name' => $this->fieldName,
'entity_type' => 'node',
'bundle' => 'page',
))->save();
entity_get_display('node', 'page', 'default')
->setComponent($this->field_name)
->setComponent($this->fieldName)
->save();
entity_get_form_display('node', 'page', 'default')
->setComponent($this->field_name)
->setComponent($this->fieldName)
->save();
}
@ -77,32 +77,32 @@ class NodeAccessFieldTest extends NodeTestBase {
*/
function testNodeAccessAdministerField() {
// Create a page node.
$field_data = array();
$value = $field_data[0]['value'] = $this->randomMachineName();
$node = $this->drupalCreateNode(array($this->field_name => $field_data));
$fieldData = array();
$value = $fieldData[0]['value'] = $this->randomMachineName();
$node = $this->drupalCreateNode(array($this->fieldName => $fieldData));
// Log in as the administrator and confirm that the field value is present.
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$this->drupalGet('node/' . $node->id());
$this->assertText($value, 'The saved field value is visible to an administrator.');
// Log in as the content admin and try to view the node.
$this->drupalLogin($this->content_admin_user);
$this->drupalLogin($this->contentAdminUser);
$this->drupalGet('node/' . $node->id());
$this->assertText('Access denied', 'Access is denied for the content admin.');
// Modify the field default as the content admin.
$edit = array();
$default = 'Sometimes words have two meanings';
$edit["default_value_input[{$this->field_name}][0][value]"] = $default;
$edit["default_value_input[{$this->fieldName}][0][value]"] = $default;
$this->drupalPostForm(
"admin/structure/types/manage/page/fields/node.page.{$this->field_name}",
"admin/structure/types/manage/page/fields/node.page.{$this->fieldName}",
$edit,
t('Save settings')
);
// Log in as the administrator.
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
// Confirm that the existing node still has the correct field value.
$this->drupalGet('node/' . $node->id());

View File

@ -37,14 +37,14 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
*
* @var \Drupal\user\Entity\UserInterface.
*/
protected $web_user;
protected $webUser;
/**
* User 1.
*
* @var \Drupal\user\Entity\UserInterface.
*/
protected $admin_user;
protected $adminUser;
protected function setUp() {
parent::setUp();
@ -82,11 +82,11 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
ConfigurableLanguage::createFromLangcode('ca')->save();
// Create a normal authenticated user.
$this->web_user = $this->drupalCreateUser(array('access content'));
$this->webUser = $this->drupalCreateUser(array('access content'));
// Load the user 1 user for later use as an admin user with permission to
// see everything.
$this->admin_user = user_load(1);
$this->adminUser = user_load(1);
// The node_access_test_language module allows individual translations of a
// node to be marked private (not viewable by normal users), and the
@ -195,75 +195,75 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
// When the node and both translations are public, access should only be
// denied when a translation that does not exist is requested.
$this->assertNodeAccess($expected_node_access, $this->nodes['public_both_public'], $this->web_user);
$this->assertNodeAccess($expected_node_access, $this->nodes['public_both_public'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['public_both_public'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_public'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access, $this->nodes['public_both_public'], $this->webUser);
$this->assertNodeAccess($expected_node_access, $this->nodes['public_both_public'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['public_both_public'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_public'], $this->webUser, 'en');
// If the node is marked private but both existing translations are not,
// access should still be granted, because the grants are additive.
$this->assertNodeAccess($expected_node_access, $this->nodes['private_both_public'], $this->web_user);
$this->assertNodeAccess($expected_node_access, $this->nodes['private_both_public'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['private_both_public'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_public'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access, $this->nodes['private_both_public'], $this->webUser);
$this->assertNodeAccess($expected_node_access, $this->nodes['private_both_public'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['private_both_public'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_public'], $this->webUser, 'en');
// If the node is marked private, but a existing translation is public,
// access should only be granted for the public translation. For a
// translation that does not exist yet (English translation), the access is
// denied. With the Hungarian translation marked as private, but the Catalan
// translation public, the access is granted.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_hu_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_hu_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['public_hu_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_hu_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_hu_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_hu_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['public_hu_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_hu_private'], $this->webUser, 'en');
// With the Catalan translation marked as private, but the node public,
// access is granted for the existing Hungarian translation, but not for the
// Catalan nor the English ones.
$this->assertNodeAccess($expected_node_access, $this->nodes['public_ca_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access, $this->nodes['public_ca_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_ca_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_ca_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access, $this->nodes['public_ca_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access, $this->nodes['public_ca_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_ca_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_ca_private'], $this->webUser, 'en');
// With both translations marked as private, but the node public, access
// should be denied in all cases.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_both_private'], $this->webUser, 'en');
// If the node and both its existing translations are private, access should
// be denied in all cases.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_both_private'], $this->webUser, 'en');
// No access for all languages as the language aware node access module
// denies access.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->webUser, 'en');
// Access only for request with no language defined.
$this->assertNodeAccess($expected_node_access, $this->nodes['public_no_language_public'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access, $this->nodes['public_no_language_public'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->webUser, 'en');
// No access for all languages as both node access modules deny access.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->webUser, 'en');
// No access for all languages as the non language aware node access module
// denies access.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->webUser, 'en');
// Query the node table with the node access tag in several languages.
@ -271,7 +271,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
// Query with no language specified. The fallback (hu or und) will be used.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -286,7 +286,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
// Query with Hungarian (hu) specified.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'hu')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -300,7 +300,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
// Query with Catalan (ca) specified.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'ca')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -314,7 +314,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
// Query with German (de) specified.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'de')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -326,7 +326,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
// tag and no specific langcode.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->admin_user)
->addMetaData('account', $this->adminUser)
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -337,7 +337,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
// tag and langcode de.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->admin_user)
->addMetaData('account', $this->adminUser)
->addMetaData('langcode', 'de')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');

View File

@ -32,12 +32,19 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
*/
protected $nodes = array();
/**
* A user with permission to bypass access content.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* A normal authenticated user.
*
* @var \Drupal\user\UserInterface
*/
protected $web_user;
protected $webUser;
protected function setUp() {
parent::setUp();
@ -69,11 +76,11 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
node_access_rebuild();
// Create a normal authenticated user.
$this->web_user = $this->drupalCreateUser(array('access content'));
$this->webUser = $this->drupalCreateUser(array('access content'));
// Load the user 1 user for later use as an admin user with permission to
// see everything.
$this->admin_user = user_load(1);
$this->adminUser = user_load(1);
// Add Hungarian and Catalan.
ConfigurableLanguage::createFromLangcode('hu')->save();
@ -148,65 +155,65 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
// When both Hungarian and Catalan are marked as public, access to the
// Hungarian translation should be granted when no language is specified or
// when the Hungarian translation is specified explicitly.
$this->assertNodeAccess($expected_node_access, $this->nodes['both_public'], $this->web_user);
$this->assertNodeAccess($expected_node_access, $this->nodes['both_public'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['both_public'], $this->webUser);
$this->assertNodeAccess($expected_node_access, $this->nodes['both_public'], $this->webUser, 'hu');
// Access to the Catalan translation should also be granted.
$this->assertNodeAccess($expected_node_access, $this->nodes['both_public'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access, $this->nodes['both_public'], $this->webUser, 'ca');
// There is no English translation, so a request to access the English
// translation is denied.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_public'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_public'], $this->webUser, 'en');
// When Hungarian is marked as private, access to the Hungarian translation
// should be denied when no language is specified or when the Hungarian
// translation is specified explicitly.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['hu_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['hu_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['hu_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['hu_private'], $this->webUser, 'hu');
// Access to the Catalan translation should be granted.
$this->assertNodeAccess($expected_node_access, $this->nodes['hu_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access, $this->nodes['hu_private'], $this->webUser, 'ca');
// There is no English translation, so a request to access the English
// translation is denied.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['hu_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['hu_private'], $this->webUser, 'en');
// When Catalan is marked as private, access to the Hungarian translation
// should be granted when no language is specified or when the Hungarian
// translation is specified explicitly.
$this->assertNodeAccess($expected_node_access, $this->nodes['ca_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access, $this->nodes['ca_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access, $this->nodes['ca_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access, $this->nodes['ca_private'], $this->webUser, 'hu');
// Access to the Catalan translation should be granted.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['ca_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['ca_private'], $this->webUser, 'ca');
// There is no English translation, so a request to access the English
// translation is denied.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['ca_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['ca_private'], $this->webUser, 'en');
// When both translations are marked as private, access should be denied
// regardless of the language specified.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['both_private'], $this->webUser, 'en');
// When no language is specified for a private node, access to every
// language is denied.
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->webUser, 'en');
// When no language is specified for a public node, access should be granted
// only for the existing language (not specified), so only the request with
// no language will give access, as this request will be made with the
// langcode of the node, which is "not specified".
$this->assertNodeAccess($expected_node_access, $this->nodes['no_language_public'], $this->web_user);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->web_user, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->web_user, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->web_user, 'en');
$this->assertNodeAccess($expected_node_access, $this->nodes['no_language_public'], $this->webUser);
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->webUser, 'hu');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->webUser, 'ca');
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->webUser, 'en');
// Query the node table with the node access tag in several languages.
// Query with no language specified. The fallback (hu) will be used.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -222,7 +229,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
// Query with Hungarian (hu) specified.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'hu')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -236,7 +243,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
// Query with Catalan (ca) specified.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'ca')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -250,7 +257,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
// Query with German (de) specified.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->web_user)
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'de')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -262,7 +269,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
// tag and no specific langcode.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->admin_user)
->addMetaData('account', $this->adminUser)
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');
@ -273,7 +280,7 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
// tag and langcode de.
$select = db_select('node', 'n')
->fields('n', array('nid'))
->addMetaData('account', $this->admin_user)
->addMetaData('account', $this->adminUser)
->addMetaData('langcode', 'de')
->addTag('node_access');
$nids = $select->execute()->fetchAllAssoc('nid');

View File

@ -30,7 +30,7 @@ class NodeAccessPagerTest extends WebTestBase {
node_access_rebuild();
$this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
$this->container->get('comment.manager')->addDefaultField('node', 'page');
$this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'node test view'));
$this->webUser = $this->drupalCreateUser(array('access content', 'access comments', 'node test view'));
}
/**
@ -55,7 +55,7 @@ class NodeAccessPagerTest extends WebTestBase {
$comment->save();
}
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
// View the node page. With the default 50 comments per page there should
// be two pages (0, 1) but no third (2) page.
@ -92,7 +92,7 @@ class NodeAccessPagerTest extends WebTestBase {
// View the general discussion forum page. With the default 25 nodes per
// page there should be two pages for 30 nodes, no more.
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
$this->drupalGet('forum/' . $tid);
$this->assertRaw('page=1');
$this->assertNoRaw('page=2');

View File

@ -13,12 +13,19 @@ namespace Drupal\node\Tests;
* @group node
*/
class NodeAccessRebuildTest extends NodeTestBase {
/**
* A normal authenticated user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
protected function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'access site reports'));
$this->drupalLogin($web_user);
$this->web_user = $web_user;
$this->webUser = $web_user;
}
/**

View File

@ -13,6 +13,12 @@ namespace Drupal\node\Tests;
* @group node
*/
class NodeAdminTest extends NodeTestBase {
/**
* A user with permission to bypass access content.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Modules to enable.
@ -29,7 +35,7 @@ class NodeAdminTest extends NodeTestBase {
// correctly.
user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array('view own unpublished content'));
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access'));
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access'));
$this->base_user_1 = $this->drupalCreateUser(array('access content overview'));
$this->base_user_2 = $this->drupalCreateUser(array('access content overview', 'view own unpublished content'));
$this->base_user_3 = $this->drupalCreateUser(array('access content overview', 'bypass node access'));
@ -39,7 +45,7 @@ class NodeAdminTest extends NodeTestBase {
* Tests that the table sorting works on the content admin pages.
*/
function testContentAdminSort() {
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$changed = REQUEST_TIME;
foreach (array('dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB') as $prefix) {
@ -87,7 +93,7 @@ class NodeAdminTest extends NodeTestBase {
* @see TaxonomyNodeFilterTestCase
*/
function testContentAdminPages() {
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$nodes['published_page'] = $this->drupalCreateNode(array('type' => 'page'));
$nodes['published_article'] = $this->drupalCreateNode(array('type' => 'article'));

View File

@ -14,17 +14,27 @@ namespace Drupal\node\Tests;
*/
class NodeFormButtonsTest extends NodeTestBase {
protected $web_user;
/**
* A normal logged in user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
protected $admin_user;
/**
* A user with permission to bypass access content.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
// Create a user that has no access to change the state of the node.
$this->web_user = $this->drupalCreateUser(array('create article content', 'edit own article content'));
$this->webUser = $this->drupalCreateUser(array('create article content', 'edit own article content'));
// Create a user that has access to change the state of the node.
$this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access'));
$this->adminUser = $this->drupalCreateUser(array('administer nodes', 'bypass node access'));
}
/**
@ -33,7 +43,7 @@ class NodeFormButtonsTest extends NodeTestBase {
function testNodeFormButtons() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Login as administrative user.
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
// Verify the buttons on a node add form.
$this->drupalGet('node/add/article');
@ -72,7 +82,7 @@ class NodeFormButtonsTest extends NodeTestBase {
// Create a node as a normal user.
$this->drupalLogout();
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
// Verify the buttons for a normal user.
$this->drupalGet('node/add/article');
@ -87,7 +97,7 @@ class NodeFormButtonsTest extends NodeTestBase {
// Login as an administrator and unpublish the node that just
// was created by the normal user.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$this->drupalPostForm('node/' . $node_2->id() . '/edit', array(), t('Save and unpublish'));
$node_storage->resetCache(array(2));
$node_2 = $node_storage->load(2);
@ -96,7 +106,7 @@ class NodeFormButtonsTest extends NodeTestBase {
// Login again as the normal user, save the node and verify
// it's still unpublished.
$this->drupalLogout();
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
$this->drupalPostForm('node/' . $node_2->id() . '/edit', array(), t('Save'));
$node_storage->resetCache(array(2));
$node_2 = $node_storage->load(2);
@ -112,13 +122,13 @@ class NodeFormButtonsTest extends NodeTestBase {
->save();
// Verify the buttons on a node add form for an administrator.
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$this->drupalGet('node/add/article');
$this->assertButtons(array(t('Save as unpublished'), t('Save and publish')));
// Verify the node is unpublished by default for a normal user.
$this->drupalLogout();
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
$edit = array('title[0][value]' => $this->randomString());
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$node_3 = $node_storage->load(3);

View File

@ -16,6 +16,13 @@ use Drupal\node\Entity\Node;
*/
class NodeSaveTest extends NodeTestBase {
/**
* A normal logged in user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* Modules to enable.
*
@ -29,7 +36,7 @@ class NodeSaveTest extends NodeTestBase {
// Create a user that is allowed to post; we'll use this to test the submission.
$web_user = $this->drupalCreateUser(array('create article content'));
$this->drupalLogin($web_user);
$this->web_user = $web_user;
$this->webUser = $web_user;
}
/**
@ -48,7 +55,7 @@ class NodeSaveTest extends NodeTestBase {
$node = array(
'title' => $title,
'body' => array(array('value' => $this->randomMachineName(32))),
'uid' => $this->web_user->id(),
'uid' => $this->webUser->id(),
'type' => 'article',
'nid' => $test_nid,
);
@ -57,7 +64,7 @@ class NodeSaveTest extends NodeTestBase {
$node->enforceIsNew();
// Verify that node_submit did not overwrite the user ID.
$this->assertEqual($node->getOwnerId(), $this->web_user->id(), 'Function node_submit() preserves user ID');
$this->assertEqual($node->getOwnerId(), $this->webUser->id(), 'Function node_submit() preserves user ID');
$node->save();
// Test the import.
@ -74,7 +81,7 @@ class NodeSaveTest extends NodeTestBase {
function testTimestamps() {
// Use the default timestamps.
$edit = array(
'uid' => $this->web_user->id(),
'uid' => $this->webUser->id(),
'type' => 'article',
'title' => $this->randomMachineName(8),
);
@ -101,7 +108,7 @@ class NodeSaveTest extends NodeTestBase {
// Programmatically set the timestamps on the node.
$edit = array(
'uid' => $this->web_user->id(),
'uid' => $this->webUser->id(),
'type' => 'article',
'title' => $this->randomMachineName(8),
'created' => 280299600, // Sun, 19 Nov 1978 05:00:00 GMT
@ -132,7 +139,7 @@ class NodeSaveTest extends NodeTestBase {
function testDeterminingChanges() {
// Initial creation.
$node = entity_create('node', array(
'uid' => $this->web_user->id(),
'uid' => $this->webUser->id(),
'type' => 'article',
'title' => 'test_changes',
));

View File

@ -21,13 +21,18 @@ class NodeTitleTest extends NodeTestBase {
*/
public static $modules = array('comment', 'views');
protected $admin_user;
/**
* A user with permission to bypass access content.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer nodes', 'create article content', 'create page content', 'post comments'));
$this->drupalLogin($this->admin_user);
$this->adminUser = $this->drupalCreateUser(array('administer nodes', 'create article content', 'create page content', 'post comments'));
$this->drupalLogin($this->adminUser);
$this->container->get('comment.manager')->addDefaultField('node', 'page');
}

View File

@ -26,13 +26,20 @@ class NodeTypeRenameConfigImportTest extends WebTestBase {
*/
public static $modules = array('node', 'text', 'config');
/**
* A normal logged in user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('synchronize configuration'));
$this->drupalLogin($this->web_user);
$this->webUser = $this->drupalCreateUser(array('synchronize configuration'));
$this->drupalLogin($this->webUser);
}
/**

View File

@ -13,21 +13,21 @@ namespace Drupal\node\Tests;
* @group node
*/
class PageEditTest extends NodeTestBase {
protected $web_user;
protected $admin_user;
protected $webUser;
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
$this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes'));
$this->webUser = $this->drupalCreateUser(array('edit own page content', 'create page content'));
$this->adminUser = $this->drupalCreateUser(array('bypass node access', 'administer nodes'));
}
/**
* Checks node edit functionality.
*/
function testPageEdit() {
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
$title_key = 'title[0][value]';
$body_key = 'body[0][value]';
@ -92,7 +92,7 @@ class PageEditTest extends NodeTestBase {
*/
function testPageAuthoredBy() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
// Create node to edit.
$body_key = 'body[0][value]';
@ -103,7 +103,7 @@ class PageEditTest extends NodeTestBase {
// Check that the node was authored by the currently logged in user.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertIdentical($node->getOwnerId(), $this->admin_user->id(), 'Node authored by admin user.');
$this->assertIdentical($node->getOwnerId(), $this->adminUser->id(), 'Node authored by admin user.');
// Try to change the 'authored by' field to an invalid user name.
$edit = array(
@ -121,14 +121,14 @@ class PageEditTest extends NodeTestBase {
// Change the authored by field to another user's name (that is not
// logged in).
$edit['uid[0][target_id]'] = $this->web_user->getUsername();
$edit['uid[0][target_id]'] = $this->webUser->getUsername();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
$node_storage->resetCache(array($node->id()));
$node = $node_storage->load($node->id());
$this->assertIdentical($node->getOwnerId(), $this->web_user->id(), 'Node authored by normal user.');
$this->assertIdentical($node->getOwnerId(), $this->webUser->id(), 'Node authored by normal user.');
// Check that normal users cannot change the authored by information.
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertNoFieldByName('uid[0][target_id]');
}