|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Security\Core\Tests\Authorization; |
| 13 | + |
| 14 | +use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; |
| 15 | +use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager; |
| 16 | +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
| 17 | + |
| 18 | +class DebugAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @dataProvider provideObjectsAndLogs |
| 22 | + */ |
| 23 | + public function testDecideLog($expectedLog, $object) |
| 24 | + { |
| 25 | + $adm = new DebugAccessDecisionManager(new AccessDecisionManager()); |
| 26 | + $adm->decide($this->getMock(TokenInterface::class), array('ATTRIBUTE_1'), $object); |
| 27 | + |
| 28 | + $this->assertSame($expectedLog, $adm->getDecisionLog()); |
| 29 | + } |
| 30 | + |
| 31 | + public function provideObjectsAndLogs() |
| 32 | + { |
| 33 | + $object = new \stdClass(); |
| 34 | + |
| 35 | + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'NULL', 'result' => false)), null); |
| 36 | + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'boolean (true)', 'result' => false)), true); |
| 37 | + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'string (jolie string)', 'result' => false)), 'jolie string'); |
| 38 | + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'integer (12345)', 'result' => false)), 12345); |
| 39 | + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'resource', 'result' => false)), fopen(__FILE__, 'r')); |
| 40 | + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'array', 'result' => false)), array()); |
| 41 | + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => sprintf('stdClass (object hash: %s)', spl_object_hash($object)), 'result' => false)), $object); |
| 42 | + } |
| 43 | +} |
0 commit comments