Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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
 * sfTesterRequest implements tests for the symfony request object.
13
 *
14
 * @package    symfony
15
 * @subpackage test
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfTesterRequest.class.php 27845 2010-02-10 19:46:03Z Kris.Wallsmith $
18
 */
19
class sfTesterRequest extends sfTester
20
{
21
  protected $request;
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->request = $this->browser->getRequest();
36
  }
37
 
38
  /**
39
   * Tests whether or not a given key and value exists in the request.
40
   *
41
   * @param string $key
42
   * @param string $value
43
   *
44
   * @return sfTestFunctionalBase|sfTester
45
   */
46
  public function isParameter($key, $value)
47
  {
48
    $this->tester->is($this->request->getParameter($key), $value, sprintf('request parameter "%s" is "%s"', $key, $value));
49
 
50
    return $this->getObjectToReturn();
51
  }
52
 
53
  /**
54
   * Tests for the request is in the given format.
55
   *
56
   * @param  string $format  The request format
57
   *
58
   * @return sfTestFunctionalBase|sfTester
59
   */
60
  public function isFormat($format)
61
  {
62
    $this->tester->is($this->request->getRequestFormat(), $format, sprintf('request format is "%s"', $format));
63
 
64
    return $this->getObjectToReturn();
65
  }
66
 
67
  /**
68
   * Tests if the current HTTP method matches the given one
69
   *
70
   * @param  string  $method  The HTTP method name
71
   *
72
   * @return sfTestFunctionalBase|sfTester
73
   */
74
  public function isMethod($method)
75
  {
76
    $this->tester->ok($this->request->isMethod($method), sprintf('request method is "%s"', strtoupper($method)));
77
 
78
    return $this->getObjectToReturn();
79
  }
80
 
81
  /**
82
   * Checks if a cookie exists.
83
   *
84
   * @param string  $name   The cookie name
85
   * @param Boolean $exists Whether the cookie must exist or not
86
   *
87
   * @return sfTestFunctionalBase|sfTester
88
   */
89
  public function hasCookie($name, $exists = true)
90
  {
91
    if (!array_key_exists($name, $_COOKIE))
92
    {
93
      if ($exists)
94
      {
95
        $this->tester->fail(sprintf('cookie "%s" exists.', $name));
96
      }
97
      else
98
      {
99
        $this->tester->pass(sprintf('cookie "%s" does not exist.', $name));
100
      }
101
 
102
      return $this->getObjectToReturn();
103
    }
104
 
105
    if ($exists)
106
    {
107
      $this->tester->pass(sprintf('cookie "%s" exists.', $name));
108
    }
109
    else
110
    {
111
      $this->tester->fail(sprintf('cookie "%s" does not exist.', $name));
112
    }
113
 
114
    return $this->getObjectToReturn();
115
  }
116
 
117
  /**
118
   * Checks the value of a cookie.
119
   *
120
   * @param string $name   The cookie name
121
   * @param mixed  $value  The expected value
122
   *
123
   * @return sfTestFunctionalBase|sfTester
124
   */
125
  public function isCookie($name, $value)
126
  {
127
    if (!array_key_exists($name, $_COOKIE))
128
    {
129
      $this->tester->fail(sprintf('cookie "%s" does not exist.', $name));
130
 
131
      return $this->getObjectToReturn();
132
    }
133
 
134
    if (preg_match('/^(!)?([^a-zA-Z0-9\\\\]).+?\\2[ims]?$/', $value, $match))
135
    {
136
      if ($match[1] == '!')
137
      {
138
        $this->tester->unlike($_COOKIE[$name], substr($value, 1), sprintf('cookie "%s" content does not match regex "%s"', $name, $value));
139
      }
140
      else
141
      {
142
        $this->tester->like($_COOKIE[$name], $value, sprintf('cookie "%s" content matches regex "%s"', $name, $value));
143
      }
144
    }
145
    else
146
    {
147
      $this->tester->is($_COOKIE[$name], $value, sprintf('cookie "%s" content is ok', $name));
148
    }
149
 
150
    return $this->getObjectToReturn();
151
  }
152
}