1. sfTesterUser.class.php
  2. /** * sfTesterUser implements tests for the symfony user object. * * @package symfony * @subpackage test * @author Fabien Potencier * @version SVN: $Id: sfTesterUser.class.php 21769 2009-09-08 03:01:39Z dwhittle $ */
  3. class sfTesterUser extends sfTester
  4. {
  5. protected $user;
  6. /**
  7. * Prepares the tester.
  8. */
  9. public function prepare()
  10. {
  11. }
  12. /**
  13. * Initializes the tester.
  14. */
  15. public function initialize()
  16. {
  17. $this->user = $this->browser->getUser();
  18. }
  19. /**
  20. * Tests a user attribute value.
  21. *
  22. * @param string $key
  23. * @param string $value
  24. * @param string $ns
  25. *
  26. * @return sfTestFunctionalBase|sfTester
  27. */
  28. public function isAttribute($key, $value, $ns = null)
  29. {
  30. $this->tester->is($this->user->getAttribute($key, null, $ns), $value, sprintf('user attribute "%s" is "%s"', $key, $value));
  31. return $this->getObjectToReturn();
  32. }
  33. /**
  34. * Tests a user flash value.
  35. *
  36. * @param string $key
  37. * @param string $value
  38. *
  39. * @return sfTestFunctionalBase|sfTester
  40. */
  41. public function isFlash($key, $value)
  42. {
  43. $this->tester->is($this->user->getFlash($key), $value, sprintf('user flash "%s" is "%s"', $key, $value));
  44. return $this->getObjectToReturn();
  45. }
  46. /**
  47. * Tests the user culture.
  48. *
  49. * @param string $culture The user culture
  50. *
  51. * @return sfTestFunctionalBase|sfTester
  52. */
  53. public function isCulture($culture)
  54. {
  55. $this->tester->is($this->user->getCulture(), $culture, sprintf('user culture is "%s"', $culture));
  56. return $this->getObjectToReturn();
  57. }
  58. /**
  59. * Tests if the user is authenticated.
  60. *
  61. * @param Boolean $boolean Whether to check if the user is authenticated or not
  62. *
  63. * @return sfTestFunctionalBase|sfTester
  64. */
  65. public function isAuthenticated($boolean = true)
  66. {
  67. $this->tester->is($this->user->isAuthenticated(), $boolean, sprintf('user is %sauthenticated', $boolean ? '' : 'not '));
  68. return $this->getObjectToReturn();
  69. }
  70. /**
  71. * Tests if the user has some credentials.
  72. *
  73. * @param mixed $credentials
  74. * @param bool $boolean Whether to check if the user have some credentials or not
  75. * @param bool $useAnd specify the mode, either AND or OR
  76. *
  77. * @return sfTestFunctionalBase|sfTester
  78. */
  79. public function hasCredential($credentials, $boolean = true, $useAnd = true)
  80. {
  81. $this->tester->is($this->user->hasCredential($credentials, $useAnd), $boolean, sprintf('user has %sthe right credentials', $boolean ? '' : 'not '));
  82. return $this->getObjectToReturn();
  83. }
  84. }

Debug toolbar