2013-06-05 13:28:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Cms\Test\Behaviour;
|
|
|
|
|
|
|
|
use Behat\Behat\Context\ClosuredContextInterface,
|
2013-11-15 11:44:56 +01:00
|
|
|
Behat\Behat\Context\TranslatedContextInterface,
|
|
|
|
Behat\Behat\Context\BehatContext,
|
|
|
|
Behat\Behat\Context\Step,
|
|
|
|
Behat\Behat\Event\StepEvent,
|
|
|
|
Behat\Behat\Exception\PendingException,
|
|
|
|
Behat\Mink\Driver\Selenium2Driver,
|
|
|
|
Behat\Gherkin\Node\PyStringNode,
|
|
|
|
Behat\Gherkin\Node\TableNode;
|
2013-06-05 13:28:57 +02:00
|
|
|
|
|
|
|
// PHPUnit
|
|
|
|
require_once 'PHPUnit/Autoload.php';
|
|
|
|
require_once 'PHPUnit/Framework/Assert/Functions.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context used to create fixtures in the SilverStripe ORM.
|
|
|
|
*/
|
2013-11-15 11:44:56 +01:00
|
|
|
class FixtureContext extends \SilverStripe\BehatExtension\Context\FixtureContext {
|
2013-06-05 13:28:57 +02:00
|
|
|
|
2013-11-29 04:44:22 +01:00
|
|
|
/**
|
2013-11-15 11:44:56 +01:00
|
|
|
* Find or create a redirector page and link to another existing page.
|
|
|
|
* Example: Given a "page" "My Redirect" which redirects to a "page" "Page 1"
|
|
|
|
*
|
|
|
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?<targetType>[^"]+)" "(?<targetId>[^"]+)"$/
|
|
|
|
*/
|
|
|
|
public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) {
|
|
|
|
$class = 'RedirectorPage';
|
|
|
|
$targetClass = $this->convertTypeToClass($targetType);
|
2013-11-29 04:44:22 +01:00
|
|
|
|
2013-11-15 11:44:56 +01:00
|
|
|
$targetObj = $this->fixtureFactory->get($targetClass, $targetId);
|
2013-11-29 04:44:22 +01:00
|
|
|
if (!$targetObj) $targetObj = $this->fixtureFactory->get($targetClass, $targetId);
|
|
|
|
|
2013-11-15 11:44:56 +01:00
|
|
|
$fields = array('LinkToID' => $targetObj->ID);
|
|
|
|
$obj = $this->fixtureFactory->get($class, $id);
|
2013-11-29 04:44:22 +01:00
|
|
|
if ($obj) {
|
2013-11-15 11:44:56 +01:00
|
|
|
$obj->update($fields);
|
|
|
|
} else {
|
|
|
|
$obj = $this->fixtureFactory->createObject($class, $id, $fields);
|
|
|
|
}
|
|
|
|
$obj->write();
|
|
|
|
$obj->publish('Stage', 'Live');
|
|
|
|
}
|
2013-11-29 04:44:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check if the user can edit a page
|
|
|
|
*
|
|
|
|
* Example: Then pages should be editable by "Admin"
|
|
|
|
* Then pages should not be editable by "Admin"
|
|
|
|
*
|
|
|
|
* @Then /^pages should( not? |\s*)be editable by "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function pagesShouldBeEditableBy($negative, $member){
|
|
|
|
$edit = '"/admin/pages/edit"';
|
|
|
|
$editable = 'I should'.$negative.'see an edit page form';
|
|
|
|
|
|
|
|
return array(
|
|
|
|
new Step\Given('I am not logged in'),
|
|
|
|
new Step\Given('I am logged in with "'.$member.'" permissions'),
|
|
|
|
new Step\Given('I go to '.$edit),
|
|
|
|
new Step\Given($editable),
|
|
|
|
new Step\Then('I am on the homepage')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|