Skip to content

Commit

Permalink
Merge pull request #162 from localgovdrupal/2.x
Browse files Browse the repository at this point in the history
2.1.9 release
  • Loading branch information
finnlewis authored May 14, 2024
2 parents 59a3132 + 170dcc1 commit 6bc1557
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Plugin/Block/GuidesAbstractBaseBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
*/
protected function setPages() {
if (is_null($this->guidePages)) {
// Initialise guidePages as an array.
$this->guidePages = [];

if ($this->node->bundle() == 'localgov_guides_overview') {
$this->overview = $this->node;
}
Expand Down
98 changes: 96 additions & 2 deletions tests/src/Functional/GuidePagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\Tests\localgov_guides\Functional;

use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;
Expand Down Expand Up @@ -58,13 +59,16 @@ class GuidePagesTest extends BrowserTestBase {
*/
protected function setUp(): void {
parent::setUp();

$this->adminUser = $this->drupalCreateUser([
'bypass node access',
'administer nodes',
'administer node fields',
]);
$this->nodeStorage = $this->container->get('entity_type.manager')->getStorage('node');
// Place the guide navigation block.
$this->drupalLogin($this->adminUser);
$this->drupalPlaceBlock('localgov_guides_contents');
$this->drupalLogout();
}

/**
Expand All @@ -76,10 +80,100 @@ public function testConfigForm() {
$this->assertSession()->pageTextContains('Guide pages');
$this->assertSession()->pageTextContains('Guide section title');
$this->assertSession()->pageTextContains('List format');

$this->drupalGet('/admin/structure/types/manage/localgov_guides_page/fields');
$this->assertSession()->pageTextContains('Parent page');
$this->assertSession()->pageTextContains('Guide section title');
}

/**
* Test adding unpublished guide pages via /node/add form.
*/
public function testUnpublishedGuidePages() {
$guide_overview_title = 'Guide overview - ' . $this->randomMachineName(8);
$guide_summary_text = 'Aenean semper sodales augue. In volutpat quam id nisi accumsan scelerisque. Phasellus et dignissim arcu. Quisque vulputate ligula ac mauris consectetur bibendum. Phasellus ultrices velit ultrices efficitur sodales.';
$guide_body_text = 'Vestibulum scelerisque viverra diam in cursus. Donec interdum eget tellus sed volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec tempus at neque vitae tempor. Aenean tristique elit id ultrices ornare. Morbi a mauris magna. Ut diam dui, venenatis non purus in, tincidunt aliquet diam. Maecenas a mattis sapien. Duis ultricies lacinia tortor, et interdum ante rhoncus id. Ut ultrices leo et dui aliquam placerat. Nullam egestas eros a lectus venenatis, vel mattis dolor consectetur. Sed ac mattis purus. Duis vulputate nisi nisl, a varius ligula accumsan non. Praesent sed ipsum nunc. Cras tincidunt, metus in commodo pulvinar, tortor nisi consequat est, ac porttitor orci eros id sem. Suspendisse rutrum risus arcu, quis placerat dolor pulvinar quis.';
$this->drupalLogin($this->adminUser);
$this->drupalGet('/node/add/localgov_guides_overview');
$this->assertSession()->statusCodeEquals(200);
$page = $this->getSession()->getPage();
$page->fillField('edit-title-0-value', $guide_overview_title);
$page->fillField('edit-localgov-guides-section-title-0-value', $guide_overview_title);
$page->fillField('edit-body-0-summary', $guide_summary_text);
$page->fillField('edit-body-0-value', $guide_body_text);
// Set node to be unpublished.
$page->uncheckField('status[value]');
$page->pressButton('Save');
// Check we have a 200 and not a fatal error.
// See https://github.com/localgovdrupal/localgov_guides/issues/159
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Guide overview ' . $guide_overview_title . ' has been created.');
$this->drupalLogout();
$this->drupalGet('/node/1');
$this->assertSession()->statusCodeEquals(403);

// Create a guide overview and couple of unpublished guide pages.
$guide_page_title_1 = 'Guide page - ' . $this->randomMachineName(8);
$guide_page_title_2 = 'Guide page - ' . $this->randomMachineName(8);
$guide_overview_page = $this->createNode([
'title' => $guide_overview_title,
'localgov_guides_section_title' => $guide_overview_title,
'type' => 'localgov_guides_overview',
'status' => NodeInterface::NOT_PUBLISHED,
]);
$guide_page_1 = $this->createNode([
'title' => $guide_page_title_1,
'localgov_guides_section_title' => $guide_page_title_1,
'type' => 'localgov_guides_page',
'status' => NodeInterface::NOT_PUBLISHED,
'localgov_guides_parent' => ['target_id' => $guide_overview_page->id()],
]);
$guide_page_2 = $this->createNode([
'title' => $guide_page_title_2,
'localgov_guides_section_title' => $guide_page_title_2,
'type' => 'localgov_guides_page',
'status' => NodeInterface::NOT_PUBLISHED,
'localgov_guides_parent' => ['target_id' => $guide_overview_page->id()],
]);
$this->drupalLogout();
$this->drupalGet($guide_overview_page->toUrl()->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($guide_page_1->toUrl()->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($guide_page_2->toUrl()->toString());
$this->assertSession()->statusCodeEquals(403);

// Log in and publish the nodes.
$this->drupalLogin($this->adminUser);
$this->drupalGet($guide_overview_page->toUrl()->toString());
$this->clickLink('Edit');
$page = $this->getSession()->getPage();
$page->checkField('status[value]');
$page->pressButton('Save');

$this->drupalGet($guide_page_1->toUrl()->toString());
$this->clickLink('Edit');
$page = $this->getSession()->getPage();
$page->checkField('status[value]');
$page->pressButton('Save');

$this->drupalGet($guide_page_2->toUrl()->toString());
$this->clickLink('Edit');
$page = $this->getSession()->getPage();
$page->checkField('status[value]');
$page->pressButton('Save');

$this->drupalLogout();

// Confirm we can view the guide pages, now that they are published.
$this->drupalGet($guide_overview_page->toUrl()->toString());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($guide_overview_title);
$this->drupalGet($guide_page_1->toUrl()->toString());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($guide_page_title_1);
$this->drupalGet($guide_page_2->toUrl()->toString());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($guide_page_title_2);
}

}

0 comments on commit 6bc1557

Please sign in to comment.