Commit 8d3a5f7d authored by webchick's avatar webchick

Issue #2380773 by tibbsa, hussainweb, Mile23: Clean-up Node module test...

Issue #2380773 by tibbsa, hussainweb, Mile23: Clean-up Node module test members - ensure property definition and use of camelCase naming convention
parent cc14b667
......@@ -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 @@ protected function setUp() {
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 @@ protected function setUp() {
*/
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());
......
......@@ -30,7 +30,7 @@ protected function setUp() {
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 @@ public function testCommentPager() {
$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 @@ public function testForumPager() {
// 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');
......
......@@ -13,12 +13,19 @@
* @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;
}
/**
......
......@@ -13,6 +13,12 @@
* @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 @@ protected function setUp() {
// 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 @@ protected function setUp() {
* 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 @@ function testContentAdminSort() {
* @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'));
......
......@@ -14,17 +14,27 @@
*/
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 @@ protected function setUp() {
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 @@ function testNodeFormButtons() {
// 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 @@ function testNodeFormButtons() {
// 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 @@ function testNodeFormButtons() {
// 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 @@ function testNodeFormButtons() {
->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);
......
......@@ -16,6 +16,13 @@
*/
class NodeSaveTest extends NodeTestBase {
/**
* A normal logged in user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* Modules to enable.
*
......@@ -29,7 +36,7 @@ protected function setUp() {
// 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 @@ function testImport() {
$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 @@ function testImport() {
$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 @@ function testImport() {
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 @@ function testTimestamps() {
// 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 @@ function testTimestamps() {
function testDeterminingChanges() {
// Initial creation.
$node = entity_create('node', array(
'uid' => $this->web_user->id(),
'uid' => $this->webUser->id(),
'type' => 'article',
'title' => 'test_changes',
));
......
......@@ -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');
}
......
......@@ -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);
}
/**
......
......@@ -13,21 +13,21 @@
* @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 @@ function testPageEdit() {
*/
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 @@ function testPageAuthoredBy() {
// 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 @@ function testPageAuthoredBy() {
// 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]');
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment