AclComponentTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * @since 1.2.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\Controller\Component;
  18. use Cake\Controller\ComponentRegistry;
  19. use Cake\Controller\Component\AclComponent;
  20. use Cake\Core\Configure;
  21. use Cake\TestSuite\TestCase;
  22. /**
  23. * Test Case for AclComponent
  24. *
  25. */
  26. class AclComponentTest extends TestCase {
  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('Cake\Controller\Component\Acl\AclInterface', array(), array(), 'MockAclImplementation');
  36. }
  37. Configure::write('Acl.classname', '\MockAclImplementation');
  38. $Collection = new ComponentRegistry();
  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 \Cake\Error\Exception
  55. * @return void
  56. */
  57. public function testConstrutorException() {
  58. Configure::write('Acl.classname', 'AclClassNameThatDoesNotExist');
  59. $Collection = new ComponentRegistry();
  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. $Adapter = $this->getMock('Cake\Controller\Component\Acl\AclInterface');
  69. $Adapter->expects($this->once())->method('initialize')->with($this->Acl);
  70. $this->assertNull($this->Acl->adapter($Adapter));
  71. $this->assertEquals($this->Acl->adapter(), $Adapter, 'Returned object is different %s');
  72. }
  73. /**
  74. * test that adapter() whines when the class does not implement AclInterface
  75. *
  76. * @expectedException \Cake\Error\Exception
  77. * @return void
  78. */
  79. public function testAdapterException() {
  80. $thing = new \StdClass();
  81. $this->Acl->adapter($thing);
  82. }
  83. }