AuthTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Config
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. /**
  23. * @see Zend_Auth
  24. */
  25. require_once 'Zend/Auth.php';
  26. /**
  27. * @see Zend_Auth_Adapter_Interface
  28. */
  29. require_once 'Zend/Auth/Adapter/Interface.php';
  30. /**
  31. * @see Zend_Session
  32. */
  33. require_once 'Zend/Session.php';
  34. /**
  35. * @group ZF-7882 - temp solution provided by {@link http://www.alexatnet.com/node/12}
  36. */
  37. Zend_Session::start();
  38. /**
  39. * @category Zend
  40. * @package Zend_Auth
  41. * @subpackage UnitTests
  42. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  43. * @license http://framework.zend.com/license/new-bsd New BSD License
  44. * @group Zend_Auth
  45. */
  46. class Zend_AuthTest extends PHPUnit_Framework_TestCase
  47. {
  48. /**
  49. * Ensures that the Singleton pattern is implemented properly
  50. *
  51. * @return void
  52. */
  53. public function testSingleton()
  54. {
  55. $this->assertTrue(Zend_Auth::getInstance() instanceof Zend_Auth);
  56. $this->assertEquals(Zend_Auth::getInstance(), Zend_Auth::getInstance());
  57. }
  58. /**
  59. * Ensures that getStorage() returns Zend_Auth_Storage_Session
  60. *
  61. * @return void
  62. */
  63. public function testGetStorage()
  64. {
  65. $this->assertTrue(Zend_Auth::getInstance()->getStorage() instanceof Zend_Auth_Storage_Session);
  66. }
  67. /**
  68. * Ensures expected behavior for successful authentication
  69. *
  70. * @return void
  71. */
  72. public function testAuthenticate()
  73. {
  74. $auth = Zend_Auth::getInstance();
  75. $result = $auth->authenticate(new Zend_AuthTest_Success_Adapter());
  76. $this->assertTrue($result instanceof Zend_Auth_Result);
  77. $this->assertTrue($auth->hasIdentity());
  78. $this->assertEquals('someIdentity', $auth->getIdentity());
  79. }
  80. /**
  81. * Ensures expected behavior for clearIdentity()
  82. *
  83. * @return void
  84. */
  85. public function testClearIdentity()
  86. {
  87. $auth = Zend_Auth::getInstance();
  88. $auth->clearIdentity();
  89. $this->assertFalse($auth->hasIdentity());
  90. $this->assertEquals(null, $auth->getIdentity());
  91. }
  92. }
  93. class Zend_AuthTest_Success_Adapter implements Zend_Auth_Adapter_Interface
  94. {
  95. public function authenticate()
  96. {
  97. return new Zend_Auth_Result(true, 'someIdentity');
  98. }
  99. }