2
0

AuthTest.php 2.8 KB

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