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