1 node.test | NodeAdminTestCase::testContentAdminPages() |
Tests content overview with different user permissions.
Taxonomy filters are tested separately.
See also
TaxonomyNodeFilterTestCase
File
- core/
modules/ node/ tests/ node.test, line 2446 - Tests for node.module.
Class
- NodeAdminTestCase
- Tests node administration page functionality.
Code
function testContentAdminPages() {
// Do not use any patterns for nodes in this test.
config_set('path.settings', 'node_pattern', '');
config_set('path.settings', 'node_page_pattern', '');
$this->backdropLogin($this->admin_user);
$nodes['published_page'] = $this->backdropCreateNode(array('type' => 'page'));
$nodes['published_post'] = $this->backdropCreateNode(array('type' => 'post'));
$nodes['unpublished_page_1'] = $this->backdropCreateNode(array('type' => 'page', 'uid' => $this->base_user_1->uid, 'status' => 0));
$nodes['unpublished_page_2'] = $this->backdropCreateNode(array('type' => 'page', 'uid' => $this->base_user_2->uid, 'status' => 0));
// Verify view, edit, and delete links for any content.
$this->backdropGet('admin/content');
$this->assertResponse(200);
$index = 0;
foreach ($nodes as $node) {
$this->assertLinkByHref('node/' . $node->nid);
$this->assertLinkByHref('node/' . $node->nid . '/edit');
$this->assertLinkByHref('node/' . $node->nid . '/delete');
// Verify tableselect.
$this->assertFieldByName('bulk_form[' . $index . ']', '', 'Tableselect found.');
$index++;
}
// Verify filtering by publishing status.
$this->backdropGet('admin/content/node', array('query' => array('status' => '1')));
$this->assertFieldByXPath('//select[@name="status"]', '1', 'Content list is filtered by status.');
$this->assertLinkByHref('node/' . $nodes['published_page']->nid . '/edit');
$this->assertLinkByHref('node/' . $nodes['published_post']->nid . '/edit');
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/edit');
// Verify filtering by status and content type.
$this->backdropGet('admin/content/node', array('query' => array('status' => '1', 'type' => 'page')));
$this->assertFieldByXPath('//select[@name="status"]', '1', 'Content list is filtered by status.');
$this->assertFieldByXPath('//select[@name="type"]', 'page', 'Content list is filtered by content type.');
$this->assertLinkByHref('node/' . $nodes['published_page']->nid . '/edit');
$this->assertNoLinkByHref('node/' . $nodes['published_post']->nid . '/edit');
// Verify no operation links are displayed for regular users.
$this->backdropLogout();
$this->backdropLogin($this->base_user_1);
$this->backdropGet('admin/content');
$this->assertResponse(200);
$this->assertLinkByHref('node/' . $nodes['published_page']->nid);
$this->assertLinkByHref('node/' . $nodes['published_post']->nid);
$this->assertNoLinkByHref('node/' . $nodes['published_page']->nid . '/edit');
$this->assertNoLinkByHref('node/' . $nodes['published_page']->nid . '/delete');
$this->assertNoLinkByHref('node/' . $nodes['published_post']->nid . '/edit');
$this->assertNoLinkByHref('node/' . $nodes['published_post']->nid . '/delete');
// Verify no unpublished content is displayed without permission.
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid);
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/edit');
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/delete');
// Verify no tableselect.
$this->assertNoFieldByName('nodes[' . $nodes['published_page']->nid . ']', '', 'No tableselect found.');
// Verify unpublished content is displayed with permission.
$this->backdropLogout();
$this->backdropLogin($this->base_user_2);
$this->backdropGet('admin/content');
$this->assertResponse(200);
$this->assertLinkByHref('node/' . $nodes['unpublished_page_2']->nid);
// Verify no operation links are displayed.
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->nid . '/edit');
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->nid . '/delete');
// Verify user cannot see unpublished content of other users.
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid);
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/edit');
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->nid . '/delete');
// Verify no tableselect.
$this->assertNoFieldByName('nodes[' . $nodes['unpublished_page_2']->nid . ']', '', 'No tableselect found.');
// Verify node access can be bypassed.
$this->backdropLogout();
$this->backdropLogin($this->base_user_3);
$this->backdropGet('admin/content');
$this->assertResponse(200);
foreach ($nodes as $node) {
$this->assertLinkByHref('node/' . $node->nid);
$this->assertLinkByHref('node/' . $node->nid . '/edit');
$this->assertLinkByHref('node/' . $node->nid . '/delete');
}
// Verify 'view any unpublished content' allows view but not edit or delete.
$this->backdropLogout();
$this->backdropLogin($this->base_user_4);
$this->backdropGet('admin/content');
$this->assertResponse(200);
foreach ($nodes as $node) {
$this->assertLinkByHref('node/' . $node->nid);
$this->assertNoLinkByHref('node/' . $node->nid . '/edit');
$this->assertNoLinkByHref('node/' . $node->nid . '/delete');
}
}