mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #118 from open-sausages/pulls/4.0/namespace-security
API Apply SilverStripe\Security namespace
This commit is contained in:
commit
b6ee213de7
@ -10,6 +10,8 @@ use Behat\Behat\Context\BehatContext,
|
|||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\Versioning\Versioned;
|
use SilverStripe\ORM\Versioning\Versioned;
|
||||||
|
use SilverStripe\Security\Permission;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// PHPUnit
|
// PHPUnit
|
||||||
@ -379,10 +381,10 @@ class FixtureContext extends BehatContext
|
|||||||
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)"$/
|
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)"$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateMemberWithGroup($id, $groupId) {
|
public function stepCreateMemberWithGroup($id, $groupId) {
|
||||||
$group = $this->fixtureFactory->get('Group', $groupId);
|
$group = $this->fixtureFactory->get('SilverStripe\\Security\\Group', $groupId);
|
||||||
if(!$group) $group = $this->fixtureFactory->createObject('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);
|
$member->Groups()->add($group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,7 +394,7 @@ class FixtureContext extends BehatContext
|
|||||||
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)" with (?<data>.*)$/
|
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)" with (?<data>.*)$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateMemberWithGroupAndData($id, $groupId, $data) {
|
public function stepCreateMemberWithGroupAndData($id, $groupId, $data) {
|
||||||
$class = 'Member';
|
$class = 'SilverStripe\\Security\\Member';
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
||||||
$data,
|
$data,
|
||||||
@ -403,8 +405,8 @@ class FixtureContext extends BehatContext
|
|||||||
array_combine($matches['key'], $matches['value'])
|
array_combine($matches['key'], $matches['value'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$group = $this->fixtureFactory->get('Group', $groupId);
|
$group = $this->fixtureFactory->get('SilverStripe\\Security\\Group', $groupId);
|
||||||
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
|
if(!$group) $group = $this->fixtureFactory->createObject('SilverStripe\\Security\\Group', $groupId);
|
||||||
|
|
||||||
$member = $this->fixtureFactory->createObject($class, $id, $fields);
|
$member = $this->fixtureFactory->createObject($class, $id, $fields);
|
||||||
$member->Groups()->add($group);
|
$member->Groups()->add($group);
|
||||||
@ -419,10 +421,10 @@ class FixtureContext extends BehatContext
|
|||||||
// Convert natural language permissions to codes
|
// Convert natural language permissions to codes
|
||||||
preg_match_all('/"([^"]+)"/', $permissionStr, $matches);
|
preg_match_all('/"([^"]+)"/', $permissionStr, $matches);
|
||||||
$permissions = $matches[1];
|
$permissions = $matches[1];
|
||||||
$codes = \Permission::get_codes(false);
|
$codes = Permission::get_codes(false);
|
||||||
|
|
||||||
$group = $this->fixtureFactory->get('Group', $id);
|
$group = $this->fixtureFactory->get('SilverStripe\\Security\\Group', $id);
|
||||||
if(!$group) $group = $this->fixtureFactory->createObject('Group', $id);
|
if(!$group) $group = $this->fixtureFactory->createObject('SilverStripe\\Security\\Group', $id);
|
||||||
|
|
||||||
foreach($permissions as $permission) {
|
foreach($permissions as $permission) {
|
||||||
$found = false;
|
$found = false;
|
||||||
@ -431,7 +433,7 @@ class FixtureContext extends BehatContext
|
|||||||
$permission == $code
|
$permission == $code
|
||||||
|| $permission == $details['name']
|
|| $permission == $details['name']
|
||||||
) {
|
) {
|
||||||
\Permission::grant($group->ID, $code);
|
Permission::grant($group->ID, $code);
|
||||||
$found = true;
|
$found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace SilverStripe\BehatExtension\Context;
|
namespace SilverStripe\BehatExtension\Context;
|
||||||
|
|
||||||
use Behat\Behat\Context\ClosuredContextInterface,
|
use Behat\Behat\Context\BehatContext;
|
||||||
Behat\Behat\Context\TranslatedContextInterface,
|
use Behat\Behat\Context\Step;
|
||||||
Behat\Behat\Context\BehatContext,
|
|
||||||
Behat\Behat\Context\Step,
|
|
||||||
Behat\Behat\Exception\PendingException;
|
|
||||||
use Behat\Gherkin\Node\PyStringNode,
|
|
||||||
Behat\Gherkin\Node\TableNode;
|
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\Security\Group;
|
||||||
|
use SilverStripe\Security\Member;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// PHPUnit
|
// PHPUnit
|
||||||
@ -75,27 +73,27 @@ class LoginContext extends BehatContext
|
|||||||
function iAmLoggedInWithPermissions($permCode)
|
function iAmLoggedInWithPermissions($permCode)
|
||||||
{
|
{
|
||||||
if (!isset($this->cache_generatedMembers[$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) {
|
if (!$group) {
|
||||||
$group = \Injector::inst()->create('Group');
|
$group = \Injector::inst()->create('SilverStripe\\Security\\Group');
|
||||||
}
|
}
|
||||||
|
|
||||||
$group->Title = "$permCode group";
|
$group->Title = "$permCode group";
|
||||||
$group->write();
|
$group->write();
|
||||||
|
|
||||||
$permission = \Injector::inst()->create('Permission');
|
$permission = \Injector::inst()->create('SilverStripe\\Security\\Permission');
|
||||||
$permission->Code = $permCode;
|
$permission->Code = $permCode;
|
||||||
$permission->write();
|
$permission->write();
|
||||||
$group->Permissions()->add($permission);
|
$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) {
|
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
|
// make sure any validation for password is skipped, since we're not testing complexity here
|
||||||
$validator = \Member::password_validator();
|
$validator = Member::password_validator();
|
||||||
\Member::set_password_validator(null);
|
Member::set_password_validator(null);
|
||||||
$member->FirstName = $permCode;
|
$member->FirstName = $permCode;
|
||||||
$member->Surname = "User";
|
$member->Surname = "User";
|
||||||
$member->Email = "$permCode@example.org";
|
$member->Email = "$permCode@example.org";
|
||||||
@ -103,7 +101,7 @@ class LoginContext extends BehatContext
|
|||||||
$member->changePassword('Secret!123');
|
$member->changePassword('Secret!123');
|
||||||
$member->write();
|
$member->write();
|
||||||
$group->Members()->add($member);
|
$group->Members()->add($member);
|
||||||
\Member::set_password_validator($validator);
|
Member::set_password_validator($validator);
|
||||||
|
|
||||||
$this->cache_generatedMembers[$permCode] = $member;
|
$this->cache_generatedMembers[$permCode] = $member;
|
||||||
}
|
}
|
||||||
@ -183,7 +181,7 @@ class LoginContext extends BehatContext
|
|||||||
*/
|
*/
|
||||||
public function stepPasswordForEmailShouldBe($id, $password)
|
public function stepPasswordForEmailShouldBe($id, $password)
|
||||||
{
|
{
|
||||||
$member = \Member::get()->filter('Email', $id)->First();
|
$member = Member::get()->filter('Email', $id)->First();
|
||||||
assertNotNull($member);
|
assertNotNull($member);
|
||||||
assertTrue($member->checkPassword($password)->valid());
|
assertTrue($member->checkPassword($password)->valid());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user