AuthTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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-2010 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. * @see Zend_Session
  36. */
  37. require_once 'Zend/Session.php';
  38. /**
  39. * @issue ZF-7882 - temp solution provided by {@link http://www.alexatnet.com/node/12}
  40. */
  41. Zend_Session::start();
  42. /**
  43. * @category Zend
  44. * @package Zend_Auth
  45. * @subpackage UnitTests
  46. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  47. * @license http://framework.zend.com/license/new-bsd New BSD License
  48. * @group Zend_Auth
  49. */
  50. class Zend_AuthTest extends PHPUnit_Framework_TestCase
  51. {
  52. /**
  53. * Ensures that the Singleton pattern is implemented properly
  54. *
  55. * @return void
  56. */
  57. public function testSingleton()
  58. {
  59. $this->assertTrue(Zend_Auth::getInstance() instanceof Zend_Auth);
  60. $this->assertEquals(Zend_Auth::getInstance(), Zend_Auth::getInstance());
  61. }
  62. /**
  63. * Ensures that getStorage() returns Zend_Auth_Storage_Session
  64. *
  65. * @return void
  66. */
  67. public function testGetStorage()
  68. {
  69. $this->assertTrue(Zend_Auth::getInstance()->getStorage() instanceof Zend_Auth_Storage_Session);
  70. }
  71. /**
  72. * Ensures expected behavior for successful authentication
  73. *
  74. * @return void
  75. */
  76. public function testAuthenticate()
  77. {
  78. $auth = Zend_Auth::getInstance();
  79. $result = $auth->authenticate(new Zend_AuthTest_Success_Adapter());
  80. $this->assertTrue($result instanceof Zend_Auth_Result);
  81. $this->assertTrue($auth->hasIdentity());
  82. $this->assertEquals('someIdentity', $auth->getIdentity());
  83. }
  84. /**
  85. * Ensures expected behavior for clearIdentity()
  86. *
  87. * @return void
  88. */
  89. public function testClearIdentity()
  90. {
  91. $auth = Zend_Auth::getInstance();
  92. $auth->clearIdentity();
  93. $this->assertFalse($auth->hasIdentity());
  94. $this->assertEquals(null, $auth->getIdentity());
  95. }
  96. }
  97. class Zend_AuthTest_Success_Adapter implements Zend_Auth_Adapter_Interface
  98. {
  99. public function authenticate()
  100. {
  101. return new Zend_Auth_Result(true, 'someIdentity');
  102. }
  103. }