123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- class sfTesterRequest extends sfTester
- {
- protected $request;
-
- public function prepare()
- {
- }
-
- public function initialize()
- {
- $this->request = $this->browser->getRequest();
- }
-
- public function isParameter($key, $value)
- {
- $this->tester->is($this->request->getParameter($key), $value, sprintf('request parameter "%s" is "%s"', $key, $value));
- return $this->getObjectToReturn();
- }
-
- public function isFormat($format)
- {
- $this->tester->is($this->request->getRequestFormat(), $format, sprintf('request format is "%s"', $format));
- return $this->getObjectToReturn();
- }
-
- public function isMethod($method)
- {
- $this->tester->ok($this->request->isMethod($method), sprintf('request method is "%s"', strtoupper($method)));
- return $this->getObjectToReturn();
- }
-
- public function hasCookie($name, $exists = true)
- {
- if (!array_key_exists($name, $_COOKIE))
- {
- if ($exists)
- {
- $this->tester->fail(sprintf('cookie "%s" exist.', $name));
- }
- else
- {
- $this->tester->pass(sprintf('cookie "%s" does not exist.', $name));
- }
- return $this->getObjectToReturn();
- }
- if ($exists)
- {
- $this->tester->pass(sprintf('cookie "%s" exists.', $name));
- }
- else
- {
- $this->tester->fail(sprintf('cookie "%s" does not exist.', $name));
- }
- return $this->getObjectToReturn();
- }
-
- public function isCookie($name, $value)
- {
- if (!array_key_exists($name, $_COOKIE))
- {
- $this->tester->fail(sprintf('cookie "%s" does not exist.', $name));
- return $this->getObjectToReturn();
- }
- if (preg_match('/^(!)?([^a-zA-Z0-9\\\\]).+?\\2[ims]?$/', $value, $match))
- {
- if ($match[1] == '!')
- {
- $this->tester->unlike($_COOKIE[$name], substr($value, 1), sprintf('cookie "%s" content does not match regex "%s"', $name, $value));
- }
- else
- {
- $this->tester->like($_COOKIE[$name], $value, sprintf('cookie "%s" content matches regex "%s"', $name, $value));
- }
- }
- else
- {
- $this->tester->is($_COOKIE[$name], $value, sprintf('cookie "%s" content is ok', $name));
- }
- return $this->getObjectToReturn();
- }
- }
|