mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
Merge pull request #122 from creative-commoners/pulls/4/review-behat-tests
ENH Extracting logic for canX from Company and Employee
This commit is contained in:
commit
da63f28e71
@ -8,6 +8,13 @@ SilverStripe\Assets\File:
|
|||||||
extensions:
|
extensions:
|
||||||
- BasicFieldsTestFileExtension
|
- BasicFieldsTestFileExtension
|
||||||
|
|
||||||
|
SilverStripe\FrameworkTest\Model\Company:
|
||||||
|
extensions:
|
||||||
|
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
|
||||||
|
SilverStripe\FrameworkTest\Model\Employee:
|
||||||
|
extensions:
|
||||||
|
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
|
||||||
|
|
||||||
---
|
---
|
||||||
Only:
|
Only:
|
||||||
moduleexists: 'dnadesign/silverstripe-elemental'
|
moduleexists: 'dnadesign/silverstripe-elemental'
|
||||||
|
@ -13,8 +13,6 @@ use SilverStripe\Versioned\RecursivePublishable;
|
|||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use RelationFieldsTestPage;
|
use RelationFieldsTestPage;
|
||||||
use GridFieldTestPage;
|
use GridFieldTestPage;
|
||||||
use SilverStripe\Security\Permission;
|
|
||||||
use SilverStripe\Security\PermissionProvider;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -33,7 +31,7 @@ use SilverStripe\Security\PermissionProvider;
|
|||||||
* @mixin Versioned
|
* @mixin Versioned
|
||||||
* @mixin RecursivePublishable
|
* @mixin RecursivePublishable
|
||||||
*/
|
*/
|
||||||
class Company extends DataObject implements PermissionProvider
|
class Company extends DataObject
|
||||||
{
|
{
|
||||||
private static $table_name = 'Company';
|
private static $table_name = 'Company';
|
||||||
|
|
||||||
@ -373,40 +371,4 @@ class Company extends DataObject implements PermissionProvider
|
|||||||
return DropdownField::create('CompanyID', 'Company', self::get()->map())->setEmptyString('');
|
return DropdownField::create('CompanyID', 'Company', self::get()->map())->setEmptyString('');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providePermissions()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'COMPANY_EDIT' => [
|
|
||||||
'name' => _t(
|
|
||||||
__CLASS__ . '.EditPermissionLabel',
|
|
||||||
'Edit a company'
|
|
||||||
),
|
|
||||||
'category' => _t(
|
|
||||||
__CLASS__ . '.Category',
|
|
||||||
'Company'
|
|
||||||
),
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canView($member = null)
|
|
||||||
{
|
|
||||||
return Permission::check('COMPANY_EDIT', 'any', $member);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canEdit($member = null)
|
|
||||||
{
|
|
||||||
return Permission::check('COMPANY_EDIT', 'any', $member);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canDelete($member = null)
|
|
||||||
{
|
|
||||||
return Permission::check('COMPANY_EDIT', 'any', $member);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canCreate($member = null, $context = [])
|
|
||||||
{
|
|
||||||
return Permission::check('COMPANY_EDIT', 'any', $member);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
code/TestDataObjectExtension.php
Normal file
46
code/TestDataObjectExtension.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\FrameworkTest\Extension;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataExtension;
|
||||||
|
use SilverStripe\Security\Permission;
|
||||||
|
use SilverStripe\Security\PermissionProvider;
|
||||||
|
|
||||||
|
class TestDataObjectExtension extends DataExtension implements PermissionProvider
|
||||||
|
{
|
||||||
|
public function providePermissions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'TEST_DATAOBJECT_EDIT' => [
|
||||||
|
'name' => _t(
|
||||||
|
__CLASS__ . '.EditPermissionLabel',
|
||||||
|
'Manage a test object'
|
||||||
|
),
|
||||||
|
'category' => _t(
|
||||||
|
__CLASS__ . '.Category',
|
||||||
|
'Test Data Object'
|
||||||
|
),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canView($member = null)
|
||||||
|
{
|
||||||
|
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canEdit($member = null)
|
||||||
|
{
|
||||||
|
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canDelete($member = null)
|
||||||
|
{
|
||||||
|
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canCreate($member = null, $context = [])
|
||||||
|
{
|
||||||
|
return Permission::check('TEST_DATAOBJECT_EDIT', 'any', $member);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user