2
0

AuthTest.php 2.8 KB

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