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 {
// uw_ct_sidebar is tested separately below.
];
$content_nids = [];
foreach ($content_types as $content_type => $extra_fields) {
// Create node.
$edit = [
......@@ -282,6 +283,13 @@ class UwWcmsBasicTest extends BrowserTestBase {
}
$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.
$this->assertSession()->addressMatches('/^\/[a-z0-9-\/]+\/layout$/');
// Check node title.
......@@ -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-weight');
$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 {
// UWService::nodeIsHomePage().
$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.
$this->drupalGet('node/' . $web_page_nid . '/edit');
$this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/edit');
$this->assertSession()->elementExists('css', '#edit-path-0');
// Cannot test for #edit-menu because an empty 'div' with that exists.
$this->assertSession()->elementExists('css', '#edit-menu-enabled');
......@@ -412,17 +407,17 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Delete link exists.
$this->assertSession()->elementExists('css', 'a#edit-delete');
// 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);
// 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();
$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.
$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-promote-wrapper');
......@@ -435,7 +430,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
// No delete link.
$this->assertSession()->elementNotExists('css', 'a#edit-delete');
// 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);
}
......
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