Commit ffbcd1ed authored by Lily Yan's avatar Lily Yan
Browse files

ISTWCMS-4535 Change assertFieldByXPath() to xpath()

Change record:
https://www.drupal.org/node/3129738
parent 98ccb1ce
......@@ -151,13 +151,15 @@ class UwWcmsBasicTest extends BrowserTestBase {
// 'Slide speed' is required.
$slide_speed_required = $this->getSession()->getPage()->find('xpath', "//label[contains(text(), 'Slide speed')]");
$this->assertEquals('js-form-required form-required', $slide_speed_required->getAttribute('class'));
$this->assertFieldByXPath('//input[@value="7000" and @name="settings[block_form][field_uw_slide_speed][0][value]"]', NULL, 'Default value is 7000ms.');
// The default value of 'Slide speed' is 7000ms.
$this->assertTrue((bool) $this->xpath('//input[@value="7000" and @name="settings[block_form][field_uw_slide_speed][0][value]"]'), '7000 ms is selected.');
$this->assertSession()->pageTextContains('Enter the time, in milliseconds, that should elapse between slides when the slideshow is playing.');
// 'Transition speed' is required.
$slide_speed_required = $this->getSession()->getPage()->find('xpath', "//label[contains(text(), 'Transition speed')]");
$this->assertEquals('js-form-required form-required', $slide_speed_required->getAttribute('class'));
$this->assertFieldByXPath('//input[@value="400" and @name="settings[block_form][field_uw_transition_speed][0][value]"]', NULL, 'Default value is 400ms.');
// The default value of 'Transition speed' is 400ms.
$this->assertTrue((bool) $this->xpath('//input[@value="400" and @name="settings[block_form][field_uw_transition_speed][0][value]"]'), '400 ms is selected.');
$this->assertSession()->pageTextContains('Enter the time, in milliseconds, the banner transition should take to complete.');
// Autoplay is checked by default.
......@@ -178,8 +180,9 @@ class UwWcmsBasicTest extends BrowserTestBase {
foreach ($expected_options as $key => $expected_option) {
$this->assertEquals($options[$key], $expected_option);
}
// Full banner is selected as default.
$this->assertFieldByXPath('//option[@value="full-width" and @selected="selected"]', NULL, 'Full banner width, bottom, theme colour background ("FDSU" style) is selected.');
// Full banner width, bottom, theme colour background
// ("FDSU" style) is selected as default.
$this->assertTrue((bool) $this->xpath('//option[@value="full-width" and @selected="selected"]'), 'Full banner width, bottom, theme colour background ("FDSU" style) is selected as default.');
$this->assertSession()->pageTextContains('Note that all options other than "FDSU" style are unsupported at this time, and are provided for future use.');
// Click 'Add Image banner'.
......@@ -261,7 +264,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->submitForm($edit, 'Save');
// Test for existence Webform CAPTCHA component on newly-created Webform.
$this->assertFieldByXPath('//table[@id="edit-webform-ui-elements"]/tbody/tr[@data-webform-type="captcha"]', NULL, 'CAPTCHA component exists.');
$this->assertTrue((bool) $this->xpath('//table[@id="edit-webform-ui-elements"]/tbody/tr[@data-webform-type="captcha"]'), 'CAPTCHA component exists.');
// Save the access page. If a form is altered by unsetting parts of it
// instead of setting #access, empty access values will be saved leading to
......@@ -515,9 +518,9 @@ class UwWcmsBasicTest extends BrowserTestBase {
}
if ($key === 'event') {
$this->assertFieldByXPath('//select[@id="edit-location-presets-select"]', NULL, 'Location lookup menu exists.');
$this->assertTrue((bool) $this->xpath('//select[@id="edit-location-presets-select"]'), 'Location lookup menu exists.');
// Test field_uw_event_map exists.
$this->assertFieldByXPath('//input[@type="url" and @id="edit-field-uw-event-map-0-uri"]', NULL, 'Map link field exists.');
$this->assertTrue((bool) $this->xpath('//input[@type="url" and @id="edit-field-uw-event-map-0-uri"]'), 'Map link field exists.');
$this->assertSession()->pageTextContains('Optional: provide a link to a map with the event location (e.g. https://uwaterloo.ca/map/)');
}
}
......@@ -1171,7 +1174,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Test that the CodePen block markup appears on the page.
$this->assertSession()->pageTextContains($edit['edit-settings-label']);
$this->assertFieldByXPath('//div[@class="uw-codepen"]/div[
$this->xpath('//div[@class="uw-codepen"]/div[
@class="codepen"
and @data-height="' . $edit['edit-settings-block-form-field-codepen-pixel-height-0-value'] . '"
and @data-theme-id="dark"
......@@ -1181,7 +1184,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
and @data-pen-title="' . $edit['edit-settings-block-form-field-codepen-displayed-title-0-value'] . '"
and @data-preview="true"
]/a[@href="https://codepen.io/' . $edit['edit-settings-block-form-field-codepen-username-0-value'] . '/pen/' . $edit['edit-settings-block-form-field-codepen-id-0-value'] . '/"]');
$this->assertFieldByXPath('//div[@class="uw-codepen"]/script[@src="https://static.codepen.io/assets/embed/ei.js"]');
$this->assertTrue((bool) $this->xpath('//div[@class="uw-codepen"]/script[@src="https://static.codepen.io/assets/embed/ei.js"]'));
break;
case 'Google Maps':
......@@ -1195,8 +1198,8 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Test that the Google Maps block markup appears on the page.
$this->assertSession()->pageTextContains($edit['edit-settings-label']);
$this->assertFieldByXPath('//div[@class="uw-google-maps"]/div[text()="Enable JavaScript to view map."]');
$this->assertFieldByXPath('//div[@class="uw-google-maps"]/iframe[@height="' . $edit['edit-settings-block-form-field-gmaps-height-0-value'] . '" and @src="' . $edit['edit-settings-block-form-field-gmaps-embedded-url-0-uri'] . '"]');
$this->assertTrue((bool) $this->xpath('//div[@class="uw-google-maps"]/div[text()="Enable JavaScript to view map."]'));
$this->assertTrue((bool) $this->xpath('//div[@class="uw-google-maps"]/iframe[@height="' . $edit['edit-settings-block-form-field-gmaps-height-0-value'] . '" and @src="' . $edit['edit-settings-block-form-field-gmaps-embedded-url-0-uri'] . '"]'));
break;
case 'Multi-type list':
......@@ -1214,7 +1217,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Test that the PowerBI block markup appears on the page.
$this->assertSession()->pageTextContains($edit['edit-settings-label']);
$this->assertFieldByXPath('//div[@class="uw-powerbi"]/iframe[@src="' . $edit['edit-settings-block-form-field-uw-powerbi-url-0-value'] . '"]');
$this->assertTrue((bool) $this->xpath('//div[@class="uw-powerbi"]/iframe[@src="' . $edit['edit-settings-block-form-field-uw-powerbi-url-0-value'] . '"]'));
break;
case 'Related links':
......@@ -1239,10 +1242,10 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->assertSession()->pageTextContains($edit['edit-settings-label']);
// Internal link.
$xpath_prefix = '//div[contains(@class, "block-inline-blockuw-cbl-related-links")]/div[@class="item-list"]/ul/li';
$this->assertFieldByXPath($xpath_prefix . '/a[@href="' . base_path() . 'home" and text()="Home"]');
$this->assertTrue((bool) $this->xpath($xpath_prefix . '/a[@href="' . base_path() . 'home" and text()="Home"]'));
$this->assertSession()->pageTextNotContains($edit['edit-settings-block-form-field-uw-rl-related-link-0-title']);
// External link.
$this->assertFieldByXPath($xpath_prefix . '/a[@href="' . $edit['edit-settings-block-form-field-uw-rl-related-link-1-uri'] . '" and text()="' . $edit['edit-settings-block-form-field-uw-rl-related-link-1-title'] . '"]');
$this->assertTrue((bool) $this->xpath($xpath_prefix . '/a[@href="' . $edit['edit-settings-block-form-field-uw-rl-related-link-1-uri'] . '" and text()="' . $edit['edit-settings-block-form-field-uw-rl-related-link-1-title'] . '"]'));
unset($xpath_prefix);
break;
......@@ -1260,11 +1263,11 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Test that the appropriate Tableau block markup appears on the page.
$this->assertSession()->pageTextContains($edit['edit-settings-label']);
$this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="host_url" and @value="https://public.tableau.com/"]');
$this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="site_root" and @value="' . $edit['edit-settings-block-form-field-uw-tbl-site-name-0-value'] . '"]');
$this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="name" and @value="' . $edit['edit-settings-block-form-field-uw-tbl-tableau-name-0-value'] . '"]');
$this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="tabs" and @value="yes"]');
$this->assertFieldByXPath('//div[@class="uw-tableau__wrapper"]/script');
$this->assertTrue((bool) $this->xpath('//object[@class="tableauViz"]/param[@name="host_url" and @value="https://public.tableau.com/"]'));
$this->assertTrue((bool) $this->xpath('//object[@class="tableauViz"]/param[@name="site_root" and @value="' . $edit['edit-settings-block-form-field-uw-tbl-site-name-0-value'] . '"]'));
$this->assertTrue((bool) $this->xpath('//object[@class="tableauViz"]/param[@name="name" and @value="' . $edit['edit-settings-block-form-field-uw-tbl-tableau-name-0-value'] . '"]'));
$this->assertTrue((bool) $this->xpath('//object[@class="tableauViz"]/param[@name="tabs" and @value="yes"]'));
$this->assertTrue((bool) $this->xpath('//div[@class="uw-tableau__wrapper"]/script'));
$this->assertSession()->responseContains("vizElement.style.height = '" . $edit['edit-settings-block-form-field-uw-tbl-tableau-height-0-value'] . "px';");
break;
}
......@@ -1752,7 +1755,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Check 'Default background colour' field help text.
$this->assertSession()->pageTextContains('When gold is selected, the default colour will always be black.');
// Check 'Default background colour' field default value.
$this->assertFieldByXPath('//option[@value="grey" and @selected="selected"]', NULL, 'Grey is selected.');
$this->assertTrue((bool) $this->xpath('//option[@value="grey" and @selected="selected"]'));
$this->assertSession()->fieldExists('settings[block_form][field_uw_ff_fact_figure][0][subform][field_uw_ff_def_color]');
// Select 'gold', then 'Default background colour' field is gone.
$this->getSession()->getPage()->selectFieldOption('settings[block_form][field_uw_ff_fact_figure][0][subform][field_uw_ff_dbg_color]', 'gold');
......@@ -1765,7 +1768,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
foreach ($options as $option) {
$this->assertNotEquals('- None -', $option);
}
$this->assertFieldByXPath('//option[@value="org-default" and @selected="selected"]', NULL, 'Default uWaterloo is selected.');
$this->assertTrue((bool) $this->xpath('//option[@value="org-default" and @selected="selected"]'));
// The type includes 'Small highlight' with value 'small'.
$smallhighlight = $this->assertSession()->optionExists('settings[block_form][field_uw_ff_fact_figure][0][subform][field_uw_fact_figure][0][subform][field_uw_ff_info][0][style]', 'small');
$this->assertTrue((bool) $smallhighlight);
......@@ -1988,8 +1991,8 @@ class UwWcmsBasicTest extends BrowserTestBase {
// Two required field (First name and Last name) in 'Add user' page.
$this->drupalGet('admin/people/create');
$this->assertSession()->statusCodeEquals(200);
$this->assertFieldByXPath('//input[@type="text" and @id="edit-field-uw-first-name-0-value" and @required=true()]', NULL, 'Required first name.');
$this->assertFieldByXPath('//input[@type="text" and @id="edit-field-uw-last-name-0-value" and @required=true()]', NULL, 'Required last name.');
$this->assertTrue((bool) $this->xpath('//input[@type="text" and @id="edit-field-uw-first-name-0-value" and @required=true()]'));
$this->assertTrue((bool) $this->xpath('//input[@type="text" and @id="edit-field-uw-last-name-0-value" and @required=true()]'));
// Admin has "Manage" toolbar item.
$this->assertSession()->elementExists('css', '#toolbar-item-administration');
......@@ -2144,7 +2147,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('Contacts');
$this->assertSession()->pageTextContains('Name');
$this->assertSession()->pageTextContains('Limit to contacts where the name matches');
$this->assertFieldByXPath('//input[@type="text" and @id="edit-title"]', NULL, 'Input field exists.');
$this->assertTrue((bool) $this->xpath('//input[@type="text" and @id="edit-title"]'));
$this->assertSession()->pageTextContains('Groups');
$this->assertSession()->pageTextContains('Limit to contacts where the group is one or more of');
$this->assertSession()->buttonExists('Apply filters');
......@@ -2261,7 +2264,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
// $this->assertSession()->pageTextContains('Profiles');
// $this->assertSession()->pageTextContains('Name');
// $this->assertSession()->pageTextContains('Limit to profiles where the name matches');
// $this->assertFieldByXPath('//input[@type="text" and @id="edit-title"]', NULL, 'Input field exists.');
// $this->assertTrue((bool) $this->xpath('//input[@type="text" and @id="edit-title"]'));
// $this->assertSession()->pageTextContains('Types');
// $this->assertSession()->pageTextContains('Limit to profiles where the type is one or more of');
// $this->assertSession()->buttonExists('Apply filters');
......
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