-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support concatenated callables in RenderCallbackRule (#544)
Co-authored-by: Matt Glaman <nmd.matt@gmail.com>
- Loading branch information
Showing
3 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Bug543; | ||
|
||
use Drupal\Core\Access\AccessResult; | ||
use Drupal\Core\Security\TrustedCallbackInterface; | ||
|
||
/** | ||
* Code snippets from \Drupal\Tests\Core\Render\RendererTest. | ||
*/ | ||
class TestClass { | ||
|
||
/** | ||
* Provides a list of both booleans. | ||
* | ||
* @return array | ||
*/ | ||
public function providerAccessValues() { | ||
return [ | ||
[FALSE], | ||
[TRUE], | ||
[AccessResult::forbidden()], | ||
[AccessResult::allowed()], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider providerAccessValues | ||
*/ | ||
public function testRenderWithAccessControllerResolved($access) { | ||
|
||
switch ($access) { | ||
case AccessResult::allowed(): | ||
$method = 'accessResultAllowed'; | ||
break; | ||
|
||
case AccessResult::forbidden(): | ||
$method = 'accessResultForbidden'; | ||
break; | ||
|
||
case FALSE: | ||
$method = 'accessFalse'; | ||
break; | ||
|
||
case TRUE: | ||
$method = 'accessTrue'; | ||
break; | ||
} | ||
|
||
$build = [ | ||
'#access_callback' => TestAccessClass::class . '::' . $method, | ||
]; | ||
} | ||
|
||
public function bug543AccessResultAllowed(): void { | ||
$build = [ | ||
'#access_callback' => TestAccessClass::class . '::accessResultAllowed', | ||
]; | ||
} | ||
|
||
public function bug543AccessResultForbidden(): void { | ||
$build = [ | ||
'#access_callback' => TestAccessClass::class . '::accessResultForbidden', | ||
]; | ||
} | ||
|
||
public function bug543AccessFalse(): void { | ||
$build = [ | ||
'#access_callback' => TestAccessClass::class . '::accessFalse', | ||
]; | ||
} | ||
|
||
public function bug543AccessTrue(): void { | ||
$build = [ | ||
'#access_callback' => TestAccessClass::class . '::accessTrue', | ||
]; | ||
} | ||
} | ||
|
||
class TestAccessClass implements TrustedCallbackInterface { | ||
|
||
public static function accessTrue() { | ||
return TRUE; | ||
} | ||
|
||
public static function accessFalse() { | ||
return FALSE; | ||
} | ||
|
||
public static function accessResultAllowed() { | ||
return AccessResult::allowed(); | ||
} | ||
|
||
public static function accessResultForbidden() { | ||
return AccessResult::forbidden(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function trustedCallbacks() { | ||
return ['accessTrue', 'accessFalse', 'accessResultAllowed', 'accessResultForbidden']; | ||
} | ||
|
||
} |