Chris@0: adminUser = $this->drupalCreateUser(['access administration pages', 'access content overview', 'administer nodes', 'bypass node access']); Chris@0: $this->baseUser1 = $this->drupalCreateUser(['access content overview']); Chris@0: $this->baseUser2 = $this->drupalCreateUser(['access content overview', 'view own unpublished content']); Chris@0: $this->baseUser3 = $this->drupalCreateUser(['access content overview', 'bypass node access']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that the table sorting works on the content admin pages. Chris@0: */ Chris@0: public function testContentAdminSort() { Chris@0: $this->drupalLogin($this->adminUser); Chris@0: Chris@0: $changed = REQUEST_TIME; Chris@18: $connection = Database::getConnection(); Chris@0: foreach (['dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB'] as $prefix) { Chris@0: $changed += 1000; Chris@0: $node = $this->drupalCreateNode(['title' => $prefix . $this->randomMachineName(6)]); Chris@18: $connection->update('node_field_data') Chris@0: ->fields(['changed' => $changed]) Chris@0: ->condition('nid', $node->id()) Chris@0: ->execute(); Chris@0: } Chris@0: Chris@0: // Test that the default sort by node.changed DESC actually fires properly. Chris@18: $nodes_query = $connection->select('node_field_data', 'n') Chris@0: ->fields('n', ['title']) Chris@0: ->orderBy('changed', 'DESC') Chris@0: ->execute() Chris@0: ->fetchCol(); Chris@0: Chris@0: $this->drupalGet('admin/content'); Chris@0: foreach ($nodes_query as $delta => $string) { Chris@0: $elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', [':class' => 'views-table', ':label' => $string]); Chris@0: $this->assertTrue(!empty($elements), 'The node was found in the correct order.'); Chris@0: } Chris@0: Chris@0: // Compare the rendered HTML node list to a query for the nodes ordered by Chris@0: // title to account for possible database-dependent sort order. Chris@18: $nodes_query = $connection->select('node_field_data', 'n') Chris@0: ->fields('n', ['title']) Chris@0: ->orderBy('title') Chris@0: ->execute() Chris@0: ->fetchCol(); Chris@0: Chris@0: $this->drupalGet('admin/content', ['query' => ['sort' => 'asc', 'order' => 'title']]); Chris@0: foreach ($nodes_query as $delta => $string) { Chris@0: $elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', [':class' => 'views-table', ':label' => $string]); Chris@0: $this->assertTrue(!empty($elements), 'The node was found in the correct order.'); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests content overview with different user permissions. Chris@0: * Chris@0: * Taxonomy filters are tested separately. Chris@0: * Chris@0: * @see TaxonomyNodeFilterTestCase Chris@0: */ Chris@0: public function testContentAdminPages() { Chris@0: $this->drupalLogin($this->adminUser); Chris@0: Chris@0: // Use an explicit changed time to ensure the expected order in the content Chris@0: // admin listing. We want these to appear in the table in the same order as Chris@0: // they appear in the following code, and the 'content' View has a table Chris@0: // style configuration with a default sort on the 'changed' field DESC. Chris@0: $time = time(); Chris@0: $nodes['published_page'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--]); Chris@0: $nodes['published_article'] = $this->drupalCreateNode(['type' => 'article', 'changed' => $time--]); Chris@0: $nodes['unpublished_page_1'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--, 'uid' => $this->baseUser1->id(), 'status' => 0]); Chris@0: $nodes['unpublished_page_2'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time, 'uid' => $this->baseUser2->id(), 'status' => 0]); Chris@0: Chris@0: // Verify view, edit, and delete links for any content. Chris@0: $this->drupalGet('admin/content'); Chris@0: $this->assertResponse(200); Chris@0: Chris@0: $node_type_labels = $this->xpath('//td[contains(@class, "views-field-type")]'); Chris@0: $delta = 0; Chris@0: foreach ($nodes as $node) { Chris@0: $this->assertLinkByHref('node/' . $node->id()); Chris@0: $this->assertLinkByHref('node/' . $node->id() . '/edit'); Chris@0: $this->assertLinkByHref('node/' . $node->id() . '/delete'); Chris@0: // Verify that we can see the content type label. Chris@0: $this->assertEqual(trim($node_type_labels[$delta]->getText()), $node->type->entity->label()); Chris@0: $delta++; Chris@0: } Chris@0: Chris@0: // Verify filtering by publishing status. Chris@0: $this->drupalGet('admin/content', ['query' => ['status' => TRUE]]); Chris@0: Chris@0: $this->assertLinkByHref('node/' . $nodes['published_page']->id() . '/edit'); Chris@0: $this->assertLinkByHref('node/' . $nodes['published_article']->id() . '/edit'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/edit'); Chris@0: Chris@0: // Verify filtering by status and content type. Chris@0: $this->drupalGet('admin/content', ['query' => ['status' => TRUE, 'type' => 'page']]); Chris@0: Chris@0: $this->assertLinkByHref('node/' . $nodes['published_page']->id() . '/edit'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['published_article']->id() . '/edit'); Chris@0: Chris@0: // Verify no operation links are displayed for regular users. Chris@0: $this->drupalLogout(); Chris@0: $this->drupalLogin($this->baseUser1); Chris@0: $this->drupalGet('admin/content'); Chris@0: $this->assertResponse(200); Chris@0: $this->assertLinkByHref('node/' . $nodes['published_page']->id()); Chris@0: $this->assertLinkByHref('node/' . $nodes['published_article']->id()); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['published_page']->id() . '/edit'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['published_page']->id() . '/delete'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['published_article']->id() . '/edit'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['published_article']->id() . '/delete'); Chris@0: Chris@0: // Verify no unpublished content is displayed without permission. Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id()); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/edit'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/delete'); Chris@0: Chris@0: // Verify no tableselect. Chris@0: $this->assertNoFieldByName('nodes[' . $nodes['published_page']->id() . ']', '', 'No tableselect found.'); Chris@0: Chris@0: // Verify unpublished content is displayed with permission. Chris@0: $this->drupalLogout(); Chris@0: $this->drupalLogin($this->baseUser2); Chris@0: $this->drupalGet('admin/content'); Chris@0: $this->assertResponse(200); Chris@0: $this->assertLinkByHref('node/' . $nodes['unpublished_page_2']->id()); Chris@0: // Verify no operation links are displayed. Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->id() . '/edit'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_2']->id() . '/delete'); Chris@0: Chris@0: // Verify user cannot see unpublished content of other users. Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id()); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/edit'); Chris@0: $this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/delete'); Chris@0: Chris@0: // Verify no tableselect. Chris@0: $this->assertNoFieldByName('nodes[' . $nodes['unpublished_page_2']->id() . ']', '', 'No tableselect found.'); Chris@0: Chris@0: // Verify node access can be bypassed. Chris@0: $this->drupalLogout(); Chris@0: $this->drupalLogin($this->baseUser3); Chris@0: $this->drupalGet('admin/content'); Chris@0: $this->assertResponse(200); Chris@0: foreach ($nodes as $node) { Chris@0: $this->assertLinkByHref('node/' . $node->id()); Chris@0: $this->assertLinkByHref('node/' . $node->id() . '/edit'); Chris@0: $this->assertLinkByHref('node/' . $node->id() . '/delete'); Chris@0: } Chris@0: } Chris@0: Chris@0: }