Ver Fonte

added test for Cookie#getRawValue and CookieJar#AllRawValues

Yoshio HANAWA há 14 anos atrás
pai
commit
6556f62e4f

+ 16 - 0
tests/Symfony/Tests/Component/BrowserKit/CookieJarTest.php

@@ -95,4 +95,20 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase
             array('http://www.example.com/foo/bar', array('foo_nothing', 'foo_path', 'foo_domain')),
         );
     }
+
+    /**
+     * @dataProvider provideAllValuesValues
+     */
+    public function testAllRawValues($uri, $values)
+    {
+        $cookieJar = new CookieJar();
+        $cookieJar->set($cookie1 = new Cookie('foo_nothing', 'foo'));
+        $cookieJar->set($cookie2 = new Cookie('foo_expired', 'foo', time() - 86400));
+        $cookieJar->set($cookie3 = new Cookie('foo_path', 'foo', null, '/foo'));
+        $cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', 'example.com'));
+        $cookieJar->set($cookie5 = new Cookie('foo_secure', 'foo', null, '/', '', true));
+
+        $this->assertEquals($values, array_keys($cookieJar->allRawValues($uri)), '->allRawValues() returns the cookie for a given URI');
+    }
+
 }

+ 13 - 0
tests/Symfony/Tests/Component/BrowserKit/CookieTest.php

@@ -33,6 +33,8 @@ class CookieTest extends \PHPUnit_Framework_TestCase
             array('foo=bar; secure'),
             array('foo=bar; httponly'),
             array('foo=bar; domain=google.com; path=/foo; secure; httponly'),
+            array('foo=bar=baz'),
+            array('foo=bar%3Dbaz'),
         );
     }
 
@@ -70,6 +72,17 @@ class CookieTest extends \PHPUnit_Framework_TestCase
     {
         $cookie = new Cookie('foo', 'bar');
         $this->assertEquals('bar', $cookie->getValue(), '->getValue() returns the cookie value');
+
+        $cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true); // raw value
+        $this->assertEquals('bar=baz', $cookie->getValue(), '->getValue() returns the urldecoded cookie value');
+    }
+
+    public function testGetRawValue()
+    {
+        $cookie = new Cookie('foo', 'bar=baz'); // decoded value
+        $this->assertEquals('bar%3Dbaz', $cookie->getRawValue(), '->getRawValue() returns the urlencoded cookie value');
+        $cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true); // raw value
+        $this->assertEquals('bar%3Dbaz', $cookie->getRawValue(), '->getRawValue() returns the non-urldecoded cookie value');
     }
 
     public function testGetPath()