/** * @Then I should see the expires header to a value in the future */ public function iShouldSeeTheExpiresHeaderToAValueInTheFuture() { $rawExpires = $this->getSession()->getResponseHeader('expires'); assertNotNull($rawExpires, 'I\'m not able to find an expires header!'); $expires = DateTime::createFromFormat(DateTime::RFC1123, $rawExpires); assertGreaterThan((new DateTime())->setTimezone(new DateTimeZone('GMT')), $expires, 'The expires header is not set on the future'); }
public function cmp_ok($exp1, $op, $exp2, $message = '') { switch ($op) { case '==': case '===': assertEquals($exp2, $exp1); break; case '!=': case '!==': assertNotEquals($exp2, $exp1); break; case '>': assertGreaterThan($exp2, $exp1); break; case '<': assertLessThan($exp2, $exp1); break; case '>=': assertGreaterThanOrEqual($exp2, $exp1); break; case '<=': assertLessThanOrEqual($exp2, $exp1); break; } }
/** * @Then /^I should get these and more:$/ */ public function iShouldGetTheseAndMore(TableNode $table) { foreach ($table->getHash() as $row) { assertArrayHasKey($row['lang'], $this->languages, 'Language ' . $row['lang'] . ' must be among available languages.'); assertEquals($row['title'], $this->languages[$row['lang']]); } foreach ($this->languages as $code => $title) { assertNotEmpty($title); } assertGreaterThan(10, count($this->languages), 'There are missing languages for sure!'); }
/** * Workaround for chosen.js dropdowns or tree dropdowns which hide the original dropdown field. * * @When /^(?:|I )fill in the "(?P<field>(?:[^"]|\\")*)" dropdown with "(?P<value>(?:[^"]|\\")*)"$/ * @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for the "(?P<field>(?:[^"]|\\")*)" dropdown$/ */ public function theIFillInTheDropdownWith($field, $value) { $field = $this->fixStepArgument($field); $value = $this->fixStepArgument($value); $nativeField = $this->getSession()->getPage()->find('named', array('select', $this->getSession()->getSelectorsHandler()->xpathLiteral($field))); if ($nativeField && $nativeField->isVisible()) { $nativeField->selectOption($value); return; } // Given the fuzzy matching, we might get more than one matching field. $formFields = array(); // Find by label $formField = $this->getSession()->getPage()->findField($field); if ($formField && $formField->getTagName() == 'select') { $formFields[] = $formField; } // Fall back to finding by title (for dropdowns without a label) if (!$formFields) { $formFields = $this->getSession()->getPage()->findAll('xpath', sprintf('//*[self::select][(./@title="%s")]', $field)); } // Find by name (incl. hidden fields) if (!$formFields) { $formFields = $this->getSession()->getPage()->findAll('xpath', "//*[@name='{$field}']"); } // Find by label if (!$formFields) { $label = $this->getSession()->getPage()->find('xpath', "//label[.='{$field}']"); if ($label && ($for = $label->getAttribute('for'))) { $formField = $this->getSession()->getPage()->find('xpath', "//*[@id='{$for}']"); if ($formField) { $formFields[] = $formField; } } } assertGreaterThan(0, count($formFields), sprintf('Chosen.js dropdown named "%s" not found', $field)); // Traverse up to field holder $container = null; foreach ($formFields as $formField) { $container = $this->findParentByClass($formField, 'field'); if ($container) { break; } // Default to first visible container } assertNotNull($container, 'Chosen.js field container not found'); // Click on newly expanded list element, indirectly setting the dropdown value $linkEl = $container->find('xpath', './/a[./@href]'); assertNotNull($linkEl, 'Chosen.js link element not found'); $this->getSession()->wait(100); // wait for dropdown overlay to appear $linkEl->click(); if (in_array('treedropdown', explode(' ', $container->getAttribute('class')))) { // wait for ajax dropdown to load $this->getSession()->wait(5000, "window.jQuery && " . "window.jQuery('#" . $container->getAttribute('id') . " .treedropdownfield-panel li').length > 0"); } else { // wait for dropdown overlay to appear (might be animated) $this->getSession()->wait(300); } $listEl = $container->find('xpath', sprintf('.//li[contains(normalize-space(string(.)), \'%s\')]', $value)); if (null === $listEl) { throw new \InvalidArgumentException(sprintf('Chosen.js list element with title "%s" not found', $value)); } $listLinkEl = $listEl->find('xpath', './/a'); if ($listLinkEl) { $listLinkEl->click(); } else { $listEl->click(); } }
/** * Asserts that we have more than a minute interval between the product updated date and the argument * * @Then /^the (product "([^"]+)") updated date should not be close to "([^"]+)"$/ */ public function theProductUpdatedDateShouldNotBeCloseTo(ProductInterface $product, $identifier, $expected) { assertGreaterThan(60, abs(strtotime($expected) - $product->getUpdated()->getTimestamp())); }
/** * @Given /^I select "([^"]*)" in the "([^"]*)" dropdown$/ */ public function iSelectInTheDropdown($dropdown_option, $dropdown_label) { $dropdown_id = ''; if (strpos($dropdown_label, 'CiviMember Membership Type') !== false) { $dropdown_id = 'civi_member_type'; } elseif (strpos($dropdown_label, 'Select a Wordpress Role') !== false) { $dropdown_id = 'wp_role'; } elseif (strpos($dropdown_label, 'Wordpress Expiry Role') !== false) { $dropdown_id = 'expire_assign_wp_role'; } $value = ''; $dropdown = $this->session->getPage()->findById($dropdown_id); $dropdown_list = $dropdown->getParent()->findAll('xpath', "select[@id='" . $dropdown_id . "']/option[@value != '']"); //$dropdown->selectOption( $dropdown_option ); assertGreaterThan(1, count($dropdown_list), 'can not find the dropdown options!'); foreach ($dropdown_list as $item) { //find which option matches $dropdown_option //get that option if ($item->getText() == $dropdown_option) { //get the value for that option //$html = $item->getHtml(); $value = $item->getAttribute('value'); $dropdown->setValue($value); } } assertEquals($dropdown->getValue(), $value, 'The ' . $dropdown_id . ' dropdown was not properly set to ' . $dropdown_option); }
/** * @Then /^I should get at least one results$/ */ public function iShouldGetAtLeastOneResults() { assertGreaterThan(0, $this->_results->count); }
/** * @Then Assert the value :arg1 is greater than :arg2 * @param $expected * @param $actual */ public function assertGreaterThan($actual, $expected) { assertGreaterThan($expected, $actual, sprintf("Assert the value [%s] is greater than [%s]", $actual, $expected)); }