mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-06-17 10:11:43 +02:00
Merge f00a1b4aa5
into 8bb5ff5a1f
This commit is contained in:
commit
3a75b6f1dc
|
@ -719,6 +719,12 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||
Then /^the email should (not |)contain the following data:$/
|
||||
Example: Then the email should contain the following data:
|
||||
|
||||
Then /^there should (not |)be an email titled "([^"]*)"$/
|
||||
|
||||
Then /^the email should (not |)be sent from "([^"]*)"$/
|
||||
|
||||
Then /^the email should (not |)be sent to "([^"]*)"$/
|
||||
|
||||
### Transformations
|
||||
|
||||
Behat [transformations](http://docs.behat.org/guides/2.definitions.html#step-argument-transformations)
|
||||
|
|
|
@ -398,6 +398,27 @@ JS;
|
|||
$clickTypeFn = $clickTypeMap[$clickType];
|
||||
$element->$clickTypeFn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
|
||||
* Example: I click "Delete" in the ".actions" element, confirming the dialog
|
||||
*
|
||||
* @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, confirming the dialog$/
|
||||
*/
|
||||
public function iClickInTheElementConfirmingTheDialog($clickType, $text, $selector) {
|
||||
$this->iClickInTheElement($clickType, $text, $selector);
|
||||
$this->iConfirmTheDialog();
|
||||
}
|
||||
/**
|
||||
* Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
|
||||
* Example: I click "Delete" in the ".actions" element, dismissing the dialog
|
||||
*
|
||||
* @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, dismissing the dialog$/
|
||||
*/
|
||||
public function iClickInTheElementDismissingTheDialog($clickType, $text, $selector) {
|
||||
$this->iClickInTheElement($clickType, $text, $selector);
|
||||
$this->iDismissTheDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
|
||||
|
|
|
@ -134,6 +134,28 @@ class EmailContext extends BehatContext
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Given the email contains "Thank you for <strong>registering!<strong>".
|
||||
* Then the email should contain plain text "Thank you for registering!"
|
||||
* Assumes an email has been identified by a previous step,
|
||||
* e.g. through 'Given there should be an email to "test@test.com"'.
|
||||
*
|
||||
* @Given /^the email should contain plain text "([^"]*)"$/
|
||||
*/
|
||||
public function thereTheEmailContainsPlainText($content)
|
||||
{
|
||||
if(!$this->lastMatchedEmail) {
|
||||
throw new \LogicException('No matched email found from previous step');
|
||||
}
|
||||
|
||||
$email = $this->lastMatchedEmail;
|
||||
$emailContent = ($email->Content) ? ($email->Content) : ($email->PlainContent);
|
||||
$emailPlainText = strip_tags($emailContent);
|
||||
$emailPlainText = preg_replace("/\h+/", " ", $emailPlainText);
|
||||
|
||||
assertContains($content, $emailPlainText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/
|
||||
*/
|
||||
|
@ -223,6 +245,7 @@ class EmailContext extends BehatContext
|
|||
}
|
||||
// Convert html content to plain text
|
||||
$emailContent = strip_tags($emailContent);
|
||||
$emailContent = preg_replace("/\h+/", " ", $emailContent);
|
||||
$rows = $table->getRows();
|
||||
|
||||
// For "should not contain"
|
||||
|
@ -236,4 +259,56 @@ class EmailContext extends BehatContext
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^there should (not |)be an email titled "([^"]*)"$/
|
||||
*/
|
||||
public function thereIsAnEmailTitled($negate, $subject)
|
||||
{
|
||||
$match = $this->mailer->findEmail(null, null, $subject);
|
||||
if(trim($negate)) {
|
||||
assertNull($match);
|
||||
} else {
|
||||
$msg = sprintf(
|
||||
'Could not find email titled "%s".',
|
||||
$subject
|
||||
);
|
||||
assertNotNull($match,$msg);
|
||||
}
|
||||
$this->lastMatchedEmail = $match;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the email should (not |)be sent from "([^"]*)"$/
|
||||
*/
|
||||
public function theEmailSentFrom($negate, $from)
|
||||
{
|
||||
if(!$this->lastMatchedEmail) {
|
||||
throw new \LogicException('No matched email found from previous step');
|
||||
}
|
||||
|
||||
$match = $this->lastMatchedEmail;
|
||||
if(trim($negate)) {
|
||||
assertNotContains($from, $match->From);
|
||||
} else {
|
||||
assertContains($from, $match->From);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the email should (not |)be sent to "([^"]*)"$/
|
||||
*/
|
||||
public function theEmailSentTo($negate, $to)
|
||||
{
|
||||
if(!$this->lastMatchedEmail) {
|
||||
throw new \LogicException('No matched email found from previous step');
|
||||
}
|
||||
|
||||
$match = $this->lastMatchedEmail;
|
||||
if(trim($negate)) {
|
||||
assertNotContains($to, $match->To);
|
||||
} else {
|
||||
assertContains($to, $match->To);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -553,8 +553,10 @@ class FixtureContext extends BehatContext
|
|||
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
|
||||
|
||||
// Create file or folder on filesystem
|
||||
$parent = \Folder::find_or_make(dirname($relativeTargetPath));
|
||||
if($class == 'Folder' || is_subclass_of($class, 'Folder')) {
|
||||
$parent = \Folder::find_or_make($relativeTargetPath);
|
||||
$targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath);
|
||||
$data['ID'] = $parent->ID;
|
||||
} else {
|
||||
if(!file_exists($sourcePath)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
|
@ -563,12 +565,27 @@ class FixtureContext extends BehatContext
|
|||
$sourcePath
|
||||
));
|
||||
}
|
||||
$parent = \Folder::find_or_make(dirname($relativeTargetPath));
|
||||
copy($sourcePath, $targetPath);
|
||||
$data['ParentID'] = $parent->ID;
|
||||
|
||||
// Load file into APL and retrieve tuple
|
||||
$asset = $this->getAssetStore()->setFromLocalFile(
|
||||
$sourcePath,
|
||||
$relativeTargetPath,
|
||||
null,
|
||||
null,
|
||||
AssetStore::CONFLICT_OVERWRITE
|
||||
);
|
||||
$data['FileFilename'] = $asset['Filename'];
|
||||
$data['FileHash'] = $asset['Hash'];
|
||||
$data['FileVariant'] = $asset['Variant'];
|
||||
|
||||
// Strip base from url to get dir relative to base
|
||||
$url = $this->getAssetStore()->getAsURL($asset['Filename'], $asset['Hash'], $asset['Variant']);
|
||||
$targetPath = $this->joinPaths(BASE_PATH, substr($url, strlen(\Director::baseURL())));
|
||||
}
|
||||
if(!isset($data['Name'])) {
|
||||
$data['Name'] = basename($relativeTargetPath);
|
||||
}
|
||||
$data['Filename'] = $this->joinPaths(ASSETS_DIR, $relativeTargetPath);
|
||||
if(!isset($data['Name'])) $data['Name'] = basename($relativeTargetPath);
|
||||
if($parent) $data['ParentID'] = $parent->ID;
|
||||
|
||||
$this->createdFilesPaths[] = $targetPath;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user