Development

/branches/1.3/test/functional/sfTestBrowserTest.php

You must first sign up to be able to contribute.

root/branches/1.3/test/functional/sfTestBrowserTest.php

Revision 24992, 6.3 kB (checked in by Kris.Wallsmith, 3 years ago)

[1.3, 1.4] added test coverage for testing browser redirects (refs #7823)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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 $app = 'frontend';
12 if (!include(dirname(__FILE__).'/../bootstrap/functional.php'))
13 {
14   return;
15 }
16
17 class TestBrowser extends sfTestBrowser
18 {
19   public $events = array();
20   public function listen(sfEvent $event)
21   {
22     $this->events[] = $event;
23   }
24 }
25
26 $b = new TestBrowser();
27 $b->addListener('context.load_factories', array($b, 'listen'));
28
29 // listeners
30 $b->get('/');
31 $b->test()->is(count($b->events), 1, 'browser can connect to context.load_factories');
32
33 // exceptions
34 $b->
35   get('/exception/noException')->
36   with('request')->begin()->
37     isParameter('module', 'exception')->
38     isParameter('action', 'noException')->
39   end()->
40
41   with('response')->begin()->
42     isStatusCode(200)->
43     matches('/foo/')->
44   end()->
45
46   get('/exception/throwsException')->
47   with('request')->begin()->
48     isParameter('module', 'exception')->
49     isParameter('action', 'throwsException')->
50   end()->
51   with('response')->isStatusCode(500)->
52   throwsException('Exception')->
53
54   get('/exception/throwsException')->
55   with('request')->begin()->
56     isParameter('module', 'exception')->
57     isParameter('action', 'throwsException')->
58   end()->
59   with('response')->isStatusCode(500)->
60   throwsException('Exception', '/Exception message/')->
61
62   get('/exception/throwsException')->
63   with('request')->begin()->
64     isParameter('module', 'exception')->
65     isParameter('action', 'throwsException')->
66   end()->
67   with('response')->isStatusCode(500)->
68   throwsException('Exception', '/message/')->
69
70   get('/exception/throwsException')->
71   with('request')->begin()->
72     isParameter('module', 'exception')->
73     isParameter('action', 'throwsException')->
74   end()->
75   with('response')->isStatusCode(500)->
76   throwsException(null, '!/sfException/')->
77
78   get('/exception/throwsSfException')->
79   with('request')->begin()->
80     isParameter('module', 'exception')->
81     isParameter('action', 'throwsSfException')->
82   end()->
83   with('response')->isStatusCode(500)->
84   throwsException('sfException')->
85
86   get('/exception/throwsSfException')->
87   with('request')->begin()->
88     isParameter('module', 'exception')->
89     isParameter('action', 'throwsSfException')->
90   end()->
91   with('response')->isStatusCode(500)->
92   throwsException('sfException', 'sfException message')
93 ;
94
95 $b->
96   get('/browser')->
97   with('response')->begin()->
98     matches('/html/')->
99     checkElement('h1', 'html')->
100   end()->
101
102   get('/browser/text')->
103   with('response')->begin()->
104     matches('/text/')->
105   end()
106 ;
107
108 try
109 {
110   $b->with('response')->checkElement('h1', 'text');
111   $b->test()->fail('The DOM is not accessible if the response content type is not HTML');
112 }
113 catch (LogicException $e)
114 {
115   $b->test()->pass('The DOM is not accessible if the response content type is not HTML');
116 }
117
118 // check response headers
119 $b->
120   get('/browser/responseHeader')->
121   with('response')->begin()->
122     isStatusCode()->
123     isHeader('content-type', 'text/plain; charset=utf-8')->
124     isHeader('content-type', '#text/plain#')->
125     isHeader('content-type', '!#text/html#')->
126     isHeader('foo', 'bar')->
127     isHeader('foo', 'foobar')->
128   end()
129 ;
130
131 // cookies
132 $b->
133   setCookie('foo', 'bar')->
134   setCookie('bar', 'foo')->
135   setCookie('foofoo', 'foo', time() - 10)->
136
137   get('/cookie')->
138   with('request')->begin()->
139     hasCookie('foofoo', false)->
140     hasCookie('foo')->
141     isCookie('foo', 'bar')->
142     isCookie('foo', '/a/')->
143     isCookie('foo', '!/z/')->
144   end()->
145   with('response')->checkElement('p', 'bar.foo-')->
146   get('/cookie')->
147   with('request')->begin()->
148     hasCookie('foo')->
149     isCookie('foo', 'bar')->
150     isCookie('foo', '/a/')->
151     isCookie('foo', '!/z/')->
152   end()->
153   with('response')->checkElement('p', 'bar.foo-')->
154   removeCookie('foo')->
155   get('/cookie')->
156   with('request')->begin()->
157     hasCookie('foo', false)->
158     hasCookie('bar')->
159   end()->
160   with('response')->checkElement('p', '.foo-')->
161   clearCookies()->
162   get('/cookie')->
163   with('request')->begin()->
164     hasCookie('foo', false)->
165     hasCookie('bar', false)->
166   end()->
167   with('response')->checkElement('p', '.-')
168 ;
169
170 $b->
171   setCookie('foo', 'bar')->
172   setCookie('bar', 'foo')->
173
174   get('/cookie/setCookie')->
175
176   get('/cookie')->
177   with('request')->begin()->
178     hasCookie('foo')->
179     isCookie('foo', 'bar')->
180     isCookie('foo', '/a/')->
181     isCookie('foo', '!/z/')->
182   end()->
183   with('response')->checkElement('p', 'bar.foo-barfoo')->
184   get('/cookie')->
185   with('request')->begin()->
186     hasCookie('foo')->
187     isCookie('foo', 'bar')->
188     isCookie('foo', '/a/')->
189     isCookie('foo', '!/z/')->
190   end()->
191   with('response')->checkElement('p', 'bar.foo-barfoo')->
192   removeCookie('foo')->
193   get('/cookie')->
194   with('request')->begin()->
195     hasCookie('foo', false)->
196     hasCookie('bar')->
197   end()->
198   with('response')->checkElement('p', '.foo-barfoo')->
199
200   get('/cookie/removeCookie')->
201
202   get('/cookie')->
203   with('request')->begin()->
204     hasCookie('foo', false)->
205     hasCookie('bar')->
206   end()->
207   with('response')->checkElement('p', '.foo-')->
208
209   get('/cookie/setCookie')->
210
211   clearCookies()->
212   get('/cookie')->
213   with('request')->begin()->
214     hasCookie('foo', false)->
215     hasCookie('bar', false)->
216   end()->
217   with('response')->checkElement('p', '.-')
218 ;
219
220 $b->
221   get('/browser')->
222   with('request')->isMethod('get')->
223   post('/browser')->
224   with('request')->isMethod('post')->
225   call('/browser', 'put')->
226   with('request')->isMethod('put')
227 ;
228
229 // sfBrowser: clean the custom view templates
230 $b->
231   get('/browser/templateCustom')->
232   with('response')->checkElement('#test', 'template')->
233
234   get('/browser/templateCustom/custom/1')->
235   with('response')->checkElement('#test', 'template 1')->
236
237   get('/browser/templateCustom')->
238   with('response')->checkElement('#test', 'template')
239 ;
240
241 $b
242   ->getAndCheck('browser', 'redirect1', null, 302)
243
244   ->followRedirect()
245
246   ->with('request')->begin()
247     ->isParameter('module', 'browser')
248     ->isParameter('action', 'redirectTarget1')
249   ->end()
250
251   ->with('response')->isStatusCode(200)
252
253   ->getAndCheck('browser', 'redirect2', null, 302)
254
255   ->followRedirect()
256
257   ->with('request')->begin()
258     ->isParameter('module', 'browser')
259     ->isParameter('action', 'redirectTarget2')
260   ->end()
261
262   ->with('response')->isStatusCode(200)
263 ;
264
Note: See TracBrowser for help on using the browser.