AclComponentTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. * @since CakePHP(tm) v 1.2.0.5435
  17. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  18. */
  19. namespace Cake\Test\TestCase\Controller\Component;
  20. use Cake\Controller\ComponentRegistry;
  21. use Cake\Controller\Component\AclComponent;
  22. use Cake\Core\Configure;
  23. use Cake\TestSuite\TestCase;
  24. /**
  25. * Test Case for AclComponent
  26. *
  27. */
  28. class AclComponentTest extends TestCase {
  29. /**
  30. * setUp method
  31. *
  32. * @return void
  33. */
  34. public function setUp() {
  35. parent::setUp();
  36. if (!class_exists('MockAclImplementation', false)) {
  37. $this->getMock('Cake\Controller\Component\Acl\AclInterface', array(), array(), 'MockAclImplementation');
  38. }
  39. Configure::write('Acl.classname', '\MockAclImplementation');
  40. $Collection = new ComponentRegistry();
  41. $this->Acl = new AclComponent($Collection);
  42. }
  43. /**
  44. * tearDown method
  45. *
  46. * @return void
  47. */
  48. public function tearDown() {
  49. parent::tearDown();
  50. unset($this->Acl);
  51. }
  52. /**
  53. * test that constructor throws an exception when Acl.classname is a
  54. * non-existent class
  55. *
  56. * @expectedException Cake\Error\Exception
  57. * @return void
  58. */
  59. public function testConstrutorException() {
  60. Configure::write('Acl.classname', 'AclClassNameThatDoesNotExist');
  61. $Collection = new ComponentRegistry();
  62. new AclComponent($Collection);
  63. }
  64. /**
  65. * test that adapter() allows control of the internal implementation AclComponent uses.
  66. *
  67. * @return void
  68. */
  69. public function testAdapter() {
  70. $implementation = new \MockAclImplementation();
  71. $implementation->expects($this->once())->method('initialize')->with($this->Acl);
  72. $this->assertNull($this->Acl->adapter($implementation));
  73. $this->assertEquals($this->Acl->adapter(), $implementation, 'Returned object is different %s');
  74. }
  75. /**
  76. * test that adapter() whines when the class is not an AclBase
  77. *
  78. * @expectedException Cake\Error\Exception
  79. * @return void
  80. */
  81. public function testAdapterException() {
  82. $thing = new \StdClass();
  83. $this->Acl->adapter($thing);
  84. }
  85. }