|
9 | 9 | * file that was distributed with this source code.
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -namespace Symfony\Component\Security\Tests\Acl\Domain; |
13 |
| - |
14 |
| -use Symfony\Component\Security\Acl\Domain\ObjectIdentity; |
15 |
| - |
16 |
| -class ObjectIdentityTest extends \PHPUnit_Framework_TestCase |
| 12 | +namespace Symfony\Component\Security\Tests\Acl\Domain |
17 | 13 | {
|
18 |
| - public function testConstructor() |
| 14 | + use Symfony\Component\Security\Acl\Domain\ObjectIdentity; |
| 15 | + |
| 16 | + class ObjectIdentityTest extends \PHPUnit_Framework_TestCase |
19 | 17 | {
|
20 |
| - $id = new ObjectIdentity('fooid', 'footype'); |
21 |
| - |
22 |
| - $this->assertEquals('fooid', $id->getIdentifier()); |
23 |
| - $this->assertEquals('footype', $id->getType()); |
24 |
| - } |
25 |
| - |
26 |
| - public function testFromDomainObjectPrefersInterfaceOverGetId() |
27 |
| - { |
28 |
| - $domainObject = $this->getMock('Symfony\Component\Security\Acl\Model\DomainObjectInterface'); |
29 |
| - $domainObject |
30 |
| - ->expects($this->once()) |
31 |
| - ->method('getObjectIdentifier') |
32 |
| - ->will($this->returnValue('getObjectIdentifier()')) |
33 |
| - ; |
34 |
| - $domainObject |
35 |
| - ->expects($this->never()) |
36 |
| - ->method('getId') |
37 |
| - ->will($this->returnValue('getId()')) |
38 |
| - ; |
39 |
| - |
40 |
| - $id = ObjectIdentity::fromDomainObject($domainObject); |
41 |
| - $this->assertEquals('getObjectIdentifier()', $id->getIdentifier()); |
42 |
| - } |
| 18 | + public function testConstructor() |
| 19 | + { |
| 20 | + $id = new ObjectIdentity('fooid', 'footype'); |
| 21 | + |
| 22 | + $this->assertEquals('fooid', $id->getIdentifier()); |
| 23 | + $this->assertEquals('footype', $id->getType()); |
| 24 | + } |
43 | 25 |
|
44 |
| - public function testFromDomainObjectWithoutInterface() |
45 |
| - { |
46 |
| - $id = ObjectIdentity::fromDomainObject(new TestDomainObject()); |
47 |
| - $this->assertEquals('getId()', $id->getIdentifier()); |
48 |
| - } |
| 26 | + // Test that constructor never changes passed type, even with proxies |
| 27 | + public function testConstructorWithProxy() |
| 28 | + { |
| 29 | + $id = new ObjectIdentity('fooid', 'Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject'); |
49 | 30 |
|
50 |
| - /** |
51 |
| - * @dataProvider getCompareData |
52 |
| - */ |
53 |
| - public function testEquals($oid1, $oid2, $equal) |
54 |
| - { |
55 |
| - if ($equal) { |
56 |
| - $this->assertTrue($oid1->equals($oid2)); |
57 |
| - } else { |
58 |
| - $this->assertFalse($oid1->equals($oid2)); |
| 31 | + $this->assertEquals('fooid', $id->getIdentifier()); |
| 32 | + $this->assertEquals('Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject', $id->getType()); |
| 33 | + } |
| 34 | + |
| 35 | + public function testFromDomainObjectPrefersInterfaceOverGetId() |
| 36 | + { |
| 37 | + $domainObject = $this->getMock('Symfony\Component\Security\Acl\Model\DomainObjectInterface'); |
| 38 | + $domainObject |
| 39 | + ->expects($this->once()) |
| 40 | + ->method('getObjectIdentifier') |
| 41 | + ->will($this->returnValue('getObjectIdentifier()')) |
| 42 | + ; |
| 43 | + $domainObject |
| 44 | + ->expects($this->never()) |
| 45 | + ->method('getId') |
| 46 | + ->will($this->returnValue('getId()')) |
| 47 | + ; |
| 48 | + |
| 49 | + $id = ObjectIdentity::fromDomainObject($domainObject); |
| 50 | + $this->assertEquals('getObjectIdentifier()', $id->getIdentifier()); |
| 51 | + } |
| 52 | + |
| 53 | + public function testFromDomainObjectWithoutInterface() |
| 54 | + { |
| 55 | + $id = ObjectIdentity::fromDomainObject(new TestDomainObject()); |
| 56 | + $this->assertEquals('getId()', $id->getIdentifier()); |
| 57 | + $this->assertEquals('Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject', $id->getType()); |
59 | 58 | }
|
60 |
| - } |
61 | 59 |
|
62 |
| - public function getCompareData() |
63 |
| - { |
64 |
| - return array( |
65 |
| - array(new ObjectIdentity('123', 'foo'), new ObjectIdentity('123', 'foo'), true), |
66 |
| - array(new ObjectIdentity('123', 'foo'), new ObjectIdentity(123, 'foo'), true), |
67 |
| - array(new ObjectIdentity('1', 'foo'), new ObjectIdentity('2', 'foo'), false), |
68 |
| - array(new ObjectIdentity('1', 'bla'), new ObjectIdentity('1', 'blub'), false), |
69 |
| - ); |
| 60 | + public function testFromDomainObjectWithProxy() |
| 61 | + { |
| 62 | + $id = ObjectIdentity::fromDomainObject(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject()); |
| 63 | + $this->assertEquals('getId()', $id->getIdentifier()); |
| 64 | + $this->assertEquals('Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject', $id->getType()); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @dataProvider getCompareData |
| 69 | + */ |
| 70 | + public function testEquals($oid1, $oid2, $equal) |
| 71 | + { |
| 72 | + if ($equal) { |
| 73 | + $this->assertTrue($oid1->equals($oid2)); |
| 74 | + } else { |
| 75 | + $this->assertFalse($oid1->equals($oid2)); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + public function getCompareData() |
| 80 | + { |
| 81 | + return array( |
| 82 | + array(new ObjectIdentity('123', 'foo'), new ObjectIdentity('123', 'foo'), true), |
| 83 | + array(new ObjectIdentity('123', 'foo'), new ObjectIdentity(123, 'foo'), true), |
| 84 | + array(new ObjectIdentity('1', 'foo'), new ObjectIdentity('2', 'foo'), false), |
| 85 | + array(new ObjectIdentity('1', 'bla'), new ObjectIdentity('1', 'blub'), false), |
| 86 | +
10000
); |
| 87 | + } |
| 88 | + |
| 89 | + protected function setUp() |
| 90 | + { |
| 91 | + if (!class_exists('Doctrine\DBAL\DriverManager')) { |
| 92 | + $this->markTestSkipped('The Doctrine2 DBAL is required for this test'); |
| 93 | + } |
| 94 | + } |
70 | 95 | }
|
71 |
| - |
72 |
| - protected function setUp() |
| 96 | + |
| 97 | + class TestDomainObject |
73 | 98 | {
|
74 |
| - if (!class_exists('Doctrine\DBAL\DriverManager')) { |
75 |
| - $this->markTestSkipped('The Doctrine2 DBAL is required for this test'); |
| 99 | + public function getObjectIdentifier() |
| 100 | + { |
| 101 | + return 'getObjectIdentifier()'; |
| 102 | + } |
| 103 | + |
| 104 | + public function getId() |
| 105 | + { |
| 106 | + return 'getId()'; |
76 | 107 | }
|
77 | 108 | }
|
78 | 109 | }
|
79 | 110 |
|
80 |
| -class TestDomainObject |
| 111 | +namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain |
81 | 112 | {
|
82 |
| - public function getObjectIdentifier() |
83 |
| - { |
84 |
| - return 'getObjectIdentifier()'; |
85 |
| - } |
86 |
| - |
87 |
| - public function getId() |
| 113 | + class TestDomainObject extends \Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject |
88 | 114 | {
|
89 |
| - return 'getId()'; |
90 | 115 | }
|
91 | 116 | }
|
0 commit comments