mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
"go to <named record>" behat step definition
This commit is contained in:
parent
e94d6e35f6
commit
a244986495
@ -358,6 +358,29 @@ class FixtureContext extends BehatContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigates to a record based on its identifier set during fixture creation,
|
||||||
|
* using its RelativeLink() method to map the record to a URL.
|
||||||
|
* Example: Given I go to the "page" "My Page"
|
||||||
|
*
|
||||||
|
* @Given /^I go to (?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"/
|
||||||
|
*/
|
||||||
|
public function stepGoToNamedRecord($type, $id) {
|
||||||
|
$class = $this->convertTypeToClass($type);
|
||||||
|
$record = $this->fixtureFactory->get($class, $id);
|
||||||
|
if(!$record) {
|
||||||
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
'Cannot resolve reference "%s", no matching fixture found',
|
||||||
|
$id
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if(!$record->hasMethod('RelativeLink')) {
|
||||||
|
throw new \InvalidArgumentException('URL for record cannot be determined, missing RelativeLink() method');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getSession()->visit($this->getMainContext()->locatePath($record->RelativeLink()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces fixture references in values with their respective database IDs,
|
* Replaces fixture references in values with their respective database IDs,
|
||||||
* with the notation "=><class>.<identifier>". Example: "=>Page.My Page".
|
* with the notation "=><class>.<identifier>". Example: "=>Page.My Page".
|
||||||
|
Loading…
Reference in New Issue
Block a user