Commit 26097106 authored by Liam Morland's avatar Liam Morland
Browse files

ISTWCMS-4705: Store NIDs of all new content

parent 42fc820a
...@@ -261,6 +261,7 @@ class UwWcmsBasicTest extends BrowserTestBase { ...@@ -261,6 +261,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
// uw_ct_sidebar is tested separately below. // uw_ct_sidebar is tested separately below.
]; ];
$content_nids = [];
foreach ($content_types as $content_type => $extra_fields) { foreach ($content_types as $content_type => $extra_fields) {
// Create node. // Create node.
$edit = [ $edit = [
...@@ -282,6 +283,13 @@ class UwWcmsBasicTest extends BrowserTestBase { ...@@ -282,6 +283,13 @@ class UwWcmsBasicTest extends BrowserTestBase {
} }
$this->drupalPostForm('node/add/' . $content_type, $edit, 'Save'); $this->drupalPostForm('node/add/' . $content_type, $edit, 'Save');
// Get the node ID of the newly-created node, store in $content_nids.
$nid = $this->xpath('//a[text() = "View"]');
preg_match('/^node\/(\d+)$/', $nid[0]->getAttribute('data-drupal-link-system-path'), $matches);
$nid = (int) $matches[1];
$this->assert($nid > 0, 'Positive nid found.');
$content_nids[$content_type] = $nid;
// On node creation, the user is redirected to the layout edit page. // On node creation, the user is redirected to the layout edit page.
$this->assertSession()->addressMatches('/^\/[a-z0-9-\/]+\/layout$/'); $this->assertSession()->addressMatches('/^\/[a-z0-9-\/]+\/layout$/');
// Check node title. // Check node title.
...@@ -344,19 +352,6 @@ class UwWcmsBasicTest extends BrowserTestBase { ...@@ -344,19 +352,6 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->assertSession()->elementNotExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-enabled'); $this->assertSession()->elementNotExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-enabled');
$this->assertSession()->elementNotExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-weight'); $this->assertSession()->elementNotExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-weight');
$this->assertSession()->elementNotExists('css', 'a[href$="/admin/structure/menu/link/uw_base_profile.front_page/edit"]'); $this->assertSession()->elementNotExists('css', 'a[href$="/admin/structure/menu/link/uw_base_profile.front_page/edit"]');
// Get alias from the above $url. e.g. https://d8/fdsu1/home/edit.
$url = substr($url, 0, -5);
$url = explode('/', $url);
$alias = end($url);
// Get path (node/nid) from the alias.
$path = \Drupal::service('path_alias.manager')->getPathByAlias('/' . $alias);
$nid = explode('/', $path, 3);
// Get nid. Save for later use.
$web_page_nid = (int) end($nid);
$this->assert($web_page_nid > 0, 'Positive nid found.');
} }
} }
...@@ -399,10 +394,10 @@ class UwWcmsBasicTest extends BrowserTestBase { ...@@ -399,10 +394,10 @@ class UwWcmsBasicTest extends BrowserTestBase {
// UWService::nodeIsHomePage(). // UWService::nodeIsHomePage().
$this->drupalLogin($this->drupalUsers['uw_role_site_manager']); $this->drupalLogin($this->drupalUsers['uw_role_site_manager']);
$this->assert(!UWService::nodeIsHomePage($web_page_nid), 'UWService::nodeIsHomePage() correctly identifies page as not the home page.'); $this->assert(!UWService::nodeIsHomePage($content_nids['uw_ct_web_page']), 'UWService::nodeIsHomePage() correctly identifies page as not the home page.');
// Test that certain options are available when not editing home page. // Test that certain options are available when not editing home page.
$this->drupalGet('node/' . $web_page_nid . '/edit'); $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/edit');
$this->assertSession()->elementExists('css', '#edit-path-0'); $this->assertSession()->elementExists('css', '#edit-path-0');
// Cannot test for #edit-menu because an empty 'div' with that exists. // Cannot test for #edit-menu because an empty 'div' with that exists.
$this->assertSession()->elementExists('css', '#edit-menu-enabled'); $this->assertSession()->elementExists('css', '#edit-menu-enabled');
...@@ -412,17 +407,17 @@ class UwWcmsBasicTest extends BrowserTestBase { ...@@ -412,17 +407,17 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Delete link exists. // Delete link exists.
$this->assertSession()->elementExists('css', 'a#edit-delete'); $this->assertSession()->elementExists('css', 'a#edit-delete');
// Access to delete page. // Access to delete page.
$this->drupalGet('node/' . $web_page_nid . '/delete'); $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/delete');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
// Make the page the home page. // Make the page the home page.
$path = \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $web_page_nid); $path = \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $content_nids['uw_ct_web_page']);
\Drupal::service('config.factory')->getEditable('system.site')->set('page.front', $path)->save(); \Drupal::service('config.factory')->getEditable('system.site')->set('page.front', $path)->save();
$this->assert(UWService::nodeIsHomePage($web_page_nid), 'UWService::nodeIsHomePage() correctly identifies page as the home page.'); $this->assert(UWService::nodeIsHomePage($content_nids['uw_ct_web_page']), 'UWService::nodeIsHomePage() correctly identifies page as the home page.');
// Test that certain options are not available when editing home page. // Test that certain options are not available when editing home page.
$this->drupalGet('node/' . $web_page_nid . '/edit'); $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/edit');
$this->assertSession()->elementNotExists('css', '#edit-path-0'); $this->assertSession()->elementNotExists('css', '#edit-path-0');
$this->assertSession()->elementNotExists('css', '#edit-promote-wrapper'); $this->assertSession()->elementNotExists('css', '#edit-promote-wrapper');
...@@ -435,7 +430,7 @@ class UwWcmsBasicTest extends BrowserTestBase { ...@@ -435,7 +430,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
// No delete link. // No delete link.
$this->assertSession()->elementNotExists('css', 'a#edit-delete'); $this->assertSession()->elementNotExists('css', 'a#edit-delete');
// No access to delete page. // No access to delete page.
$this->drupalGet('node/' . $web_page_nid . '/delete'); $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/delete');
$this->assertSession()->statusCodeEquals(403); $this->assertSession()->statusCodeEquals(403);
} }
......
Supports Markdown
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