API Apply SilverStripe\Security namespace

This commit is contained in:
Damian Mooyman 2016-06-29 10:31:00 +12:00
parent 26a95a895f
commit 8d6de532df
2 changed files with 26 additions and 26 deletions

View File

@ -10,6 +10,8 @@ use Behat\Behat\Context\BehatContext,
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Security\Permission;
// PHPUnit
@ -379,10 +381,10 @@ class FixtureContext extends BehatContext
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)"$/
*/
public function stepCreateMemberWithGroup($id, $groupId) {
$group = $this->fixtureFactory->get('Group', $groupId);
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
$group = $this->fixtureFactory->get('SilverStripe\\Security\\Group', $groupId);
if(!$group) $group = $this->fixtureFactory->createObject('SilverStripe\\Security\\Group', $groupId);
$member = $this->fixtureFactory->createObject('Member', $id);
$member = $this->fixtureFactory->createObject('SilverStripe\\Security\\Member', $id);
$member->Groups()->add($group);
}
@ -392,7 +394,7 @@ class FixtureContext extends BehatContext
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)" with (?<data>.*)$/
*/
public function stepCreateMemberWithGroupAndData($id, $groupId, $data) {
$class = 'Member';
$class = 'SilverStripe\\Security\\Member';
preg_match_all(
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
$data,
@ -403,8 +405,8 @@ class FixtureContext extends BehatContext
array_combine($matches['key'], $matches['value'])
);
$group = $this->fixtureFactory->get('Group', $groupId);
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
$group = $this->fixtureFactory->get('SilverStripe\\Security\\Group', $groupId);
if(!$group) $group = $this->fixtureFactory->createObject('SilverStripe\\Security\\Group', $groupId);
$member = $this->fixtureFactory->createObject($class, $id, $fields);
$member->Groups()->add($group);
@ -419,10 +421,10 @@ class FixtureContext extends BehatContext
// Convert natural language permissions to codes
preg_match_all('/"([^"]+)"/', $permissionStr, $matches);
$permissions = $matches[1];
$codes = \Permission::get_codes(false);
$codes = Permission::get_codes(false);
$group = $this->fixtureFactory->get('Group', $id);
if(!$group) $group = $this->fixtureFactory->createObject('Group', $id);
$group = $this->fixtureFactory->get('SilverStripe\\Security\\Group', $id);
if(!$group) $group = $this->fixtureFactory->createObject('SilverStripe\\Security\\Group', $id);
foreach($permissions as $permission) {
$found = false;
@ -431,7 +433,7 @@ class FixtureContext extends BehatContext
$permission == $code
|| $permission == $details['name']
) {
\Permission::grant($group->ID, $code);
Permission::grant($group->ID, $code);
$found = true;
}
}

View File

@ -2,14 +2,12 @@
namespace SilverStripe\BehatExtension\Context;
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\Behat\Context\BehatContext;
use Behat\Behat\Context\Step;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Group;
use SilverStripe\Security\Member;
// PHPUnit
@ -75,27 +73,27 @@ class LoginContext extends BehatContext
function iAmLoggedInWithPermissions($permCode)
{
if (!isset($this->cache_generatedMembers[$permCode])) {
$group = \Group::get()->filter('Title', "$permCode group")->first();
$group = Group::get()->filter('Title', "$permCode group")->first();
if (!$group) {
$group = \Injector::inst()->create('Group');
$group = \Injector::inst()->create('SilverStripe\\Security\\Group');
}
$group->Title = "$permCode group";
$group->write();
$permission = \Injector::inst()->create('Permission');
$permission = \Injector::inst()->create('SilverStripe\\Security\\Permission');
$permission->Code = $permCode;
$permission->write();
$group->Permissions()->add($permission);
$member = DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
$member = DataObject::get_one('SilverStripe\\Security\\Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
if (!$member) {
$member = \Injector::inst()->create('Member');
$member = \Injector::inst()->create('SilverStripe\\Security\\Member');
}
// make sure any validation for password is skipped, since we're not testing complexity here
$validator = \Member::password_validator();
\Member::set_password_validator(null);
$validator = Member::password_validator();
Member::set_password_validator(null);
$member->FirstName = $permCode;
$member->Surname = "User";
$member->Email = "$permCode@example.org";
@ -103,7 +101,7 @@ class LoginContext extends BehatContext
$member->changePassword('Secret!123');
$member->write();
$group->Members()->add($member);
\Member::set_password_validator($validator);
Member::set_password_validator($validator);
$this->cache_generatedMembers[$permCode] = $member;
}
@ -183,7 +181,7 @@ class LoginContext extends BehatContext
*/
public function stepPasswordForEmailShouldBe($id, $password)
{
$member = \Member::get()->filter('Email', $id)->First();
$member = Member::get()->filter('Email', $id)->First();
assertNotNull($member);
assertTrue($member->checkPassword($password)->valid());
}