AclComponentTest.php 2.4 KB

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