AclComponentTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * AclComponentTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @package Cake.Test.Case.Controller.Component
  15. * @since CakePHP(tm) v 1.2.0.5435
  16. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  17. */
  18. App::uses('AclComponent', 'Controller/Component');
  19. class_exists('AclComponent');
  20. /**
  21. * Test Case for AclComponent
  22. *
  23. * @package Cake.Test.Case.Controller.Component
  24. */
  25. class AclComponentTest extends CakeTestCase {
  26. /**
  27. * setUp method
  28. *
  29. * @return void
  30. */
  31. public function setUp() {
  32. parent::setUp();
  33. if (!class_exists('MockAclImplementation', false)) {
  34. $this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
  35. }
  36. Configure::write('Acl.classname', 'MockAclImplementation');
  37. $Collection = new ComponentCollection();
  38. $this->Acl = new AclComponent($Collection);
  39. }
  40. /**
  41. * tearDown method
  42. *
  43. * @return void
  44. */
  45. public function tearDown() {
  46. parent::tearDown();
  47. unset($this->Acl);
  48. }
  49. /**
  50. * test that constructor throws an exception when Acl.classname is a
  51. * non-existent class
  52. *
  53. * @expectedException CakeException
  54. * @return void
  55. */
  56. public function testConstrutorException() {
  57. Configure::write('Acl.classname', 'AclClassNameThatDoesNotExist');
  58. $Collection = new ComponentCollection();
  59. new AclComponent($Collection);
  60. }
  61. /**
  62. * test that adapter() allows control of the internal implementation AclComponent uses.
  63. *
  64. * @return void
  65. */
  66. public function testAdapter() {
  67. $Adapter = $this->getMock('AclInterface');
  68. $Adapter->expects($this->once())->method('initialize')->with($this->Acl);
  69. $this->assertNull($this->Acl->adapter($Adapter));
  70. $this->assertEquals($this->Acl->adapter(), $Adapter, 'Returned object is different %s');
  71. }
  72. /**
  73. * test that adapter() whines when the class does not implement AclInterface
  74. *
  75. * @expectedException CakeException
  76. * @return void
  77. */
  78. public function testAdapterException() {
  79. $thing = new StdClass();
  80. $this->Acl->adapter($thing);
  81. }
  82. }