MutableAclProviderTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Acl\Tests\Dbal;
  11. use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
  12. use Symfony\Component\Security\Acl\Model\FieldEntryInterface;
  13. use Symfony\Component\Security\Acl\Model\AuditableEntryInterface;
  14. use Symfony\Component\Security\Acl\Model\EntryInterface;
  15. use Symfony\Component\Security\Acl\Domain\Entry;
  16. use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
  17. use Symfony\Component\Security\Acl\Domain\Acl;
  18. use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
  19. use Symfony\Component\Security\Acl\Exception\ConcurrentModificationException;
  20. use Symfony\Component\Security\Acl\Dbal\AclProvider;
  21. use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
  22. use Symfony\Component\Security\Acl\Dbal\MutableAclProvider;
  23. use Symfony\Component\Security\Acl\Dbal\Schema;
  24. use Doctrine\DBAL\DriverManager;
  25. use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
  26. /**
  27. * @requires extension pdo_sqlite
  28. */
  29. class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
  30. {
  31. protected $con;
  32. public static function assertAceEquals(EntryInterface $a, EntryInterface $b)
  33. {
  34. self::assertInstanceOf(get_class($a), $b);
  35. foreach (array('getId', 'getMask', 'getStrategy', 'isGranting') as $getter) {
  36. self::assertSame($a->$getter(), $b->$getter());
  37. }
  38. self::assertTrue($a->getSecurityIdentity()->equals($b->getSecurityIdentity()));
  39. self::assertSame($a->getAcl()->getId(), $b->getAcl()->getId());
  40. if ($a instanceof AuditableEntryInterface) {
  41. self::assertSame($a->isAuditSuccess(), $b->isAuditSuccess());
  42. self::assertSame($a->isAuditFailure(), $b->isAuditFailure());
  43. }
  44. if ($a instanceof FieldEntryInterface) {
  45. self::assertSame($a->getField(), $b->getField());
  46. }
  47. }
  48. /**
  49. * @expectedException \Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException
  50. */
  51. public function testCreateAclThrowsExceptionWhenAclAlreadyExists()
  52. {
  53. $provider = $this->getProvider();
  54. $oid = new ObjectIdentity('123456', 'FOO');
  55. $provider->createAcl($oid);
  56. $provider->createAcl($oid);
  57. }
  58. public function testCreateAcl()
  59. {
  60. $provider = $this->getProvider();
  61. $oid = new ObjectIdentity('123456', 'FOO');
  62. $acl = $provider->createAcl($oid);
  63. $cachedAcl = $provider->findAcl($oid);
  64. $this->assertInstanceOf('Symfony\Component\Security\Acl\Domain\Acl', $acl);
  65. $this->assertSame($acl, $cachedAcl);
  66. $this->assertTrue($acl->getObjectIdentity()->equals($oid));
  67. }
  68. public function testDeleteAcl()
  69. {
  70. $provider = $this->getProvider();
  71. $oid = new ObjectIdentity(1, 'Foo');
  72. $acl = $provider->createAcl($oid);
  73. $provider->deleteAcl($oid);
  74. $loadedAcls = $this->getField($provider, 'loadedAcls');
  75. $this->assertCount(0, $loadedAcls['Foo']);
  76. try {
  77. $provider->findAcl($oid);
  78. $this->fail('ACL has not been properly deleted.');
  79. } catch (AclNotFoundException $e) {
  80. }
  81. }
  82. public function testDeleteAclDeletesChildren()
  83. {
  84. $provider = $this->getProvider();
  85. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  86. $parentAcl = $provider->createAcl(new ObjectIdentity(2, 'Foo'));
  87. $acl->setParentAcl($parentAcl);
  88. $provider->updateAcl($acl);
  89. $provider->deleteAcl($parentAcl->getObjectIdentity());
  90. try {
  91. $provider->findAcl(new ObjectIdentity(1, 'Foo'));
  92. $this->fail('Child-ACLs have not been deleted.');
  93. } catch (AclNotFoundException $e) {
  94. }
  95. }
  96. public function testFindAclsAddsPropertyListener()
  97. {
  98. $provider = $this->getProvider();
  99. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  100. $propertyChanges = $this->getField($provider, 'propertyChanges');
  101. $this->assertCount(1, $propertyChanges);
  102. $this->assertTrue($propertyChanges->contains($acl));
  103. $this->assertEquals(array(), $propertyChanges->offsetGet($acl));
  104. $listeners = $this->getField($acl, 'listeners');
  105. $this->assertSame($provider, $listeners[0]);
  106. }
  107. public function testFindAclsAddsPropertyListenerOnlyOnce()
  108. {
  109. $provider = $this->getProvider();
  110. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  111. $acl = $provider->findAcl(new ObjectIdentity(1, 'Foo'));
  112. $propertyChanges = $this->getField($provider, 'propertyChanges');
  113. $this->assertCount(1, $propertyChanges);
  114. $this->assertTrue($propertyChanges->contains($acl));
  115. $this->assertEquals(array(), $propertyChanges->offsetGet($acl));
  116. $listeners = $this->getField($acl, 'listeners');
  117. $this->assertCount(1, $listeners);
  118. $this->assertSame($provider, $listeners[0]);
  119. }
  120. public function testFindAclsAddsPropertyListenerToParentAcls()
  121. {
  122. $provider = $this->getProvider();
  123. $this->importAcls($provider, array(
  124. 'main' => array(
  125. 'object_identifier' => '1',
  126. 'class_type' => 'foo',
  127. 'parent_acl' => 'parent',
  128. ),
  129. 'parent' => array(
  130. 'object_identifier' => '1',
  131. 'class_type' => 'anotherFoo',
  132. ),
  133. ));
  134. $propertyChanges = $this->getField($provider, 'propertyChanges');
  135. $this->assertCount(0, $propertyChanges);
  136. $acl = $provider->findAcl(new ObjectIdentity('1', 'foo'));
  137. $this->assertCount(2, $propertyChanges);
  138. $this->assertTrue($propertyChanges->contains($acl));
  139. $this->assertTrue($propertyChanges->contains($acl->getParentAcl()));
  140. }
  141. /**
  142. * @expectedException \InvalidArgumentException
  143. */
  144. public function testPropertyChangedDoesNotTrackUnmanagedAcls()
  145. {
  146. $provider = $this->getProvider();
  147. $acl = new Acl(1, new ObjectIdentity(1, 'foo'), new PermissionGrantingStrategy(), array(), false);
  148. $provider->propertyChanged($acl, 'classAces', array(), array('foo'));
  149. }
  150. public function testPropertyChangedTracksChangesToAclProperties()
  151. {
  152. $provider = $this->getProvider();
  153. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  154. $propertyChanges = $this->getField($provider, 'propertyChanges');
  155. $provider->propertyChanged($acl, 'entriesInheriting', false, true);
  156. $changes = $propertyChanges->offsetGet($acl);
  157. $this->assertTrue(isset($changes['entriesInheriting']));
  158. $this->assertFalse($changes['entriesInheriting'][0]);
  159. $this->assertTrue($changes['entriesInheriting'][1]);
  160. $provider->propertyChanged($acl, 'entriesInheriting', true, false);
  161. $provider->propertyChanged($acl, 'entriesInheriting', false, true);
  162. $provider->propertyChanged($acl, 'entriesInheriting', true, false);
  163. $changes = $propertyChanges->offsetGet($acl);
  164. $this->assertFalse(isset($changes['entriesInheriting']));
  165. }
  166. public function testPropertyChangedTracksChangesToAceProperties()
  167. {
  168. $provider = $this->getProvider();
  169. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  170. $ace = new Entry(1, $acl, new UserSecurityIdentity('foo', 'FooClass'), 'all', 1, true, true, true);
  171. $ace2 = new Entry(2, $acl, new UserSecurityIdentity('foo', 'FooClass'), 'all', 1, true, true, true);
  172. $propertyChanges = $this->getField($provider, 'propertyChanges');
  173. $provider->propertyChanged($ace, 'mask', 1, 3);
  174. $changes = $propertyChanges->offsetGet($acl);
  175. $this->assertTrue(isset($changes['aces']));
  176. $this->assertInstanceOf('\SplObjectStorage', $changes['aces']);
  177. $this->assertTrue($changes['aces']->contains($ace));
  178. $aceChanges = $changes['aces']->offsetGet($ace);
  179. $this->assertTrue(isset($aceChanges['mask']));
  180. $this->assertEquals(1, $aceChanges['mask'][0]);
  181. $this->assertEquals(3, $aceChanges['mask'][1]);
  182. $provider->propertyChanged($ace, 'strategy', 'all', 'any');
  183. $changes = $propertyChanges->offsetGet($acl);
  184. $this->assertTrue(isset($changes['aces']));
  185. $this->assertInstanceOf('\SplObjectStorage', $changes['aces']);
  186. $this->assertTrue($changes['aces']->contains($ace));
  187. $aceChanges = $changes['aces']->offsetGet($ace);
  188. $this->assertTrue(isset($aceChanges['mask']));
  189. $this->assertTrue(isset($aceChanges['strategy']));
  190. $this->assertEquals('all', $aceChanges['strategy'][0]);
  191. $this->assertEquals('any', $aceChanges['strategy'][1]);
  192. $provider->propertyChanged($ace, 'mask', 3, 1);
  193. $changes = $propertyChanges->offsetGet($acl);
  194. $aceChanges = $changes['aces']->offsetGet($ace);
  195. $this->assertFalse(isset($aceChanges['mask']));
  196. $this->assertTrue(isset($aceChanges['strategy']));
  197. $provider->propertyChanged($ace2, 'mask', 1, 3);
  198. $provider->propertyChanged($ace, 'strategy', 'any', 'all');
  199. $changes = $propertyChanges->offsetGet($acl);
  200. $this->assertTrue(isset($changes['aces']));
  201. $this->assertFalse($changes['aces']->contains($ace));
  202. $this->assertTrue($changes['aces']->contains($ace2));
  203. $provider->propertyChanged($ace2, 'mask', 3, 4);
  204. $provider->propertyChanged($ace2, 'mask', 4, 1);
  205. $changes = $propertyChanges->offsetGet($acl);
  206. $this->assertFalse(isset($changes['aces']));
  207. }
  208. /**
  209. * @expectedException \InvalidArgumentException
  210. */
  211. public function testUpdateAclDoesNotAcceptUntrackedAcls()
  212. {
  213. $provider = $this->getProvider();
  214. $acl = new Acl(1, new ObjectIdentity(1, 'Foo'), new PermissionGrantingStrategy(), array(), true);
  215. $provider->updateAcl($acl);
  216. }
  217. public function testUpdateDoesNothingWhenThereAreNoChanges()
  218. {
  219. $con = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
  220. $con
  221. ->expects($this->never())
  222. ->method('beginTransaction')
  223. ;
  224. $con
  225. ->expects($this->never())
  226. ->method('executeQuery')
  227. ;
  228. $provider = new MutableAclProvider($con, new PermissionGrantingStrategy(), array());
  229. $acl = new Acl(1, new ObjectIdentity(1, 'Foo'), new PermissionGrantingStrategy(), array(), true);
  230. $propertyChanges = $this->getField($provider, 'propertyChanges');
  231. $propertyChanges->offsetSet($acl, array());
  232. $provider->updateAcl($acl);
  233. }
  234. public function testUpdateAclThrowsExceptionOnConcurrentModificationOfSharedProperties()
  235. {
  236. $provider = $this->getProvider();
  237. $acl1 = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  238. $acl2 = $provider->createAcl(new ObjectIdentity(2, 'Foo'));
  239. $acl3 = $provider->createAcl(new ObjectIdentity(1, 'AnotherFoo'));
  240. $sid = new RoleSecurityIdentity('ROLE_FOO');
  241. $acl1->insertClassAce($sid, 1);
  242. $acl3->insertClassAce($sid, 1);
  243. $provider->updateAcl($acl1);
  244. $provider->updateAcl($acl3);
  245. $acl2->insertClassAce($sid, 16);
  246. $provider->updateAcl($acl2);
  247. $acl1->insertClassAce($sid, 3);
  248. $acl2->insertClassAce($sid, 5);
  249. try {
  250. $provider->updateAcl($acl1);
  251. $this->fail('Provider failed to detect a concurrent modification.');
  252. } catch (ConcurrentModificationException $e) {
  253. }
  254. }
  255. public function testUpdateAcl()
  256. {
  257. $provider = $this->getProvider();
  258. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  259. $sid = new UserSecurityIdentity('johannes', 'FooClass');
  260. $acl->setEntriesInheriting(!$acl->isEntriesInheriting());
  261. $acl->insertObjectAce($sid, 1);
  262. $acl->insertClassAce($sid, 5, 0, false);
  263. $acl->insertObjectAce($sid, 2, 1, true);
  264. $acl->insertClassFieldAce('field', $sid, 2, 0, true);
  265. $provider->updateAcl($acl);
  266. $acl->updateObjectAce(0, 3);
  267. $acl->deleteObjectAce(1);
  268. $acl->updateObjectAuditing(0, true, false);
  269. $acl->updateClassFieldAce(0, 'field', 15);
  270. $provider->updateAcl($acl);
  271. $reloadProvider = $this->getProvider();
  272. $reloadedAcl = $reloadProvider->findAcl(new ObjectIdentity(1, 'Foo'));
  273. $this->assertNotSame($acl, $reloadedAcl);
  274. $this->assertSame($acl->isEntriesInheriting(), $reloadedAcl->isEntriesInheriting());
  275. $aces = $acl->getObjectAces();
  276. $reloadedAces = $reloadedAcl->getObjectAces();
  277. $this->assertEquals(count($aces), count($reloadedAces));
  278. foreach ($aces as $index => $ace) {
  279. $this->assertAceEquals($ace, $reloadedAces[$index]);
  280. }
  281. }
  282. public function testUpdateAclWorksForChangingTheParentAcl()
  283. {
  284. $provider = $this->getProvider();
  285. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  286. $parentAcl = $provider->createAcl(new ObjectIdentity(1, 'AnotherFoo'));
  287. $acl->setParentAcl($parentAcl);
  288. $provider->updateAcl($acl);
  289. $reloadProvider = $this->getProvider();
  290. $reloadedAcl = $reloadProvider->findAcl(new ObjectIdentity(1, 'Foo'));
  291. $this->assertNotSame($acl, $reloadedAcl);
  292. $this->assertSame($parentAcl->getId(), $reloadedAcl->getParentAcl()->getId());
  293. }
  294. public function testUpdateAclUpdatesChildAclsCorrectly()
  295. {
  296. $provider = $this->getProvider();
  297. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  298. $parentAcl = $provider->createAcl(new ObjectIdentity(1, 'Bar'));
  299. $acl->setParentAcl($parentAcl);
  300. $provider->updateAcl($acl);
  301. $parentParentAcl = $provider->createAcl(new ObjectIdentity(1, 'Baz'));
  302. $parentAcl->setParentAcl($parentParentAcl);
  303. $provider->updateAcl($parentAcl);
  304. $newParentParentAcl = $provider->createAcl(new ObjectIdentity(2, 'Baz'));
  305. $parentAcl->setParentAcl($newParentParentAcl);
  306. $provider->updateAcl($parentAcl);
  307. $reloadProvider = $this->getProvider();
  308. $reloadedAcl = $reloadProvider->findAcl(new ObjectIdentity(1, 'Foo'));
  309. $this->assertEquals($newParentParentAcl->getId(), $reloadedAcl->getParentAcl()->getParentAcl()->getId());
  310. }
  311. public function testUpdateAclInsertingMultipleObjectFieldAcesThrowsDBConstraintViolations()
  312. {
  313. $provider = $this->getProvider();
  314. $oid = new ObjectIdentity(1, 'Foo');
  315. $sid1 = new UserSecurityIdentity('johannes', 'FooClass');
  316. $sid2 = new UserSecurityIdentity('guilro', 'FooClass');
  317. $sid3 = new UserSecurityIdentity('bmaz', 'FooClass');
  318. $fieldName = 'fieldName';
  319. $acl = $provider->createAcl($oid);
  320. $acl->insertObjectFieldAce($fieldName, $sid1, 4);
  321. $provider->updateAcl($acl);
  322. $acl = $provider->findAcl($oid);
  323. $acl->insertObjectFieldAce($fieldName, $sid2, 4);
  324. $provider->updateAcl($acl);
  325. $acl = $provider->findAcl($oid);
  326. $acl->insertObjectFieldAce($fieldName, $sid3, 4);
  327. $provider->updateAcl($acl);
  328. }
  329. public function testUpdateAclDeletingObjectFieldAcesThrowsDBConstraintViolations()
  330. {
  331. $provider = $this->getProvider();
  332. $oid = new ObjectIdentity(1, 'Foo');
  333. $sid1 = new UserSecurityIdentity('johannes', 'FooClass');
  334. $sid2 = new UserSecurityIdentity('guilro', 'FooClass');
  335. $sid3 = new UserSecurityIdentity('bmaz', 'FooClass');
  336. $fieldName = 'fieldName';
  337. $acl = $provider->createAcl($oid);
  338. $acl->insertObjectFieldAce($fieldName, $sid1, 4);
  339. $provider->updateAcl($acl);
  340. $acl = $provider->findAcl($oid);
  341. $acl->insertObjectFieldAce($fieldName, $sid2, 4);
  342. $provider->updateAcl($acl);
  343. $index = 0;
  344. $acl->deleteObjectFieldAce($index, $fieldName);
  345. $provider->updateAcl($acl);
  346. $acl = $provider->findAcl($oid);
  347. $acl->insertObjectFieldAce($fieldName, $sid3, 4);
  348. $provider->updateAcl($acl);
  349. }
  350. public function testUpdateUserSecurityIdentity()
  351. {
  352. $provider = $this->getProvider();
  353. $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
  354. $sid = new UserSecurityIdentity('johannes', 'FooClass');
  355. $acl->setEntriesInheriting(!$acl->isEntriesInheriting());
  356. $acl->insertObjectAce($sid, 1);
  357. $acl->insertClassAce($sid, 5, 0, false);
  358. $acl->insertObjectAce($sid, 2, 1, true);
  359. $acl->insertClassFieldAce('field', $sid, 2, 0, true);
  360. $provider->updateAcl($acl);
  361. $newSid = new UserSecurityIdentity('mathieu', 'FooClass');
  362. $provider->updateUserSecurityIdentity($newSid, 'johannes');
  363. $reloadProvider = $this->getProvider();
  364. $reloadedAcl = $reloadProvider->findAcl(new ObjectIdentity(1, 'Foo'));
  365. $this->assertNotSame($acl, $reloadedAcl);
  366. $this->assertSame($acl->isEntriesInheriting(), $reloadedAcl->isEntriesInheriting());
  367. $aces = $acl->getObjectAces();
  368. $reloadedAces = $reloadedAcl->getObjectAces();
  369. $this->assertEquals(count($aces), count($reloadedAces));
  370. foreach ($reloadedAces as $ace) {
  371. $this->assertTrue($ace->getSecurityIdentity()->equals($newSid));
  372. }
  373. }
  374. /**
  375. * Imports acls.
  376. *
  377. * Data must have the following format:
  378. * array(
  379. * *name* => array(
  380. * 'object_identifier' => *required*
  381. * 'class_type' => *required*,
  382. * 'parent_acl' => *name (optional)*
  383. * ),
  384. * )
  385. *
  386. * @param AclProvider $provider
  387. * @param array $data
  388. *
  389. * @throws \InvalidArgumentException
  390. * @throws \Exception
  391. */
  392. protected function importAcls(AclProvider $provider, array $data)
  393. {
  394. $aclIds = $parentAcls = array();
  395. $con = $this->getField($provider, 'connection');
  396. $con->beginTransaction();
  397. try {
  398. foreach ($data as $name => $aclData) {
  399. if (!isset($aclData['object_identifier'], $aclData['class_type'])) {
  400. throw new \InvalidArgumentException('"object_identifier", and "class_type" must be present.');
  401. }
  402. $this->callMethod($provider, 'createObjectIdentity', array(new ObjectIdentity($aclData['object_identifier'], $aclData['class_type'])));
  403. $aclId = $con->lastInsertId();
  404. $aclIds[$name] = $aclId;
  405. $sql = $this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclId));
  406. $con->executeQuery($sql);
  407. if (isset($aclData['parent_acl'])) {
  408. if (isset($aclIds[$aclData['parent_acl']])) {
  409. $con->executeQuery('UPDATE acl_object_identities SET parent_object_identity_id = '.$aclIds[$aclData['parent_acl']].' WHERE id = '.$aclId);
  410. $con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$aclData['parent_acl']])));
  411. } else {
  412. $parentAcls[$aclId] = $aclData['parent_acl'];
  413. }
  414. }
  415. }
  416. foreach ($parentAcls as $aclId => $name) {
  417. if (!isset($aclIds[$name])) {
  418. throw new \InvalidArgumentException(sprintf('"%s" does not exist.', $name));
  419. }
  420. $con->executeQuery(sprintf('UPDATE acl_object_identities SET parent_object_identity_id = %d WHERE id = %d', $aclIds[$name], $aclId));
  421. $con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$name])));
  422. }
  423. $con->commit();
  424. } catch (\Exception $e) {
  425. $con->rollBack();
  426. throw $e;
  427. }
  428. }
  429. protected function callMethod($object, $method, array $args)
  430. {
  431. $method = new \ReflectionMethod($object, $method);
  432. $method->setAccessible(true);
  433. return $method->invokeArgs($object, $args);
  434. }
  435. protected function setUp()
  436. {
  437. $this->con = DriverManager::getConnection(array(
  438. 'driver' => 'pdo_sqlite',
  439. 'memory' => true,
  440. ));
  441. // import the schema
  442. $schema = new Schema($this->getOptions());
  443. foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
  444. $this->con->exec($sql);
  445. }
  446. }
  447. protected function tearDown()
  448. {
  449. $this->con = null;
  450. }
  451. protected function getField($object, $field)
  452. {
  453. $reflection = new \ReflectionProperty($object, $field);
  454. $reflection->setAccessible(true);
  455. return $reflection->getValue($object);
  456. }
  457. public function setField($object, $field, $value)
  458. {
  459. $reflection = new \ReflectionProperty($object, $field);
  460. $reflection->setAccessible(true);
  461. $reflection->setValue($object, $value);
  462. $reflection->setAccessible(false);
  463. }
  464. protected function getOptions()
  465. {
  466. return array(
  467. 'oid_table_name' => 'acl_object_identities',
  468. 'oid_ancestors_table_name' => 'acl_object_identity_ancestors',
  469. 'class_table_name' => 'acl_classes',
  470. 'sid_table_name' => 'acl_security_identities',
  471. 'entry_table_name' => 'acl_entries',
  472. );
  473. }
  474. protected function getStrategy()
  475. {
  476. return new PermissionGrantingStrategy();
  477. }
  478. protected function getProvider($cache = null)
  479. {
  480. return new MutableAclProvider($this->con, $this->getStrategy(), $this->getOptions(), $cache);
  481. }
  482. }