AuthTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Test helper
  23. */
  24. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  25. /**
  26. * @see Zend_Auth
  27. */
  28. require_once 'Zend/Auth.php';
  29. /**
  30. * @see Zend_Auth_Adapter_Interface
  31. */
  32. require_once 'Zend/Auth/Adapter/Interface.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Auth
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_AuthTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * Ensures that the Singleton pattern is implemented properly
  44. *
  45. * @return void
  46. */
  47. public function testSingleton()
  48. {
  49. $this->assertTrue(Zend_Auth::getInstance() instanceof Zend_Auth);
  50. $this->assertEquals(Zend_Auth::getInstance(), Zend_Auth::getInstance());
  51. }
  52. /**
  53. * Ensures that getStorage() returns Zend_Auth_Storage_Session
  54. *
  55. * @return void
  56. */
  57. public function testGetStorage()
  58. {
  59. $this->assertTrue(Zend_Auth::getInstance()->getStorage() instanceof Zend_Auth_Storage_Session);
  60. }
  61. /**
  62. * Ensures expected behavior for successful authentication
  63. *
  64. * @return void
  65. */
  66. public function testAuthenticate()
  67. {
  68. $auth = Zend_Auth::getInstance();
  69. $result = $auth->authenticate(new Zend_AuthTest_Success_Adapter());
  70. $this->assertTrue($result instanceof Zend_Auth_Result);
  71. $this->assertTrue($auth->hasIdentity());
  72. $this->assertEquals('someIdentity', $auth->getIdentity());
  73. }
  74. /**
  75. * Ensures expected behavior for clearIdentity()
  76. *
  77. * @return void
  78. */
  79. public function testClearIdentity()
  80. {
  81. $auth = Zend_Auth::getInstance();
  82. $auth->clearIdentity();
  83. $this->assertFalse($auth->hasIdentity());
  84. $this->assertEquals(null, $auth->getIdentity());
  85. }
  86. }
  87. class Zend_AuthTest_Success_Adapter implements Zend_Auth_Adapter_Interface
  88. {
  89. public function authenticate()
  90. {
  91. return new Zend_Auth_Result(true, 'someIdentity');
  92. }
  93. }