Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
AccessGroupAnd example
/** * @covers \Drupal\block_content\Access\AccessGroupAnd */
public
function
testGroups
(
)
{
$allowedAccessible
=
$this
->
createAccessibleDouble
(
AccessResult::
allowed
(
)
)
;
$forbiddenAccessible
=
$this
->
createAccessibleDouble
(
AccessResult::
forbidden
(
)
)
;
$neutralAccessible
=
$this
->
createAccessibleDouble
(
AccessResult::
neutral
(
)
)
;
// Ensure that groups with no dependencies return a neutral access result.
$this
->
assertTrue
(
(
new
AccessGroupAnd
(
)
)
->
access
(
'view',
$this
->account, TRUE
)
->
isNeutral
(
)
)
;
$andNeutral
=
new
AccessGroupAnd
(
)
;
$andNeutral
->
addDependency
(
$allowedAccessible
)
->
addDependency
(
$neutralAccessible
)
;
$this
->
assertTrue
(
$andNeutral
->
access
(
'view',
$this
->account, TRUE
)
->
isNeutral
(
)
)
;
$andForbidden
=
$andNeutral
;
$andForbidden
->
addDependency
(
$forbiddenAccessible
)
;
$this
->
assertTrue
(
$andForbidden
->
access
(
'view',
$this
->account, TRUE
)
->
isForbidden
(
)
)
;
// Ensure that groups added to other groups works.
$andGroupsForbidden
=
new
AccessGroupAnd
(
)
;
/** * {@inheritdoc} */
public
function
addAccessDependency
(
AccessibleInterface
$access_dependency
)
{
if
(
empty
(
$this
->accessDependency
)
)
{
$this
->accessDependency =
$access_dependency
;
return
$this
;
}
if
(
!
$this
->accessDependency instanceof AccessGroupAnd
)
{
$accessGroup
=
new
AccessGroupAnd
(
)
;
$this
->accessDependency =
$accessGroup
->
addDependency
(
$this
->accessDependency
)
;
}
$this
->accessDependency->
addDependency
(
$access_dependency
)
;
return
$this
;
}
}
$accessResultNeutral
=
$dependencies
[
1
]
->
access
(
'view',
$this
->account, TRUE
)
;
$this
->
assertTrue
(
$accessResultNeutral
->
isNeutral
(
)
)
;
$this
->
assertEquals
(
'I have no opinion',
$accessResultNeutral
->
getReason
(
)
)
;
}
/** * Tests merging a new dependency with an existing access group dependency. * * @dataProvider providerTestSetFirst */
public
function
testMergeGroup
(
$use_set_first
)
{
$andGroup
=
new
AccessGroupAnd
(
)
;
$andGroup
->
addDependency
(
$this
->forbidden
)
;
$testRefinable
=
new
RefinableDependentAccessTraitTestClass
(
)
;
if
(
$use_set_first
)
{
$testRefinable
->
setAccessDependency
(
$andGroup
)
;
}
else
{
$testRefinable
->
addAccessDependency
(
$andGroup
)
;
}
$testRefinable
->
addAccessDependency
(
$this
->neutral
)
;
/** @var \Drupal\block_content\Access\AccessGroupAnd $dependency */