Skip to content
Snippets Groups Projects
Commit 0a73919a authored by Lily Yan's avatar Lily Yan
Browse files

Merge branch 'feature/ISTWCMS-6985-j8fang-hero-banner-validate-test' into '1.0.x'

ISTWCMS-6985: Hero Banner Deleted Test

See merge request !71
parents f67ee81f b25158b4
No related branches found
No related tags found
1 merge request!71ISTWCMS-6985: Hero Banner Deleted Test
<?php
use Codeception\Util\Locator;
/**
* Class WcmsTestsHeroImageCest.
*
* Tests for Titles with Hero Images.
*/
class WcmsTestsHeroImageCest {
/**
* The nodes being used.
*
* @var Drupal\node\Entity\Node
*/
private $nodesUsed = [];
/**
* The node types to be used.
*
* @var string[]
*/
private $nodeTypes = [
'uw_ct_blog',
'uw_ct_event',
'uw_ct_news_item',
];
/**
* Test hero image title tag.
*
* @param AcceptanceTester $i
* The acceptance tester.
*/
public function testHeroImageHeader(AcceptanceTester $i) {
// Login as site manager.
$i->amOnPage('user/logout');
$i->logInWithRole('uw_role_site_manager');
// Get the hero image.
$image = $this->getImage($i);
// Upload image to media.
$this->setImageForMedia($i, $image);
// Step through content types.
foreach ($this->nodeTypes as $nodeType) {
// Create node with random title.
$title = $i->uwRandomString();
$this->nodesUsed[$title] = $i->createCtNode($nodeType, $title);
// Get the path.
switch ($nodeType) {
case 'uw_ct_blog':
$path = 'blog/' . $title;
break;
case 'uw_ct_event':
$path = 'events/' . $title;
break;
case 'uw_ct_news_item':
$path = 'news/' . $title;
break;
}
// Go to node.
$i->amOnPage($path);
// Check title is <h1> tag.
$i->see($title);
$i->seeElement(Locator::contains('h1', $title));
// Edit node.
$i->amOnPage($path . '/edit');
// Select media type image.
$i->selectOption('#edit-field-uw-type-of-media', 'Image');
// Click the Add media button.
$i->click('#edit-field-uw-hero-image-open-button');
$i->waitForText('Add or select media');
$i->waitForElementClickable(Locator::contains('button', 'Insert selected'));
// Check the image to be used.
$for = $i->grabAttributeFrom(
Locator::contains(
'label',
'Select ' . $image['title']
),
'for'
);
$i->checkOption('#' . $for);
// Click the insert selected button.
$i->click(Locator::contains('button', 'Insert selected'));
$i->waitForText('The maximum number of media items have been selected.');
// Save page.
$i->click('#edit-submit');
// Check title is <h1> tag.
$i->waitForText($title);
$i->seeElement(Locator::contains('h1', $title));
}
}
/**
* Function to get the image.
*
* @param AcceptanceTester $i
* The acceptance tester.
*
* @return array[]
* The image.
*/
private function getImage(AcceptanceTester $i): array {
// The image that will be used.
return [
'url' => 'https://uwaterloo.ca/building-the-next-wcms/sites/default/files/uploads/images/exception-experience-wcms3-banner.png',
'title' => $i->uwRandomString(),
];
}
/**
* Function to set the image to be used in hero image.
*
* @param AcceptanceTester $i
* The acceptance tester.
* @param array $image
* The image.
*/
private function setImageForMedia(AcceptanceTester $i, array $image): void {
// Go to the add image page.
$i->amOnPage('media/add/uw_mt_image');
$i->see('Add Image');
// Add remote image.
$i->click('Remote URL');
$i->fillField(
'#edit-name-0-value',
$image['title'],
);
$i->fillField(
'#edit-field-media-image-0-filefield-remote-url',
$image['url'],
);
// Click and transger and ensure that it uploads.
$i->click('Transfer');
$i->waitForText('Alternative text');
// Fill in the alt text field.
$i->fillField('input[id*="edit-field-media-image-0-alt"]', $image['title']);
// Click save and ensure that the image is added.
$i->click('Save');
$i->see('Image ' . $image['title'] . ' has been created');
}
// phpcs:disable
/**
* Function to run after the test completes.
*
* @param AcceptanceTester $i
* Acceptance test variable.
*/
public function _after(AcceptanceTester $i): void {
// phpcs:enable
// Step through each of the nodes used and delete them.
foreach ($this->nodesUsed as $node) {
$node->delete();
}
}
// phpcs:disable
/**
* Function to run after the test fails.
*
* @param AcceptanceTester $i
* Acceptance test variable.
*/
public function _failed(AcceptanceTester $i): void {
// phpcs:enable
// Step through each of the nodes used and delete them.
foreach ($this->nodesUsed as $node) {
$node->delete();
}
}
}
......@@ -237,6 +237,23 @@ class WcmsTestsMediaAboveCest {
// Increment the counter for the test image flag.
$counter++;
}
// Delete banner image.
$i->amOnPage('admin/content/media');
$i->checkOption('input[id="edit-media-bulk-form-0"]');
$i->click('#edit-submit');
$i->waitForText('Are you sure you want to delete this media item?');
$i->click('#edit-submit');
// Return to content page.
$i->amOnPage($path);
// Check title still displays.
$i->waitForText($node_title);
$i->seeElement(Locator::contains('h1', $node_title));
// Re-upload image to media.
$this->setImageForMedia($i, $images[array_key_last($images)]);
}
}
......@@ -331,6 +348,23 @@ class WcmsTestsMediaAboveCest {
$i->seeElementInDOM('.card__media style');
$i->seeElement('.card__featured-image');
$i->seeElement(Locator::contains('.card__featured-image .card__title', $node_title));
// Delete hero image.
$i->amOnPage('admin/content/media');
$i->checkOption('input[id="edit-media-bulk-form-0"]');
$i->click('#edit-submit');
$i->waitForText('Are you sure you want to delete this media item?');
$i->click('#edit-submit');
// Return to content page.
$i->amOnPage($path);
// Check title still displays.
$i->waitForText($node_title);
$i->seeElement(Locator::contains('h1', $node_title));
// Re-upload image to media.
$this->setImageForMedia($i, $images[0]);
}
}
}
......@@ -426,6 +460,43 @@ class WcmsTestsMediaAboveCest {
];
}
/**
* Function to set the image to be used in hero image.
*
* @param AcceptanceTester $i
* The acceptance tester.
* @param array $image
* The image.
*/
private function setImageForMedia(AcceptanceTester $i, array $image): void {
// Go to the add image page.
$i->amOnPage('media/add/uw_mt_image');
$i->see('Add Image');
// Add remote image.
$i->click('Remote URL');
$i->fillField(
'#edit-name-0-value',
$image['title'],
);
$i->fillField(
'#edit-field-media-image-0-filefield-remote-url',
$image['url'],
);
// Click and transger and ensure that it uploads.
$i->click('Transfer');
$i->waitForText('Alternative text');
// Fill in the alt text field.
$i->fillField('input[id*="edit-field-media-image-0-alt"]', $image['title']);
// Click save and ensure that the image is added.
$i->click('Save');
$i->see('Image ' . $image['title'] . ' has been created');
}
/**
* Function to get the image styles.
*
......@@ -459,10 +530,17 @@ class WcmsTestsMediaAboveCest {
// Click on the add image banner button.
$i->click('Add Image banner');
$image_banner_id = 'edit-field-uw-banner-' . $j . '-subform-field-uw-ban-image-open-button';
$i->waitForElementClickable('input[id*="' . $image_banner_id . '"]');
// Ensure the element is visible and clickable.
$i->waitForElementVisible('input[id*="' . $image_banner_id . '"]', 30);
$i->waitForElementClickable('input[id*="' . $image_banner_id . '"]', 30);
// Use JavaScript to scroll to the element.
$i->executeJS("document.querySelector('input[id*=\"" . $image_banner_id . "\"]').scrollIntoView();");
// Click on the Add media button.
$i->click('input[id*="' . $image_banner_id . '"]');
$i->waitForText('Add or select media');
$i->waitForElementClickable(Locator::contains('button', 'Insert selected'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment