AclComponentTest.php 2.4 KB

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