sfTesterUser.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfTesterUser implements tests for the symfony user object.
  11. *
  12. * @package symfony
  13. * @subpackage test
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfTesterUser.class.php 15802 2009-02-26 09:40:27Z fabien $
  16. */
  17. class sfTesterUser extends sfTester
  18. {
  19. protected $user;
  20. /**
  21. * Prepares the tester.
  22. */
  23. public function prepare()
  24. {
  25. }
  26. /**
  27. * Initializes the tester.
  28. */
  29. public function initialize()
  30. {
  31. $this->user = $this->browser->getUser();
  32. }
  33. /**
  34. * Tests a user attribute value.
  35. *
  36. * @param string $key
  37. * @param string $value
  38. * @param string $ns
  39. *
  40. * @return sfTestFunctionalBase|sfTester
  41. */
  42. public function isAttribute($key, $value, $ns = null)
  43. {
  44. $this->tester->is($this->user->getAttribute($key, null, $ns), $value, sprintf('user attribute "%s" is "%s"', $key, $value));
  45. return $this->getObjectToReturn();
  46. }
  47. /**
  48. * Tests a user flash value.
  49. *
  50. * @param string $key
  51. * @param string $value
  52. *
  53. * @return sfTestFunctionalBase|sfTester
  54. */
  55. public function isFlash($key, $value)
  56. {
  57. $this->tester->is($this->user->getFlash($key), $value, sprintf('user flash "%s" is "%s"', $key, $value));
  58. return $this->getObjectToReturn();
  59. }
  60. /**
  61. * Tests the user culture.
  62. *
  63. * @param string $culture The user culture
  64. *
  65. * @return sfTestFunctionalBase|sfTester
  66. */
  67. public function isCulture($culture)
  68. {
  69. $this->tester->is($this->user->getCulture(), $culture, sprintf('user culture is "%s"', $culture));
  70. return $this->getObjectToReturn();
  71. }
  72. /**
  73. * Tests if the user is authenticated.
  74. *
  75. * @param Boolean $boolean Whether to check if the user is authenticated or not
  76. *
  77. * @return sfTestFunctionalBase|sfTester
  78. */
  79. public function isAuthenticated($boolean = true)
  80. {
  81. $this->tester->is($this->user->isAuthenticated(), $boolean, sprintf('user is %sauthenticated', $boolean ? '' : 'not '));
  82. return $this->getObjectToReturn();
  83. }
  84. /**
  85. * Tests if the user has some credentials.
  86. *
  87. * @param mixed $credentials
  88. * @param bool $boolean Whether to check if the user have some credentials or not
  89. * @param bool $useAnd specify the mode, either AND or OR
  90. *
  91. * @return sfTestFunctionalBase|sfTester
  92. */
  93. public function hasCredential($credentials, $boolean = true, $useAnd = true)
  94. {
  95. $this->tester->is($this->user->hasCredential($credentials, $useAnd), $boolean, sprintf('user has %s the right credentials', $boolean ? '' : 'not '));
  96. return $this->getObjectToReturn();
  97. }
  98. }