Commit bbc9028a authored by Chris Shantz's avatar Chris Shantz
Browse files

Merge branch '3.0.x' into prod/3.0.x

parents 83b620e4 cfc418ac
......@@ -7,6 +7,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\uw_cfg_common\Service\UWService;
use Behat\Mink\Element\NodeElement;
/**
* Basic WCMS test.
......@@ -100,6 +101,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->ckeditorButtonsTest();
$this->bannerBlockTest();
$this->ofisTest();
$this->nodeRevisionDeleteTest();
}
/**
......@@ -361,8 +363,92 @@ class UwWcmsBasicTest extends BrowserTestBase {
* Test content creation.
*/
private function createContent() {
$this->drupalLogin($this->drupalUsers['uw_role_content_author']);
$this->drupalLogin($this->drupalUsers['administrator']);
// Create three events node including the below dates.
// The first two nodes are non-sticky, the third is sticky.
$dates = [
'2021-07-01',
'2021-06-01',
'2021-08-01',
];
foreach ($dates as $date) {
$edits['event'][] = [
'edit-title-0-value' => $date,
'edit-field-uw-event-summary-0-value' => 'string',
'edit-field-uw-event-date-0-value-date' => $date,
'edit-field-uw-event-date-0-value-time' => '13:00:00',
'edit-field-uw-event-date-0-end-value-date' => $date,
'edit-field-uw-event-date-0-end-value-time' => '14:00:00',
'edit-field-uw-meta-description-0-value' => 'string',
'edit-moderation-state-0-state' => 'published',
'edit-sticky-value' => ($date === '2021-08-01') ? 1 : 0,
];
$edits['blog'][] = [
'edit-title-0-value' => $date,
'edit-field-uw-blog-date-0-value-date' => $date,
'edit-field-uw-blog-summary-0-value' => 'string',
'edit-field-uw-meta-description-0-value' => 'string',
'edit-moderation-state-0-state' => 'published',
'edit-sticky-value' => ($date === '2021-08-01') ? 1 : 0,
];
$edits['news_item'][] = [
'edit-title-0-value' => $date,
'edit-field-uw-news-date-0-value-date' => $date,
'edit-field-uw-news-summary-0-value' => 'string',
'edit-field-uw-meta-description-0-value' => 'string',
'edit-moderation-state-0-state' => 'published',
'edit-sticky-value' => ($date === '2021-08-01') ? 1 : 0,
];
}
foreach ($edits as $content_type => $items) {
foreach ($items as $item) {
$this->drupalPostForm('node/add/uw_ct_' . $content_type, $item, 'Save');
}
}
// Get expected sort dates for late use.
// The stick one is the first, then sort by date field asc.
$expected_dates = [
'2021-08-01',
'2021-06-01',
'2021-07-01',
];
$expected_date_fields = [
'2021-08-01',
'2021-07-01',
'2021-06-01',
];
$page_views = [
'events',
'blog',
'news',
];
foreach ($page_views as $view) {
$this->drupalGet($view);
$this->assertSession()->statusCodeEquals(200);
$rows = $this->xpath('//div[@class="views-row"]');
// Events: getText() shows "Thursday, July 1, 2021
// 1:00 PM - 2:00 PM AEST 2021-07-01 string".
// Blog: getText() shows "Tuesday, July 1, 2021 2021-06-01
// by administrator string"
// News: getTest() shows "Thursday, July 1, 2021
// 2021-07-01 string".
// Get the actual date from the text above.
foreach ($rows as $key => $row) {
preg_match("/\d{4}\-\d{2}-\d{2}/", $row->getText(), $matches);
if ($view == 'events') {
$this->assertEqual($matches[0], $expected_dates[$key]);
}
else {
$this->assertEqual($matches[0], $expected_date_fields[$key]);
}
}
}
$this->drupalLogin($this->drupalUsers['uw_role_content_author']);
// Make sure audience taxonomy to blog, catalog,
// event and news item content types.
$types = [
......@@ -1642,6 +1728,10 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Check admin/people/permissions page.
$this->drupalGet('admin/people/permissions');
$this->assertSession()->statusCodeEquals(200);
// Content editors should have 'update any media'.
$this->assertSession()->checkboxChecked('edit-uw-role-content-editor-update-any-media');
// Site managers should not have 'access content access form'.
$this->assertSession()->checkboxNotChecked('edit-uw-role-site-manager-access-content-access-form');
// Site owner role has administer users.
$this->assertSession()->checkboxChecked('edit-uw-role-site-owner-administer-users');
// Only the site owner role assign roles permissions.
......@@ -2476,4 +2566,89 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->assertSession()->pageTextNotContains('Clear OFIS caches');
}
/**
* Test for node revision delete config.
*/
public function nodeRevisionDeleteTest() {
// Login as administrator and check node revision delete config form.
$this->drupalLogin($this->drupalUsers['administrator']);
$this->drupalGet('admin/config/content/node_revision_delete');
$this->assertSession()->statusCodeEquals(200);
$page = $this->getSession()->getPage();
// Ensures that the current configuration table is found.
$table = $page->find('css', 'table#edit-current-configuration');
$this->assertNotNull($table);
// Ensures that the expected table headers are found.
$headers = $table->findAll('css', 'thead th');
$this->assertEquals(8, count($headers));
$expected_headers = [
'Content type',
'Machine name',
'Minimum to keep',
'Minimum age',
'When to delete',
'Candidate nodes',
'Candidate revisions',
'Operations',
];
$actual_headers = array_map(function (NodeElement $element) {
return $element->getText();
}, $headers);
$this->assertSame($expected_headers, $actual_headers);
// Ensures that all the layouts are listed in the table.
$content_types = [
'uw_ct_blog' => 'Blog post',
'uw_ct_catalog_item' => 'Catalog item',
'uw_ct_contact' => 'Contact',
'uw_ct_event' => 'Event',
'uw_ct_news_item' => 'News item',
'uw_ct_profile' => 'Profile',
'uw_ct_sidebar' => 'Sidebar',
'uw_ct_site_footer' => 'Site footer',
'uw_ct_web_page' => 'Web page',
];
$table_rows = $table->findAll('css', 'tbody tr');
$this->assertEquals(9, count($table_rows));
$index = 0;
foreach ($content_types as $machine_name => $content_type) {
$cells = $table_rows[$index]->findAll('css', 'td');
$this->assertEquals(8, count($cells));
$cell_content_type = $cells[0];
$this->assertEquals($cell_content_type->getText(), $content_type);
$cell_machine_name = $cells[1];
$this->assertEquals($cell_machine_name->getText(), $machine_name);
$cell_minimum_to_key = $cells[2];
$this->assertEquals($cell_minimum_to_key->getText(), '50');
$cell_minimum_age = $cells[3];
$this->assertEquals($cell_minimum_age->getText(), 'None');
$cell_when_to_delete = $cells[4];
$this->assertEquals($cell_when_to_delete->getText(), 'Always delete');
$cell_candidate_nodes = $cells[5];
$this->assertEquals($cell_candidate_nodes->getText(), '0');
$cell_candidate_revisions = $cells[6];
$this->assertEquals($cell_candidate_revisions->getText(), '0');
$index++;
}
// Make sure the default settings.
$this->getSession()->getPage()->findField('edit-node-revision-delete-cron')->getValue('50');
$this->getSession()->getPage()->findField('edit-node-revision-delete-time')->getValue('86400');
$this->getSession()->getPage()->findField('edit-node-revision-delete-minimum-age-to-delete-time-max-number')->getValue('12');
$this->getSession()->getPage()->findField('edit-node-revision-delete-minimum-age-to-delete-time-time')->getValue('months');
$this->getSession()->getPage()->findField('edit-node-revision-delete-when-to-delete-time-max-number')->getValue('12');
$this->getSession()->getPage()->findField('edit-node-revision-delete-when-to-delete-time-time')->getValue('months');
}
}
Markdown is supported
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