Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Symfony\Component\HttpFoundation\Tests; use Symfony\Component\HttpFoundat..

Decoded Output download

<?php
 namespace Symfony\Component\HttpFoundation\Tests; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class ResponseTest extends ResponseTestCase { public function testToString() { $response = new Response(); $response = explode("\xd\xa", $response); $this->assertEquals("HTTP/1.0 200 OK", $response[0]); $this->assertEquals("Cache-Control: no-cache, private", $response[1]); } public function testClone() { $response = new Response(); $responseClone = clone $response; $this->assertEquals($response, $responseClone); } public function testSendHeaders() { $response = new Response(); $headers = $response->sendHeaders(); $this->assertSame($response, $headers); } public function testSendInformationalResponse() { $response = new Response(); $response->sendHeaders(103); $this->assertSame(200, $response->getStatusCode()); $response->sendHeaders(); } public function testSend() { $response = new Response(); $responseSend = $response->send(); $this->assertSame($response, $responseSend); } public function testGetCharset() { $response = new Response(); $charsetOrigin = "UTF-8"; $response->setCharset($charsetOrigin); $charset = $response->getCharset(); $this->assertEquals($charsetOrigin, $charset); } public function testIsCacheable() { $response = new Response(); $this->assertFalse($response->isCacheable()); } public function testIsCacheableWithErrorCode() { $response = new Response('', 500); $this->assertFalse($response->isCacheable()); } public function testIsCacheableWithNoStoreDirective() { $response = new Response(); $response->headers->set("cache-control", "private"); $this->assertFalse($response->isCacheable()); } public function testIsCacheableWithSetTtl() { $response = new Response(); $response->setTtl(10); $this->assertTrue($response->isCacheable()); } public function testMustRevalidate() { $response = new Response(); $this->assertFalse($response->mustRevalidate()); } public function testMustRevalidateWithMustRevalidateCacheControlHeader() { $response = new Response(); $response->headers->set("cache-control", "must-revalidate"); $this->assertTrue($response->mustRevalidate()); } public function testMustRevalidateWithProxyRevalidateCacheControlHeader() { $response = new Response(); $response->headers->set("cache-control", "proxy-revalidate"); $this->assertTrue($response->mustRevalidate()); } public function testSetNotModified() { $response = new Response("foo"); $modified = $response->setNotModified(); $this->assertSame($response, $modified); $this->assertEquals(304, $modified->getStatusCode()); ob_start(); $modified->sendContent(); $string = ob_get_clean(); $this->assertEmpty($string); } public function testIsSuccessful() { $response = new Response(); $this->assertTrue($response->isSuccessful()); } public function testIsNotModified() { $response = new Response(); $modified = $response->isNotModified(new Request()); $this->assertFalse($modified); } public function testIsNotModifiedNotSafe() { $request = Request::create("/homepage", "POST"); $response = new Response(); $this->assertFalse($response->isNotModified($request)); } public function testIsNotModifiedLastModified() { $before = "Sun, 25 Aug 2013 18:32:31 GMT"; $modified = "Sun, 25 Aug 2013 18:33:31 GMT"; $after = "Sun, 25 Aug 2013 19:33:31 GMT"; $request = new Request(); $request->headers->set("If-Modified-Since", $modified); $response = new Response(); $response->headers->set("Last-Modified", $modified); $this->assertTrue($response->isNotModified($request)); $response->headers->set("Last-Modified", $before); $this->assertTrue($response->isNotModified($request)); $response->headers->set("Last-Modified", $after); $this->assertFalse($response->isNotModified($request)); $response->headers->set("Last-Modified", ''); $this->assertFalse($response->isNotModified($request)); } public function testIsNotModifiedEtag() { $etagOne = "randomly_generated_etag"; $etagTwo = "randomly_generated_etag_2"; $request = new Request(); $request->headers->set("If-None-Match", sprintf("%s, %s, %s", $etagOne, $etagTwo, "etagThree")); $response = new Response(); $response->headers->set("ETag", $etagOne); $this->assertTrue($response->isNotModified($request)); $response->headers->set("ETag", $etagTwo); $this->assertTrue($response->isNotModified($request)); $response->headers->set("ETag", ''); $this->assertFalse($response->isNotModified($request)); $request = new Request(); $request->headers->set("If-None-Match", "*"); $response->headers->set("ETag", $etagOne); $this->assertTrue($response->isNotModified($request)); } public function testIsNotModifiedWeakEtag() { $etag = "randomly_generated_etag"; $weakEtag = "W/randomly_generated_etag"; $request = new Request(); $request->headers->set("If-None-Match", $etag); $response = new Response(); $response->headers->set("ETag", $etag); $this->assertTrue($response->isNotModified($request)); $response->headers->set("ETag", $weakEtag); $this->assertTrue($response->isNotModified($request)); $request->headers->set("If-None-Match", $weakEtag); $response = new Response(); $response->headers->set("ETag", $etag); $this->assertTrue($response->isNotModified($request)); $response->headers->set("ETag", $weakEtag); $this->assertTrue($response->isNotModified($request)); } public function testIsNotModifiedLastModifiedAndEtag() { $before = "Sun, 25 Aug 2013 18:32:31 GMT"; $modified = "Sun, 25 Aug 2013 18:33:31 GMT"; $after = "Sun, 25 Aug 2013 19:33:31 GMT"; $etag = "randomly_generated_etag"; $request = new Request(); $request->headers->set("If-None-Match", sprintf("%s, %s", $etag, "etagThree")); $request->headers->set("If-Modified-Since", $modified); $response = new Response(); $response->headers->set("ETag", $etag); $response->headers->set("Last-Modified", $after); $this->assertTrue($response->isNotModified($request)); $response->headers->set("ETag", "non-existent-etag"); $response->headers->set("Last-Modified", $before); $this->assertFalse($response->isNotModified($request)); $response->headers->set("ETag", $etag); $response->headers->set("Last-Modified", $modified); $this->assertTrue($response->isNotModified($request)); } public function testIsNotModifiedIfModifiedSinceAndEtagWithoutLastModified() { $modified = "Sun, 25 Aug 2013 18:33:31 GMT"; $etag = "randomly_generated_etag"; $request = new Request(); $request->headers->set("If-None-Match", sprintf("%s, %s", $etag, "etagThree")); $request->headers->set("If-Modified-Since", $modified); $response = new Response(); $response->headers->set("ETag", $etag); $this->assertTrue($response->isNotModified($request)); $response->headers->set("ETag", "non-existent-etag"); $this->assertFalse($response->isNotModified($request)); } public function testIfNoneMatchWithoutETag() { $request = new Request(); $request->headers->set("If-None-Match", "randomly_generated_etag"); $this->assertFalse((new Response())->isNotModified($request)); $request = new Request(); $request->headers->set("If-None-Match", "*"); $this->assertFalse((new Response())->isNotModified($request)); } public function testIsValidateable() { $response = new Response('', 200, array("Last-Modified" => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822))); $this->assertTrue($response->isValidateable(), "->isValidateable() returns true if Last-Modified is present"); $response = new Response('', 200, array("ETag" => ""12345"")); $this->assertTrue($response->isValidateable(), "->isValidateable() returns true if ETag is present"); $response = new Response(); $this->assertFalse($response->isValidateable(), "->isValidateable() returns false when no validator is present"); } public function testGetDate() { $oneHourAgo = $this->createDateTimeOneHourAgo(); $response = new Response('', 200, array("Date" => $oneHourAgo->format(\DATE_RFC2822))); $date = $response->getDate(); $this->assertEquals($oneHourAgo->getTimestamp(), $date->getTimestamp(), "->getDate() returns the Date header if present"); $response = new Response(); $date = $response->getDate(); $this->assertEquals(time(), $date->getTimestamp(), "->getDate() returns the current Date if no Date header present"); $response = new Response('', 200, array("Date" => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822))); $now = $this->createDateTimeNow(); $response->headers->set("Date", $now->format(\DATE_RFC2822)); $date = $response->getDate(); $this->assertEquals($now->getTimestamp(), $date->getTimestamp(), "->getDate() returns the date when the header has been modified"); $response = new Response('', 200); $now = $this->createDateTimeNow(); $response->headers->remove("Date"); $date = $response->getDate(); $this->assertEquals($now->getTimestamp(), $date->getTimestamp(), "->getDate() returns the current Date when the header has previously been removed"); } public function testGetMaxAge() { $response = new Response(); $response->headers->set("Cache-Control", "s-maxage=600, max-age=0"); $this->assertEquals(600, $response->getMaxAge(), "->getMaxAge() uses s-maxage cache control directive when present"); $response = new Response(); $response->headers->set("Cache-Control", "max-age=600"); $this->assertEquals(600, $response->getMaxAge(), "->getMaxAge() falls back to max-age when no s-maxage directive present"); $response = new Response(); $response->headers->set("Cache-Control", "must-revalidate"); $response->headers->set("Expires", $this->createDateTimeOneHourLater()->format(\DATE_RFC2822)); $this->assertEquals(3600, $response->getMaxAge(), "->getMaxAge() falls back to Expires when no max-age or s-maxage directive present"); $response = new Response(); $response->headers->set("Expires", -1); $this->assertSame(0, $response->getMaxAge()); $response = new Response(); $this->assertNull($response->getMaxAge(), "->getMaxAge() returns null if no freshness information available"); } public function testSetSharedMaxAge() { $response = new Response(); $response->setSharedMaxAge(20); $cacheControl = $response->headers->get("Cache-Control"); $this->assertEquals("public, s-maxage=20", $cacheControl); } public function testSetStaleIfError() { $response = new Response(); $response->setSharedMaxAge(20); $response->setStaleIfError(86400); $cacheControl = $response->headers->get("Cache-Control"); $this->assertEquals("public, s-maxage=20, stale-if-error=86400", $cacheControl); } public function testSetStaleWhileRevalidate() { $response = new Response(); $response->setSharedMaxAge(20); $response->setStaleWhileRevalidate(300); $cacheControl = $response->headers->get("Cache-Control"); $this->assertEquals("public, s-maxage=20, stale-while-revalidate=300", $cacheControl); } public function testSetStaleIfErrorWithoutSharedMaxAge() { $response = new Response(); $response->setStaleIfError(86400); $cacheControl = $response->headers->get("Cache-Control"); $this->assertEquals("stale-if-error=86400, private", $cacheControl); } public function testSetStaleWhileRevalidateWithoutSharedMaxAge() { $response = new Response(); $response->setStaleWhileRevalidate(300); $cacheControl = $response->headers->get("Cache-Control"); $this->assertEquals("stale-while-revalidate=300, private", $cacheControl); } public function testIsPrivate() { $response = new Response(); $response->headers->set("Cache-Control", "max-age=100"); $response->setPrivate(); $this->assertEquals(100, $response->headers->getCacheControlDirective("max-age"), "->isPrivate() adds the private Cache-Control directive when set to true"); $this->assertTrue($response->headers->getCacheControlDirective("private"), "->isPrivate() adds the private Cache-Control directive when set to true"); $response = new Response(); $response->headers->set("Cache-Control", "public, max-age=100"); $response->setPrivate(); $this->assertEquals(100, $response->headers->getCacheControlDirective("max-age"), "->isPrivate() adds the private Cache-Control directive when set to true"); $this->assertTrue($response->headers->getCacheControlDirective("private"), "->isPrivate() adds the private Cache-Control directive when set to true"); $this->assertFalse($response->headers->hasCacheControlDirective("public"), "->isPrivate() removes the public Cache-Control directive"); } public function testExpire() { $response = new Response(); $response->headers->set("Cache-Control", "max-age=100"); $response->expire(); $this->assertEquals(100, $response->headers->get("Age"), "->expire() sets the Age to max-age when present"); $response = new Response(); $response->headers->set("Cache-Control", "max-age=100, s-maxage=500"); $response->expire(); $this->assertEquals(500, $response->headers->get("Age"), "->expire() sets the Age to s-maxage when both max-age and s-maxage are present"); $response = new Response(); $response->headers->set("Cache-Control", "max-age=5, s-maxage=500"); $response->headers->set("Age", "1000"); $response->expire(); $this->assertEquals(1000, $response->headers->get("Age"), "->expire() does nothing when the response is already stale/expired"); $response = new Response(); $response->expire(); $this->assertFalse($response->headers->has("Age"), "->expire() does nothing when the response does not include freshness information"); $response = new Response(); $response->headers->set("Expires", -1); $response->expire(); $this->assertNull($response->headers->get("Age"), "->expire() does not set the Age when the response is expired"); $response = new Response(); $response->headers->set("Expires", date(\DATE_RFC2822, time() + 600)); $response->expire(); $this->assertNull($response->headers->get("Expires"), "->expire() removes the Expires header when the response is fresh"); } public function testNullExpireHeader() { $response = new Response(null, 200, array("Expires" => null)); $this->assertNull($response->getExpires()); } public function testGetTtl() { $response = new Response(); $this->assertNull($response->getTtl(), "->getTtl() returns null when no Expires or Cache-Control headers are present"); $response = new Response(); $response->headers->set("Expires", $this->createDateTimeOneHourLater()->format(\DATE_RFC2822)); $this->assertEquals(3600, $response->getTtl(), "->getTtl() uses the Expires header when no max-age is present"); $response = new Response(); $response->headers->set("Expires", $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)); $this->assertSame(0, $response->getTtl(), "->getTtl() returns zero when Expires is in past"); $response = new Response(); $response->headers->set("Expires", $response->getDate()->format(\DATE_RFC2822)); $response->headers->set("Age", 0); $this->assertSame(0, $response->getTtl(), "->getTtl() correctly handles zero"); $response = new Response(); $response->headers->set("Cache-Control", "max-age=60"); $this->assertEquals(60, $response->getTtl(), "->getTtl() uses Cache-Control max-age when present"); } public function testSetClientTtl() { $response = new Response(); $response->setClientTtl(10); $this->assertEquals($response->getMaxAge(), $response->getAge() + 10); } public function testGetSetProtocolVersion() { $response = new Response(); $this->assertEquals("1.0", $response->getProtocolVersion()); $response->setProtocolVersion("1.1"); $this->assertEquals("1.1", $response->getProtocolVersion()); } public function testGetVary() { $response = new Response(); $this->assertEquals(array(), $response->getVary(), "->getVary() returns an empty array if no Vary header is present"); $response = new Response(); $response->headers->set("Vary", "Accept-Language"); $this->assertEquals(array("Accept-Language"), $response->getVary(), "->getVary() parses a single header name value"); $response = new Response(); $response->headers->set("Vary", "Accept-Language User-Agent    X-Foo"); $this->assertEquals(array("Accept-Language", "User-Agent", "X-Foo"), $response->getVary(), "->getVary() parses multiple header name values separated by spaces"); $response = new Response(); $response->headers->set("Vary", "Accept-Language,User-Agent,    X-Foo"); $this->assertEquals(array("Accept-Language", "User-Agent", "X-Foo"), $response->getVary(), "->getVary() parses multiple header name values separated by commas"); $vary = array("Accept-Language", "User-Agent", "X-foo"); $response = new Response(); $response->headers->set("Vary", $vary); $this->assertEquals($vary, $response->getVary(), "->getVary() parses multiple header name values in arrays"); $response = new Response(); $response->headers->set("Vary", "Accept-Language, User-Agent, X-foo"); $this->assertEquals($vary, $response->getVary(), "->getVary() parses multiple header name values in arrays"); } public function testSetVary() { $response = new Response(); $response->setVary("Accept-Language"); $this->assertEquals(array("Accept-Language"), $response->getVary()); $response->setVary("Accept-Language, User-Agent"); $this->assertEquals(array("Accept-Language", "User-Agent"), $response->getVary(), "->setVary() replace the vary header by default"); $response->setVary("X-Foo", false); $this->assertEquals(array("Accept-Language", "User-Agent", "X-Foo"), $response->getVary(), "->setVary() doesn't wipe out earlier Vary headers if replace is set to false"); } public function testDefaultContentType() { $response = new Response("foo"); $response->prepare(new Request()); $this->assertSame("text/html; charset=UTF-8", $response->headers->get("Content-Type")); } public function testContentTypeCharset() { $response = new Response(); $response->headers->set("Content-Type", "text/css"); $response->prepare(new Request()); $this->assertEquals("text/css; charset=UTF-8", $response->headers->get("Content-Type")); } public function testContentTypeIsNull() { $response = new Response("foo"); $response->headers->set("Content-Type", null); $response->prepare(new Request()); $this->expectNotToPerformAssertions(); } public function testPrepareDoesNothingIfContentTypeIsSet() { $response = new Response("foo"); $response->headers->set("Content-Type", "text/plain"); $response->prepare(new Request()); $this->assertEquals("text/plain; charset=UTF-8", $response->headers->get("content-type")); } public function testPrepareDoesNothingIfRequestFormatIsNotDefined() { $response = new Response("foo"); $response->prepare(new Request()); $this->assertEquals("text/html; charset=UTF-8", $response->headers->get("content-type")); } public function testPrepareDoesNotSetContentTypeBasedOnRequestAcceptHeader() { $response = new Response("foo"); $request = Request::create("/"); $request->headers->set("Accept", "application/json"); $response->prepare($request); $this->assertSame("text/html; charset=UTF-8", $response->headers->get("content-type")); } public function testPrepareSetContentType() { $response = new Response("foo"); $request = Request::create("/"); $request->setRequestFormat("json"); $response->prepare($request); $this->assertEquals("application/json", $response->headers->get("content-type")); } public function testPrepareRemovesContentForHeadRequests() { $response = new Response("foo"); $request = Request::create("/", "HEAD"); $length = 12345; $response->headers->set("Content-Length", $length); $response->prepare($request); $this->assertEquals('', $response->getContent()); $this->assertEquals($length, $response->headers->get("Content-Length"), "Content-Length should be as if it was GET; see RFC2616 14.13"); } public function testPrepareRemovesContentForInformationalResponse() { $response = new Response("foo"); $request = Request::create("/"); $response->setContent("content"); $response->setStatusCode(101); $response->prepare($request); $this->assertEquals('', $response->getContent()); $this->assertFalse($response->headers->has("Content-Type")); $response->setContent("content"); $response->setStatusCode(304); $response->prepare($request); $this->assertEquals('', $response->getContent()); $this->assertFalse($response->headers->has("Content-Type")); $this->assertFalse($response->headers->has("Content-Length")); } public function testPrepareRemovesContentLength() { $response = new Response("foo"); $request = Request::create("/"); $response->headers->set("Content-Length", 12345); $response->prepare($request); $this->assertEquals(12345, $response->headers->get("Content-Length")); $response->headers->set("Transfer-Encoding", "chunked"); $response->prepare($request); $this->assertFalse($response->headers->has("Content-Length")); } public function testPrepareSetsPragmaOnHttp10Only() { $request = Request::create("/", "GET"); $request->server->set("SERVER_PROTOCOL", "HTTP/1.0"); $response = new Response("foo"); $response->prepare($request); $this->assertEquals("no-cache", $response->headers->get("pragma")); $this->assertEquals("-1", $response->headers->get("expires")); $response = new Response("foo"); $response->headers->remove("cache-control"); $response->prepare($request); $this->assertFalse($response->headers->has("pragma")); $this->assertFalse($response->headers->has("expires")); $request->server->set("SERVER_PROTOCOL", "HTTP/1.1"); $response = new Response("foo"); $response->prepare($request); $this->assertFalse($response->headers->has("pragma")); $this->assertFalse($response->headers->has("expires")); } public function testPrepareSetsCookiesSecure() { $cookie = Cookie::create("foo", "bar"); $response = new Response("foo"); $response->headers->setCookie($cookie); $request = Request::create("/", "GET"); $response->prepare($request); $this->assertFalse($cookie->isSecure()); $request = Request::create("https://localhost/", "GET"); $response->prepare($request); $this->assertTrue($cookie->isSecure()); } public function testSetCache() { $response = new Response(); try { $response->setCache(array("wrong option" => "value")); $this->fail("->setCache() throws an InvalidArgumentException if an option is not supported"); } catch (\Exception $e) { $this->assertInstanceOf(\InvalidArgumentException::class, $e, "->setCache() throws an InvalidArgumentException if an option is not supported"); $this->assertStringContainsString(""wrong option"", $e->getMessage()); } $options = array("etag" => ""whatever""); $response->setCache($options); $this->assertEquals(""whatever"", $response->getEtag()); $now = $this->createDateTimeNow(); $options = array("last_modified" => $now); $response->setCache($options); $this->assertEquals($now->getTimestamp(), $response->getLastModified()->getTimestamp()); $options = array("max_age" => 100); $response->setCache($options); $this->assertEquals(100, $response->getMaxAge()); $options = array("s_maxage" => 200); $response->setCache($options); $this->assertEquals(200, $response->getMaxAge()); $this->assertTrue($response->headers->hasCacheControlDirective("public")); $this->assertFalse($response->headers->hasCacheControlDirective("private")); $response->setCache(array("public" => true)); $this->assertTrue($response->headers->hasCacheControlDirective("public")); $this->assertFalse($response->headers->hasCacheControlDirective("private")); $response->setCache(array("public" => false)); $this->assertFalse($response->headers->hasCacheControlDirective("public")); $this->assertTrue($response->headers->hasCacheControlDirective("private")); $response->setCache(array("private" => true)); $this->assertFalse($response->headers->hasCacheControlDirective("public")); $this->assertTrue($response->headers->hasCacheControlDirective("private")); $response->setCache(array("private" => false)); $this->assertTrue($response->headers->hasCacheControlDirective("public")); $this->assertFalse($response->headers->hasCacheControlDirective("private")); $response->setCache(array("immutable" => true)); $this->assertTrue($response->headers->hasCacheControlDirective("immutable")); $response->setCache(array("immutable" => false)); $this->assertFalse($response->headers->hasCacheControlDirective("immutable")); $directives = array("proxy_revalidate", "must_revalidate", "no_cache", "no_store", "no_transform"); foreach ($directives as $directive) { $response->setCache(array($directive => true)); $this->assertTrue($response->headers->hasCacheControlDirective(str_replace("_", "-", $directive))); } foreach ($directives as $directive) { $response->setCache(array($directive => false)); $this->assertFalse($response->headers->hasCacheControlDirective(str_replace("_", "-", $directive))); } $response = new DefaultResponse(); $options = array("etag" => ""whatever""); $response->setCache($options); $this->assertSame($response->getEtag(), ""whatever""); } public function testSendContent() { $response = new Response("test response rendering", 200); ob_start(); $response->sendContent(); $string = ob_get_clean(); $this->assertStringContainsString("test response rendering", $string); } public function testSetPublic() { $response = new Response(); $response->setPublic(); $this->assertTrue($response->headers->hasCacheControlDirective("public")); $this->assertFalse($response->headers->hasCacheControlDirective("private")); } public function testSetImmutable() { $response = new Response(); $response->setImmutable(); $this->assertTrue($response->headers->hasCacheControlDirective("immutable")); } public function testIsImmutable() { $response = new Response(); $response->setImmutable(); $this->assertTrue($response->isImmutable()); } public function testSetDate() { $response = new Response(); $response->setDate(\DateTime::createFromFormat(\DateTimeInterface::ATOM, "2013-01-26T09:21:56+0100", new \DateTimeZone("Europe/Berlin"))); $this->assertEquals("2013-01-26T08:21:56+00:00", $response->getDate()->format(\DateTimeInterface::ATOM)); } public function testSetDateWithImmutable() { $response = new Response(); $response->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, "2013-01-26T09:21:56+0100", new \DateTimeZone("Europe/Berlin"))); $this->assertEquals("2013-01-26T08:21:56+00:00", $response->getDate()->format(\DateTimeInterface::ATOM)); } public function testSetExpires() { $response = new Response(); $response->setExpires(null); $this->assertNull($response->getExpires(), "->setExpires() remove the header when passed null"); $now = $this->createDateTimeNow(); $response->setExpires($now); $this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp()); } public function testSetExpiresWithImmutable() { $response = new Response(); $now = $this->createDateTimeImmutableNow(); $response->setExpires($now); $this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp()); } public function testSetLastModified() { $response = new Response(); $response->setLastModified($this->createDateTimeNow()); $this->assertNotNull($response->getLastModified()); $response->setLastModified(null); $this->assertNull($response->getLastModified()); } public function testSetLastModifiedWithImmutable() { $response = new Response(); $response->setLastModified($this->createDateTimeImmutableNow()); $this->assertNotNull($response->getLastModified()); $response->setLastModified(null); $this->assertNull($response->getLastModified()); } public function testIsInvalid() { $response = new Response(); try { $response->setStatusCode(99); $this->fail(); } catch (\InvalidArgumentException $e) { $this->assertTrue($response->isInvalid()); } try { $response->setStatusCode(650); $this->fail(); } catch (\InvalidArgumentException $e) { $this->assertTrue($response->isInvalid()); } $response = new Response('', 200); $this->assertFalse($response->isInvalid()); } public function testSetStatusCode($code, $text, $expectedText) { $response = new Response(); $response->setStatusCode($code, $text); $statusText = new \ReflectionProperty($response, "statusText"); $this->assertEquals($expectedText, $statusText->getValue($response)); } public static function getStatusCodeFixtures() { return array(array("200", null, "OK"), array("200", false, ''), array("200", "foo", "foo"), array("199", null, "unknown status"), array("199", false, ''), array("199", "foo", "foo")); } public function testIsInformational() { $response = new Response('', 100); $this->assertTrue($response->isInformational()); $response = new Response('', 200); $this->assertFalse($response->isInformational()); } public function testIsRedirectRedirection() { foreach (array(301, 302, 303, 307) as $code) { $response = new Response('', $code); $this->assertTrue($response->isRedirection()); $this->assertTrue($response->isRedirect()); } $response = new Response('', 304); $this->assertTrue($response->isRedirection()); $this->assertFalse($response->isRedirect()); $response = new Response('', 200); $this->assertFalse($response->isRedirection()); $this->assertFalse($response->isRedirect()); $response = new Response('', 404); $this->assertFalse($response->isRedirection()); $this->assertFalse($response->isRedirect()); $response = new Response('', 301, array("Location" => "/good-uri")); $this->assertFalse($response->isRedirect("/bad-uri")); $this->assertTrue($response->isRedirect("/good-uri")); } public function testIsNotFound() { $response = new Response('', 404); $this->assertTrue($response->isNotFound()); $response = new Response('', 200); $this->assertFalse($response->isNotFound()); } public function testIsEmpty() { foreach (array(204, 304) as $code) { $response = new Response('', $code); $this->assertTrue($response->isEmpty()); } $response = new Response('', 200); $this->assertFalse($response->isEmpty()); } public function testIsForbidden() { $response = new Response('', 403); $this->assertTrue($response->isForbidden()); $response = new Response('', 200); $this->assertFalse($response->isForbidden()); } public function testIsOk() { $response = new Response('', 200); $this->assertTrue($response->isOk()); $response = new Response('', 404); $this->assertFalse($response->isOk()); } public function testIsServerOrClientError() { $response = new Response('', 404); $this->assertTrue($response->isClientError()); $this->assertFalse($response->isServerError()); $response = new Response('', 500); $this->assertFalse($response->isClientError()); $this->assertTrue($response->isServerError()); } public function testHasVary() { $response = new Response(); $this->assertFalse($response->hasVary()); $response->setVary("User-Agent"); $this->assertTrue($response->hasVary()); } public function testSetEtag() { $response = new Response('', 200, array("ETag" => ""12345"")); $response->setEtag(null); $this->assertNull($response->headers->get("Etag"), "->setEtag() removes Etags when call with null"); } public function testSetContent($content) { $response = new Response(); $response->setContent($content); $this->assertEquals((string) $content, $response->getContent()); } public function testSettersAreChainable() { $response = new Response(); $setters = array("setProtocolVersion" => "1.0", "setCharset" => "UTF-8", "setPublic" => null, "setPrivate" => null, "setDate" => $this->createDateTimeNow(), "expire" => null, "setMaxAge" => 1, "setSharedMaxAge" => 1, "setTtl" => 1, "setClientTtl" => 1); foreach ($setters as $setter => $arg) { $this->assertEquals($response, $response->{$setter}($arg)); } } public function testNoDeprecationsAreTriggered() { new DefaultResponse(); $this->createMock(Response::class); $this->addToAssertionCount(1); } public static function validContentProvider() { return array("obj" => array(new StringableObject()), "string" => array("Foo"), "int" => array(2)); } protected function createDateTimeOneHourAgo() { return $this->createDateTimeNow()->sub(new \DateInterval("PT1H")); } protected function createDateTimeOneHourLater() { return $this->createDateTimeNow()->add(new \DateInterval("PT1H")); } protected function createDateTimeNow() { $date = new \DateTime(); return $date->setTimestamp(time()); } protected function createDateTimeImmutableNow() { $date = new \DateTimeImmutable(); return $date->setTimestamp(time()); } protected function provideResponse() { return new Response(); } public static function ianaCodesReasonPhrasesProvider() { $ianaHttpStatusCodes = new \DOMDocument(); $ianaHttpStatusCodes->load(__DIR__ . "/Fixtures/xml/http-status-codes.xml"); if (!$ianaHttpStatusCodes->relaxNGValidate(__DIR__ . "/schema/http-status-codes.rng")) { self::fail("Invalid IANA's HTTP status code list."); } $ianaCodesReasonPhrases = array(); $xpath = new \DOMXPath($ianaHttpStatusCodes); $xpath->registerNamespace("ns", "http://www.iana.org/assignments"); $records = $xpath->query("//ns:record"); foreach ($records as $record) { $value = $xpath->query(".//ns:value", $record)->item(0)->nodeValue; $description = $xpath->query(".//ns:description", $record)->item(0)->nodeValue; if (\in_array($description, array("Unassigned", "(Unused)"), true)) { continue; } if (preg_match("/^([0-9]+)\s*\-\s*([0-9]+)$/", $value, $matches)) { for ($value = $matches[1]; $value <= $matches[2]; ++$value) { $ianaCodesReasonPhrases[] = array($value, $description); } } else { $ianaCodesReasonPhrases[] = array($value, $description); } } return $ianaCodesReasonPhrases; } public function testReasonPhraseDefaultsAgainstIana($code, $reasonPhrase) { $this->assertEquals($reasonPhrase, Response::$statusTexts[$code]); } public function testSetContentSafe() { $response = new Response(); $this->assertFalse($response->headers->has("Preference-Applied")); $this->assertFalse($response->headers->has("Vary")); $response->setContentSafe(); $this->assertSame("safe", $response->headers->get("Preference-Applied")); $this->assertSame("Prefer", $response->headers->get("Vary")); $response->setContentSafe(false); $this->assertFalse($response->headers->has("Preference-Applied")); $this->assertSame("Prefer", $response->headers->get("Vary")); } } class StringableObject { public function __toString() : string { return "Foo"; } } class DefaultResponse extends Response { } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Symfony\Component\HttpFoundation\Tests; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class ResponseTest extends ResponseTestCase { public function testToString() { $response = new Response(); $response = explode("\xd\xa", $response); $this->assertEquals("\x48\x54\124\120\x2f\61\56\60\40\62\60\60\40\x4f\113", $response[0]); $this->assertEquals("\103\x61\x63\x68\145\x2d\103\x6f\156\x74\162\157\x6c\x3a\40\x6e\157\x2d\x63\x61\143\150\145\x2c\x20\160\x72\151\166\141\164\145", $response[1]); } public function testClone() { $response = new Response(); $responseClone = clone $response; $this->assertEquals($response, $responseClone); } public function testSendHeaders() { $response = new Response(); $headers = $response->sendHeaders(); $this->assertSame($response, $headers); } public function testSendInformationalResponse() { $response = new Response(); $response->sendHeaders(103); $this->assertSame(200, $response->getStatusCode()); $response->sendHeaders(); } public function testSend() { $response = new Response(); $responseSend = $response->send(); $this->assertSame($response, $responseSend); } public function testGetCharset() { $response = new Response(); $charsetOrigin = "\125\x54\106\55\x38"; $response->setCharset($charsetOrigin); $charset = $response->getCharset(); $this->assertEquals($charsetOrigin, $charset); } public function testIsCacheable() { $response = new Response(); $this->assertFalse($response->isCacheable()); } public function testIsCacheableWithErrorCode() { $response = new Response('', 500); $this->assertFalse($response->isCacheable()); } public function testIsCacheableWithNoStoreDirective() { $response = new Response(); $response->headers->set("\143\x61\x63\150\145\x2d\143\157\x6e\164\162\157\x6c", "\160\162\151\166\x61\164\145"); $this->assertFalse($response->isCacheable()); } public function testIsCacheableWithSetTtl() { $response = new Response(); $response->setTtl(10); $this->assertTrue($response->isCacheable()); } public function testMustRevalidate() { $response = new Response(); $this->assertFalse($response->mustRevalidate()); } public function testMustRevalidateWithMustRevalidateCacheControlHeader() { $response = new Response(); $response->headers->set("\x63\141\143\150\x65\x2d\143\157\x6e\x74\x72\x6f\x6c", "\x6d\165\x73\164\x2d\162\x65\166\x61\x6c\151\144\141\164\145"); $this->assertTrue($response->mustRevalidate()); } public function testMustRevalidateWithProxyRevalidateCacheControlHeader() { $response = new Response(); $response->headers->set("\143\x61\143\150\x65\x2d\143\x6f\156\x74\162\x6f\154", "\160\x72\157\170\171\55\162\145\166\x61\154\x69\144\141\x74\145"); $this->assertTrue($response->mustRevalidate()); } public function testSetNotModified() { $response = new Response("\146\x6f\157"); $modified = $response->setNotModified(); $this->assertSame($response, $modified); $this->assertEquals(304, $modified->getStatusCode()); ob_start(); $modified->sendContent(); $string = ob_get_clean(); $this->assertEmpty($string); } public function testIsSuccessful() { $response = new Response(); $this->assertTrue($response->isSuccessful()); } public function testIsNotModified() { $response = new Response(); $modified = $response->isNotModified(new Request()); $this->assertFalse($modified); } public function testIsNotModifiedNotSafe() { $request = Request::create("\57\150\x6f\155\145\160\141\147\x65", "\x50\x4f\123\124"); $response = new Response(); $this->assertFalse($response->isNotModified($request)); } public function testIsNotModifiedLastModified() { $before = "\x53\165\x6e\x2c\x20\62\65\40\101\x75\147\x20\x32\x30\x31\x33\40\x31\x38\x3a\63\62\x3a\x33\61\x20\x47\x4d\x54"; $modified = "\x53\x75\156\54\x20\62\x35\40\101\165\x67\40\x32\x30\x31\x33\40\61\70\x3a\63\x33\x3a\63\x31\x20\x47\x4d\124"; $after = "\x53\x75\x6e\54\x20\62\65\40\x41\165\x67\40\x32\60\61\63\x20\x31\x39\72\63\x33\x3a\63\x31\x20\107\115\x54"; $request = new Request(); $request->headers->set("\111\x66\x2d\115\157\144\151\146\x69\x65\x64\55\x53\x69\x6e\x63\145", $modified); $response = new Response(); $response->headers->set("\114\141\x73\164\55\x4d\157\x64\151\146\x69\x65\x64", $modified); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\x4c\141\163\x74\x2d\x4d\157\144\151\x66\151\x65\x64", $before); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\114\141\x73\x74\x2d\x4d\157\x64\151\146\x69\x65\x64", $after); $this->assertFalse($response->isNotModified($request)); $response->headers->set("\x4c\141\x73\164\x2d\115\x6f\x64\x69\x66\151\x65\144", ''); $this->assertFalse($response->isNotModified($request)); } public function testIsNotModifiedEtag() { $etagOne = "\162\x61\x6e\144\x6f\x6d\x6c\x79\x5f\x67\145\x6e\x65\x72\x61\164\x65\144\x5f\x65\x74\x61\x67"; $etagTwo = "\162\x61\x6e\144\157\x6d\154\171\137\x67\x65\156\x65\x72\141\x74\x65\144\137\145\x74\141\x67\137\x32"; $request = new Request(); $request->headers->set("\111\146\x2d\x4e\157\x6e\145\x2d\x4d\x61\x74\x63\x68", sprintf("\x25\x73\x2c\x20\x25\x73\54\40\x25\x73", $etagOne, $etagTwo, "\x65\164\141\147\x54\x68\x72\x65\145")); $response = new Response(); $response->headers->set("\105\124\141\x67", $etagOne); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\x45\124\141\147", $etagTwo); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\x45\124\141\147", ''); $this->assertFalse($response->isNotModified($request)); $request = new Request(); $request->headers->set("\x49\146\55\116\x6f\x6e\x65\x2d\x4d\141\x74\x63\x68", "\52"); $response->headers->set("\x45\124\141\147", $etagOne); $this->assertTrue($response->isNotModified($request)); } public function testIsNotModifiedWeakEtag() { $etag = "\162\x61\x6e\144\157\x6d\x6c\x79\137\147\x65\x6e\x65\162\141\164\x65\x64\x5f\x65\164\141\x67"; $weakEtag = "\x57\57\x72\x61\156\144\x6f\155\x6c\171\137\x67\145\156\145\162\x61\164\x65\144\137\145\164\141\x67"; $request = new Request(); $request->headers->set("\111\146\x2d\116\x6f\x6e\145\x2d\x4d\141\164\x63\150", $etag); $response = new Response(); $response->headers->set("\x45\124\141\x67", $etag); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\x45\124\x61\x67", $weakEtag); $this->assertTrue($response->isNotModified($request)); $request->headers->set("\111\146\55\x4e\x6f\156\x65\x2d\115\141\164\143\x68", $weakEtag); $response = new Response(); $response->headers->set("\105\x54\x61\147", $etag); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\105\124\141\147", $weakEtag); $this->assertTrue($response->isNotModified($request)); } public function testIsNotModifiedLastModifiedAndEtag() { $before = "\x53\x75\x6e\x2c\x20\x32\65\x20\x41\x75\x67\40\62\60\61\x33\x20\61\70\x3a\63\x32\x3a\63\x31\x20\107\115\x54"; $modified = "\123\165\156\54\x20\x32\x35\x20\x41\165\x67\x20\62\x30\61\x33\40\x31\x38\x3a\x33\63\72\63\x31\x20\x47\115\x54"; $after = "\x53\165\156\54\x20\x32\x35\x20\x41\165\147\x20\62\60\x31\x33\40\61\71\72\x33\x33\x3a\x33\x31\x20\x47\115\124"; $etag = "\162\141\x6e\x64\x6f\155\154\x79\x5f\147\145\156\x65\162\x61\x74\145\144\x5f\x65\164\x61\147"; $request = new Request(); $request->headers->set("\111\x66\x2d\116\x6f\x6e\x65\55\x4d\x61\x74\143\150", sprintf("\x25\x73\x2c\40\x25\x73", $etag, "\x65\x74\141\147\124\150\162\x65\145")); $request->headers->set("\111\146\55\115\x6f\x64\151\x66\x69\145\144\x2d\123\x69\156\x63\x65", $modified); $response = new Response(); $response->headers->set("\105\x54\x61\147", $etag); $response->headers->set("\114\x61\x73\164\x2d\x4d\x6f\x64\151\146\x69\x65\x64", $after); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\105\x54\141\x67", "\x6e\x6f\x6e\55\x65\x78\x69\x73\x74\145\x6e\164\55\145\164\141\147"); $response->headers->set("\x4c\x61\x73\164\x2d\x4d\157\x64\151\146\151\145\144", $before); $this->assertFalse($response->isNotModified($request)); $response->headers->set("\105\124\141\147", $etag); $response->headers->set("\114\141\163\164\x2d\x4d\x6f\x64\x69\x66\x69\x65\x64", $modified); $this->assertTrue($response->isNotModified($request)); } public function testIsNotModifiedIfModifiedSinceAndEtagWithoutLastModified() { $modified = "\x53\165\156\54\x20\x32\65\40\x41\x75\x67\x20\x32\x30\x31\x33\40\61\x38\72\x33\63\72\63\x31\40\107\115\124"; $etag = "\162\x61\156\144\157\x6d\154\171\x5f\147\145\x6e\x65\x72\141\x74\145\x64\137\145\164\x61\147"; $request = new Request(); $request->headers->set("\111\x66\x2d\116\157\156\145\x2d\x4d\141\164\143\x68", sprintf("\45\x73\54\x20\45\163", $etag, "\145\x74\x61\x67\x54\150\162\x65\x65")); $request->headers->set("\x49\x66\55\115\x6f\144\151\146\151\145\x64\x2d\123\x69\x6e\x63\145", $modified); $response = new Response(); $response->headers->set("\105\124\141\147", $etag); $this->assertTrue($response->isNotModified($request)); $response->headers->set("\105\124\x61\147", "\x6e\157\156\x2d\x65\170\151\x73\x74\x65\x6e\164\x2d\x65\164\141\147"); $this->assertFalse($response->isNotModified($request)); } public function testIfNoneMatchWithoutETag() { $request = new Request(); $request->headers->set("\x49\146\x2d\x4e\x6f\x6e\x65\x2d\115\141\x74\x63\x68", "\162\x61\156\144\157\155\x6c\x79\137\147\145\x6e\145\162\x61\164\145\x64\137\x65\x74\141\147"); $this->assertFalse((new Response())->isNotModified($request)); $request = new Request(); $request->headers->set("\x49\x66\x2d\116\157\156\x65\x2d\x4d\x61\x74\143\150", "\x2a"); $this->assertFalse((new Response())->isNotModified($request)); } public function testIsValidateable() { $response = new Response('', 200, array("\x4c\x61\x73\164\55\115\157\x64\x69\146\151\x65\x64" => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822))); $this->assertTrue($response->isValidateable(), "\x2d\76\151\x73\126\x61\154\151\144\x61\x74\145\141\x62\x6c\x65\x28\x29\40\162\145\x74\165\x72\x6e\x73\x20\x74\162\165\x65\x20\x69\146\x20\x4c\x61\x73\164\x2d\115\157\144\151\146\x69\x65\144\40\x69\x73\40\160\x72\145\163\145\156\164"); $response = new Response('', 200, array("\x45\124\141\x67" => "\x22\x31\62\63\x34\65\x22")); $this->assertTrue($response->isValidateable(), "\55\x3e\151\163\126\141\154\x69\x64\x61\x74\x65\141\x62\154\145\50\51\40\x72\145\x74\165\162\x6e\163\x20\x74\162\x75\145\x20\151\146\x20\x45\x54\141\x67\x20\x69\x73\40\160\162\145\x73\x65\156\x74"); $response = new Response(); $this->assertFalse($response->isValidateable(), "\55\x3e\x69\163\x56\141\154\x69\144\141\164\145\141\142\x6c\x65\x28\x29\x20\162\x65\x74\165\162\156\x73\x20\x66\141\154\163\145\40\x77\x68\145\156\40\156\157\x20\x76\x61\x6c\x69\144\x61\164\157\162\40\151\x73\x20\x70\x72\145\163\145\x6e\x74"); } public function testGetDate() { $oneHourAgo = $this->createDateTimeOneHourAgo(); $response = new Response('', 200, array("\x44\x61\164\145" => $oneHourAgo->format(\DATE_RFC2822))); $date = $response->getDate(); $this->assertEquals($oneHourAgo->getTimestamp(), $date->getTimestamp(), "\x2d\76\x67\x65\x74\x44\x61\x74\145\x28\x29\40\x72\145\164\165\162\x6e\x73\40\x74\150\145\40\104\141\164\x65\x20\150\x65\x61\144\145\x72\40\151\x66\x20\x70\x72\x65\163\x65\x6e\x74"); $response = new Response(); $date = $response->getDate(); $this->assertEquals(time(), $date->getTimestamp(), "\55\76\147\x65\x74\104\x61\x74\145\x28\x29\40\x72\145\x74\165\x72\x6e\x73\40\164\150\145\x20\x63\x75\x72\x72\145\x6e\164\x20\104\x61\164\145\x20\x69\x66\40\156\157\x20\x44\x61\x74\x65\x20\x68\145\x61\144\145\162\40\160\162\145\163\x65\x6e\x74"); $response = new Response('', 200, array("\104\141\164\x65" => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822))); $now = $this->createDateTimeNow(); $response->headers->set("\104\141\x74\145", $now->format(\DATE_RFC2822)); $date = $response->getDate(); $this->assertEquals($now->getTimestamp(), $date->getTimestamp(), "\55\x3e\147\145\x74\x44\x61\164\x65\50\51\40\162\x65\x74\x75\x72\156\x73\x20\x74\x68\145\40\144\141\164\145\40\167\x68\145\156\x20\164\150\x65\40\x68\145\141\x64\145\162\x20\150\141\163\x20\x62\145\x65\x6e\x20\x6d\x6f\x64\151\146\x69\145\x64"); $response = new Response('', 200); $now = $this->createDateTimeNow(); $response->headers->remove("\x44\141\x74\145"); $date = $response->getDate(); $this->assertEquals($now->getTimestamp(), $date->getTimestamp(), "\x2d\x3e\x67\x65\x74\x44\x61\x74\145\x28\51\x20\x72\145\164\x75\162\x6e\163\x20\x74\x68\145\40\143\165\162\162\145\x6e\164\40\104\x61\164\x65\x20\x77\150\x65\156\40\164\150\x65\40\150\x65\141\144\x65\162\40\150\x61\163\40\160\162\145\x76\151\x6f\x75\x73\x6c\171\40\142\x65\x65\156\40\162\145\155\157\x76\x65\x64"); } public function testGetMaxAge() { $response = new Response(); $response->headers->set("\103\141\x63\x68\145\x2d\103\x6f\x6e\x74\x72\x6f\154", "\163\x2d\x6d\141\x78\x61\x67\x65\x3d\66\60\x30\x2c\x20\155\x61\x78\x2d\141\147\x65\75\x30"); $this->assertEquals(600, $response->getMaxAge(), "\55\x3e\147\145\x74\115\141\170\x41\x67\x65\50\51\40\165\163\x65\163\40\163\x2d\x6d\x61\x78\x61\x67\145\40\x63\141\143\150\145\x20\x63\157\156\164\162\x6f\x6c\x20\x64\x69\162\145\x63\164\151\166\x65\40\167\150\x65\x6e\x20\x70\162\145\163\145\x6e\x74"); $response = new Response(); $response->headers->set("\103\141\x63\x68\145\55\x43\x6f\x6e\164\162\157\x6c", "\155\x61\x78\x2d\141\x67\x65\75\x36\x30\x30"); $this->assertEquals(600, $response->getMaxAge(), "\55\76\x67\x65\164\x4d\x61\x78\x41\x67\145\x28\x29\x20\x66\141\154\154\x73\40\142\141\x63\x6b\x20\164\157\x20\155\141\x78\55\x61\147\145\40\167\150\x65\x6e\x20\x6e\157\x20\x73\x2d\x6d\141\170\x61\147\145\x20\x64\x69\x72\145\143\x74\151\166\x65\40\x70\x72\145\163\145\x6e\x74"); $response = new Response(); $response->headers->set("\103\x61\x63\x68\145\55\x43\157\156\164\x72\157\154", "\155\165\x73\164\x2d\x72\x65\x76\141\x6c\x69\x64\141\164\145"); $response->headers->set("\105\170\x70\151\x72\x65\x73", $this->createDateTimeOneHourLater()->format(\DATE_RFC2822)); $this->assertEquals(3600, $response->getMaxAge(), "\x2d\x3e\x67\x65\164\115\x61\170\x41\147\x65\x28\x29\40\146\x61\x6c\154\163\40\142\x61\x63\153\40\x74\157\40\105\170\x70\x69\162\145\x73\x20\x77\x68\145\156\40\156\x6f\x20\155\x61\x78\55\x61\147\145\40\x6f\162\40\163\55\x6d\141\x78\141\147\145\x20\x64\151\x72\x65\143\164\151\166\x65\40\160\162\x65\x73\145\x6e\x74"); $response = new Response(); $response->headers->set("\x45\170\160\151\162\x65\163", -1); $this->assertSame(0, $response->getMaxAge()); $response = new Response(); $this->assertNull($response->getMaxAge(), "\x2d\x3e\x67\145\x74\115\x61\170\x41\147\x65\50\x29\x20\x72\x65\164\x75\x72\156\x73\40\x6e\x75\x6c\154\x20\151\x66\40\x6e\x6f\x20\146\x72\x65\163\150\156\x65\163\163\40\151\156\x66\157\162\x6d\141\164\151\157\156\40\141\166\141\151\x6c\x61\x62\x6c\145"); } public function testSetSharedMaxAge() { $response = new Response(); $response->setSharedMaxAge(20); $cacheControl = $response->headers->get("\103\x61\143\x68\145\55\x43\157\156\164\162\157\154"); $this->assertEquals("\x70\x75\x62\x6c\x69\143\x2c\40\x73\55\155\141\x78\x61\x67\145\x3d\62\60", $cacheControl); } public function testSetStaleIfError() { $response = new Response(); $response->setSharedMaxAge(20); $response->setStaleIfError(86400); $cacheControl = $response->headers->get("\x43\x61\x63\150\x65\55\x43\157\x6e\x74\x72\157\x6c"); $this->assertEquals("\160\x75\x62\x6c\151\143\x2c\x20\163\55\x6d\x61\x78\141\x67\145\x3d\x32\x30\54\x20\163\164\x61\x6c\145\55\151\146\x2d\x65\162\x72\x6f\x72\x3d\70\x36\64\60\60", $cacheControl); } public function testSetStaleWhileRevalidate() { $response = new Response(); $response->setSharedMaxAge(20); $response->setStaleWhileRevalidate(300); $cacheControl = $response->headers->get("\103\x61\x63\150\x65\x2d\103\x6f\156\x74\162\157\154"); $this->assertEquals("\x70\x75\142\154\x69\x63\54\x20\163\55\155\141\170\141\x67\145\75\62\60\54\x20\163\164\141\x6c\145\55\x77\x68\x69\154\x65\55\162\x65\166\141\x6c\151\x64\141\x74\145\75\x33\x30\60", $cacheControl); } public function testSetStaleIfErrorWithoutSharedMaxAge() { $response = new Response(); $response->setStaleIfError(86400); $cacheControl = $response->headers->get("\103\141\x63\150\x65\x2d\x43\157\x6e\164\x72\x6f\154"); $this->assertEquals("\163\164\141\x6c\x65\55\x69\x66\x2d\x65\162\162\157\x72\75\x38\66\x34\x30\x30\54\40\x70\162\151\x76\141\164\x65", $cacheControl); } public function testSetStaleWhileRevalidateWithoutSharedMaxAge() { $response = new Response(); $response->setStaleWhileRevalidate(300); $cacheControl = $response->headers->get("\103\141\x63\x68\145\55\103\x6f\x6e\164\x72\x6f\x6c"); $this->assertEquals("\163\x74\x61\154\x65\55\x77\x68\151\x6c\145\55\162\145\166\141\154\x69\144\141\x74\145\75\x33\x30\60\54\40\160\x72\x69\x76\x61\164\145", $cacheControl); } public function testIsPrivate() { $response = new Response(); $response->headers->set("\103\x61\143\150\x65\x2d\103\x6f\x6e\x74\x72\x6f\154", "\155\x61\x78\55\141\x67\145\75\61\x30\x30"); $response->setPrivate(); $this->assertEquals(100, $response->headers->getCacheControlDirective("\x6d\141\x78\x2d\141\147\x65"), "\55\76\x69\x73\120\x72\x69\x76\141\x74\x65\x28\51\x20\141\144\x64\163\x20\x74\x68\145\40\x70\x72\151\x76\x61\x74\145\x20\x43\x61\143\150\x65\x2d\103\x6f\156\x74\x72\157\154\x20\144\151\x72\145\143\164\x69\166\x65\40\167\150\145\x6e\x20\163\x65\164\x20\x74\x6f\x20\x74\162\165\145"); $this->assertTrue($response->headers->getCacheControlDirective("\x70\162\151\x76\141\164\145"), "\55\x3e\151\163\120\x72\151\x76\x61\x74\145\x28\x29\40\x61\144\x64\x73\40\x74\x68\x65\40\x70\162\151\x76\x61\164\x65\x20\103\x61\143\150\x65\55\x43\157\156\x74\162\x6f\154\40\144\151\x72\145\x63\164\x69\x76\145\x20\167\x68\x65\x6e\40\x73\145\164\x20\164\x6f\x20\x74\x72\165\145"); $response = new Response(); $response->headers->set("\103\141\143\x68\x65\x2d\103\x6f\156\x74\x72\x6f\x6c", "\160\x75\142\154\151\143\x2c\x20\x6d\141\x78\x2d\x61\147\x65\x3d\61\60\60"); $response->setPrivate(); $this->assertEquals(100, $response->headers->getCacheControlDirective("\155\x61\170\55\x61\x67\145"), "\55\76\x69\163\x50\162\151\166\141\164\145\x28\51\40\x61\144\144\163\x20\x74\150\x65\40\160\162\x69\166\x61\x74\x65\x20\x43\141\x63\x68\x65\55\103\157\x6e\164\162\x6f\x6c\x20\144\x69\x72\145\143\x74\x69\166\x65\x20\x77\x68\145\156\40\163\x65\x74\40\x74\x6f\x20\x74\x72\x75\x65"); $this->assertTrue($response->headers->getCacheControlDirective("\x70\x72\151\x76\x61\x74\145"), "\55\x3e\151\163\120\x72\151\166\141\x74\x65\x28\51\40\141\x64\x64\x73\40\164\150\145\40\160\162\x69\x76\x61\164\x65\x20\103\141\x63\150\145\x2d\x43\157\x6e\x74\x72\x6f\x6c\40\x64\x69\x72\x65\x63\x74\151\x76\145\40\167\x68\x65\x6e\40\163\x65\164\x20\x74\x6f\40\164\162\x75\x65"); $this->assertFalse($response->headers->hasCacheControlDirective("\x70\x75\x62\154\x69\x63"), "\x2d\x3e\151\163\120\x72\151\x76\x61\x74\145\x28\51\40\x72\x65\x6d\157\x76\145\x73\x20\x74\x68\x65\40\x70\x75\142\154\x69\143\x20\x43\141\x63\x68\x65\x2d\103\x6f\x6e\164\162\x6f\154\x20\x64\x69\162\x65\x63\x74\151\166\x65"); } public function testExpire() { $response = new Response(); $response->headers->set("\x43\141\143\x68\145\55\x43\157\156\x74\162\x6f\x6c", "\x6d\141\170\55\x61\x67\145\x3d\x31\60\x30"); $response->expire(); $this->assertEquals(100, $response->headers->get("\101\x67\145"), "\x2d\x3e\x65\170\x70\x69\x72\145\50\51\x20\x73\x65\x74\163\40\164\150\x65\40\101\x67\145\x20\x74\x6f\x20\x6d\141\x78\x2d\141\147\x65\40\x77\x68\x65\156\x20\160\x72\x65\163\145\156\x74"); $response = new Response(); $response->headers->set("\103\141\143\x68\145\55\x43\157\x6e\164\x72\x6f\x6c", "\x6d\141\170\x2d\141\147\145\75\x31\60\60\x2c\x20\x73\x2d\x6d\x61\x78\x61\x67\145\75\x35\60\60"); $response->expire(); $this->assertEquals(500, $response->headers->get("\101\147\145"), "\55\76\145\x78\160\151\x72\x65\x28\51\40\x73\145\164\x73\x20\x74\x68\145\40\101\147\145\40\x74\x6f\x20\x73\x2d\155\x61\x78\141\147\145\x20\167\x68\145\x6e\x20\142\157\x74\x68\x20\155\x61\170\x2d\x61\x67\x65\40\x61\x6e\144\40\x73\x2d\x6d\141\170\141\x67\145\x20\141\x72\145\40\x70\x72\x65\163\145\x6e\x74"); $response = new Response(); $response->headers->set("\103\141\x63\150\145\55\103\157\x6e\164\x72\157\x6c", "\155\x61\x78\55\141\x67\x65\x3d\x35\x2c\x20\163\x2d\155\141\170\x61\x67\145\75\x35\x30\x30"); $response->headers->set("\101\x67\x65", "\61\x30\x30\x30"); $response->expire(); $this->assertEquals(1000, $response->headers->get("\x41\x67\145"), "\x2d\76\x65\170\160\x69\x72\x65\x28\x29\x20\x64\157\x65\163\x20\156\x6f\x74\150\151\156\x67\x20\167\x68\x65\x6e\40\164\x68\145\x20\162\x65\x73\x70\x6f\156\x73\x65\x20\151\163\40\141\x6c\162\145\141\144\171\40\163\164\x61\154\x65\57\145\x78\160\x69\x72\x65\144"); $response = new Response(); $response->expire(); $this->assertFalse($response->headers->has("\101\x67\x65"), "\55\76\x65\170\x70\x69\x72\145\50\51\40\144\157\145\163\x20\x6e\157\164\x68\x69\156\x67\x20\167\x68\145\156\40\x74\x68\x65\x20\162\x65\163\x70\157\x6e\163\145\x20\x64\x6f\x65\x73\40\x6e\157\x74\x20\151\x6e\x63\154\x75\x64\145\x20\x66\x72\x65\x73\150\x6e\x65\163\x73\x20\x69\156\x66\x6f\162\155\141\x74\151\x6f\x6e"); $response = new Response(); $response->headers->set("\105\170\160\151\162\145\163", -1); $response->expire(); $this->assertNull($response->headers->get("\x41\x67\x65"), "\x2d\x3e\145\170\160\151\162\145\x28\51\x20\144\157\x65\163\x20\x6e\x6f\164\40\163\x65\x74\40\164\150\x65\40\x41\x67\145\40\x77\150\145\x6e\40\x74\150\x65\x20\162\x65\x73\160\x6f\x6e\163\145\40\x69\x73\x20\145\x78\160\151\162\145\144"); $response = new Response(); $response->headers->set("\x45\170\x70\x69\162\145\x73", date(\DATE_RFC2822, time() + 600)); $response->expire(); $this->assertNull($response->headers->get("\x45\x78\160\x69\162\x65\163"), "\55\76\145\x78\x70\x69\x72\145\50\51\40\x72\x65\155\x6f\166\145\163\x20\x74\x68\x65\x20\105\170\x70\151\162\x65\163\x20\x68\x65\x61\144\x65\162\40\167\150\145\156\40\164\x68\145\40\162\145\x73\160\157\156\163\x65\40\x69\x73\x20\x66\162\145\x73\150"); } public function testNullExpireHeader() { $response = new Response(null, 200, array("\x45\170\x70\151\x72\x65\x73" => null)); $this->assertNull($response->getExpires()); } public function testGetTtl() { $response = new Response(); $this->assertNull($response->getTtl(), "\x2d\x3e\147\x65\x74\124\x74\154\x28\51\x20\162\x65\x74\165\162\x6e\x73\x20\156\x75\x6c\x6c\x20\167\x68\145\156\40\x6e\157\40\x45\x78\160\x69\x72\x65\x73\40\x6f\162\40\x43\141\x63\150\x65\x2d\103\x6f\156\164\162\x6f\154\40\x68\145\x61\144\145\162\163\x20\141\x72\x65\40\x70\x72\145\x73\x65\x6e\164"); $response = new Response(); $response->headers->set("\x45\x78\x70\x69\162\145\163", $this->createDateTimeOneHourLater()->format(\DATE_RFC2822)); $this->assertEquals(3600, $response->getTtl(), "\55\76\147\x65\164\124\x74\154\x28\51\x20\165\163\145\163\40\164\150\145\x20\x45\170\x70\151\162\145\x73\40\x68\x65\141\144\x65\162\40\167\x68\145\x6e\40\156\157\40\155\141\x78\x2d\141\147\145\x20\151\x73\40\160\162\x65\163\x65\x6e\164"); $response = new Response(); $response->headers->set("\x45\x78\x70\151\x72\x65\163", $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)); $this->assertSame(0, $response->getTtl(), "\55\x3e\147\x65\164\x54\x74\154\x28\x29\40\x72\145\x74\165\x72\156\x73\x20\x7a\x65\x72\x6f\40\x77\x68\145\x6e\40\x45\x78\160\x69\162\145\x73\x20\151\163\x20\151\x6e\x20\x70\x61\163\x74"); $response = new Response(); $response->headers->set("\105\170\160\x69\162\x65\x73", $response->getDate()->format(\DATE_RFC2822)); $response->headers->set("\101\147\145", 0); $this->assertSame(0, $response->getTtl(), "\x2d\x3e\x67\145\164\x54\x74\154\x28\51\40\x63\x6f\x72\x72\145\143\164\x6c\x79\x20\x68\x61\156\144\x6c\x65\163\x20\172\145\162\x6f"); $response = new Response(); $response->headers->set("\x43\x61\x63\150\145\x2d\103\157\156\x74\162\x6f\154", "\155\141\x78\55\x61\x67\145\75\x36\x30"); $this->assertEquals(60, $response->getTtl(), "\x2d\76\x67\x65\164\x54\164\154\50\x29\x20\x75\163\145\163\40\x43\x61\143\150\x65\55\x43\157\156\164\x72\157\154\40\x6d\x61\x78\55\141\x67\145\40\167\x68\145\x6e\40\x70\162\145\x73\x65\x6e\x74"); } public function testSetClientTtl() { $response = new Response(); $response->setClientTtl(10); $this->assertEquals($response->getMaxAge(), $response->getAge() + 10); } public function testGetSetProtocolVersion() { $response = new Response(); $this->assertEquals("\x31\x2e\x30", $response->getProtocolVersion()); $response->setProtocolVersion("\x31\x2e\x31"); $this->assertEquals("\61\56\61", $response->getProtocolVersion()); } public function testGetVary() { $response = new Response(); $this->assertEquals(array(), $response->getVary(), "\55\x3e\147\x65\164\126\141\x72\x79\x28\x29\40\162\x65\x74\165\162\x6e\163\40\x61\156\40\x65\x6d\x70\x74\x79\40\141\x72\162\141\171\40\x69\146\40\x6e\x6f\40\x56\x61\x72\171\x20\150\x65\x61\x64\x65\162\40\151\x73\40\x70\162\x65\x73\145\x6e\164"); $response = new Response(); $response->headers->set("\x56\x61\x72\x79", "\101\143\x63\x65\x70\164\x2d\x4c\x61\156\147\165\x61\x67\x65"); $this->assertEquals(array("\x41\x63\143\x65\160\164\55\x4c\x61\x6e\x67\x75\141\x67\145"), $response->getVary(), "\x2d\x3e\x67\x65\164\126\141\162\171\50\51\40\160\x61\x72\163\145\x73\x20\x61\40\163\151\156\147\x6c\145\40\x68\x65\x61\144\x65\162\x20\156\141\155\145\x20\166\141\x6c\x75\x65"); $response = new Response(); $response->headers->set("\x56\x61\x72\x79", "\x41\x63\143\x65\x70\x74\55\114\x61\x6e\147\x75\141\x67\x65\40\125\163\x65\x72\55\101\x67\x65\x6e\x74\40\40\x20\40\x58\x2d\x46\x6f\x6f"); $this->assertEquals(array("\101\x63\x63\145\160\x74\55\x4c\141\x6e\147\165\x61\x67\x65", "\125\x73\x65\162\55\x41\x67\145\x6e\x74", "\x58\55\106\x6f\x6f"), $response->getVary(), "\x2d\76\x67\x65\x74\x56\x61\x72\171\50\x29\x20\160\141\162\163\x65\163\40\x6d\x75\154\x74\x69\160\x6c\x65\40\x68\x65\141\144\145\x72\40\x6e\x61\x6d\x65\40\x76\141\x6c\165\x65\163\40\x73\x65\x70\141\x72\x61\164\x65\x64\x20\142\x79\40\x73\160\x61\143\x65\163"); $response = new Response(); $response->headers->set("\126\141\x72\171", "\x41\143\143\145\160\164\x2d\x4c\x61\156\x67\x75\x61\147\145\54\125\163\x65\162\55\x41\x67\x65\x6e\164\54\40\40\x20\40\130\55\106\x6f\157"); $this->assertEquals(array("\x41\x63\x63\x65\x70\164\55\x4c\x61\156\147\165\x61\x67\145", "\125\x73\x65\x72\55\101\x67\x65\x6e\164", "\x58\55\106\157\157"), $response->getVary(), "\x2d\x3e\147\x65\x74\x56\x61\162\171\50\51\x20\160\141\x72\x73\145\x73\x20\155\x75\154\164\x69\160\154\145\40\150\145\x61\x64\145\162\x20\x6e\141\x6d\x65\x20\x76\x61\x6c\165\x65\x73\x20\163\145\160\141\162\x61\164\x65\x64\x20\x62\171\40\143\x6f\x6d\155\141\x73"); $vary = array("\101\143\x63\145\160\x74\x2d\114\x61\x6e\147\165\141\147\x65", "\x55\163\145\162\55\x41\x67\145\156\164", "\x58\55\x66\x6f\x6f"); $response = new Response(); $response->headers->set("\x56\141\x72\x79", $vary); $this->assertEquals($vary, $response->getVary(), "\x2d\76\x67\x65\164\x56\141\162\171\50\51\40\x70\x61\162\x73\x65\163\x20\155\x75\x6c\x74\x69\160\x6c\145\x20\150\145\141\x64\x65\x72\x20\x6e\141\155\x65\40\166\x61\x6c\x75\145\x73\x20\151\156\40\141\x72\162\141\171\163"); $response = new Response(); $response->headers->set("\126\x61\x72\x79", "\x41\143\143\145\160\164\x2d\114\141\x6e\147\x75\x61\x67\x65\54\x20\125\163\x65\162\x2d\101\x67\145\156\164\x2c\40\130\x2d\x66\157\x6f"); $this->assertEquals($vary, $response->getVary(), "\x2d\x3e\x67\x65\164\x56\x61\x72\171\x28\51\40\x70\x61\162\163\145\163\40\x6d\165\154\x74\x69\x70\x6c\x65\x20\150\x65\141\144\x65\x72\x20\x6e\x61\x6d\x65\x20\166\141\x6c\165\x65\x73\40\x69\156\x20\141\162\162\141\x79\163"); } public function testSetVary() { $response = new Response(); $response->setVary("\101\143\143\x65\160\164\x2d\x4c\x61\156\x67\165\x61\x67\145"); $this->assertEquals(array("\101\x63\x63\x65\x70\x74\x2d\x4c\141\156\x67\x75\141\x67\145"), $response->getVary()); $response->setVary("\x41\x63\x63\145\160\164\55\x4c\141\156\147\165\141\147\x65\x2c\40\125\x73\145\162\55\x41\147\x65\156\164"); $this->assertEquals(array("\101\143\143\x65\x70\164\x2d\114\x61\156\x67\x75\x61\147\x65", "\125\x73\145\162\x2d\101\x67\145\x6e\x74"), $response->getVary(), "\55\76\x73\x65\164\126\141\162\171\50\51\x20\x72\x65\160\x6c\x61\x63\x65\40\164\x68\x65\40\x76\141\162\x79\x20\x68\145\141\144\145\x72\40\x62\x79\x20\144\145\x66\x61\165\154\164"); $response->setVary("\x58\x2d\x46\x6f\x6f", false); $this->assertEquals(array("\x41\x63\143\145\x70\164\x2d\x4c\141\156\x67\x75\x61\147\x65", "\x55\x73\145\x72\55\x41\x67\145\x6e\164", "\130\x2d\x46\157\157"), $response->getVary(), "\x2d\76\x73\x65\164\x56\141\x72\171\50\x29\40\x64\x6f\145\x73\156\x27\164\40\x77\151\x70\145\x20\157\x75\164\x20\x65\141\x72\154\x69\x65\x72\x20\126\141\x72\171\40\150\x65\x61\144\x65\x72\x73\x20\x69\x66\x20\162\145\160\x6c\141\x63\145\40\151\163\x20\x73\x65\x74\40\x74\x6f\40\146\x61\154\x73\x65"); } public function testDefaultContentType() { $response = new Response("\146\x6f\157"); $response->prepare(new Request()); $this->assertSame("\164\x65\x78\x74\x2f\x68\x74\155\154\73\40\x63\x68\x61\162\x73\x65\164\x3d\x55\x54\x46\55\70", $response->headers->get("\103\x6f\x6e\164\145\156\164\55\124\171\160\x65")); } public function testContentTypeCharset() { $response = new Response(); $response->headers->set("\103\157\x6e\x74\x65\x6e\x74\x2d\124\171\x70\x65", "\164\145\170\x74\x2f\x63\x73\x73"); $response->prepare(new Request()); $this->assertEquals("\x74\x65\170\164\57\143\163\x73\73\x20\x63\150\x61\x72\163\145\x74\x3d\x55\124\x46\x2d\x38", $response->headers->get("\x43\157\x6e\164\x65\156\164\55\124\171\160\x65")); } public function testContentTypeIsNull() { $response = new Response("\x66\157\157"); $response->headers->set("\x43\x6f\x6e\x74\x65\x6e\164\x2d\124\171\160\145", null); $response->prepare(new Request()); $this->expectNotToPerformAssertions(); } public function testPrepareDoesNothingIfContentTypeIsSet() { $response = new Response("\146\x6f\157"); $response->headers->set("\x43\x6f\156\164\x65\156\164\55\124\171\160\145", "\x74\x65\x78\164\x2f\x70\x6c\141\151\x6e"); $response->prepare(new Request()); $this->assertEquals("\x74\x65\170\164\x2f\160\x6c\x61\151\156\73\x20\143\x68\x61\x72\x73\145\164\x3d\125\x54\x46\55\70", $response->headers->get("\x63\157\156\x74\145\x6e\x74\55\164\x79\x70\145")); } public function testPrepareDoesNothingIfRequestFormatIsNotDefined() { $response = new Response("\146\x6f\x6f"); $response->prepare(new Request()); $this->assertEquals("\164\145\170\164\x2f\x68\164\155\x6c\x3b\40\143\150\141\x72\163\x65\x74\x3d\125\x54\106\x2d\70", $response->headers->get("\x63\157\156\164\x65\156\164\x2d\164\171\x70\145")); } public function testPrepareDoesNotSetContentTypeBasedOnRequestAcceptHeader() { $response = new Response("\x66\x6f\157"); $request = Request::create("\x2f"); $request->headers->set("\101\143\x63\145\x70\x74", "\141\160\160\154\151\x63\141\x74\x69\x6f\x6e\x2f\x6a\163\157\156"); $response->prepare($request); $this->assertSame("\164\145\x78\x74\57\x68\x74\155\x6c\73\40\x63\150\x61\x72\x73\x65\x74\75\125\124\106\55\x38", $response->headers->get("\x63\x6f\156\x74\145\156\x74\55\164\x79\x70\x65")); } public function testPrepareSetContentType() { $response = new Response("\x66\x6f\157"); $request = Request::create("\x2f"); $request->setRequestFormat("\152\163\157\x6e"); $response->prepare($request); $this->assertEquals("\141\160\160\154\x69\143\141\164\151\157\x6e\x2f\x6a\163\x6f\156", $response->headers->get("\x63\157\156\x74\x65\x6e\164\x2d\x74\171\160\145")); } public function testPrepareRemovesContentForHeadRequests() { $response = new Response("\146\x6f\x6f"); $request = Request::create("\x2f", "\110\x45\x41\104"); $length = 12345; $response->headers->set("\x43\157\x6e\x74\x65\156\x74\55\x4c\x65\x6e\147\x74\x68", $length); $response->prepare($request); $this->assertEquals('', $response->getContent()); $this->assertEquals($length, $response->headers->get("\x43\x6f\156\164\x65\156\164\55\x4c\x65\x6e\x67\x74\x68"), "\103\x6f\x6e\x74\x65\156\164\55\114\145\x6e\147\164\150\x20\163\150\157\165\154\x64\x20\x62\x65\40\x61\163\40\x69\x66\40\x69\164\40\167\x61\x73\x20\107\x45\x54\x3b\x20\163\145\x65\x20\x52\x46\x43\x32\x36\x31\x36\x20\x31\x34\56\x31\x33"); } public function testPrepareRemovesContentForInformationalResponse() { $response = new Response("\x66\x6f\157"); $request = Request::create("\57"); $response->setContent("\x63\157\x6e\x74\x65\x6e\x74"); $response->setStatusCode(101); $response->prepare($request); $this->assertEquals('', $response->getContent()); $this->assertFalse($response->headers->has("\103\157\x6e\x74\x65\x6e\x74\x2d\x54\x79\160\145")); $response->setContent("\x63\x6f\156\164\145\156\164"); $response->setStatusCode(304); $response->prepare($request); $this->assertEquals('', $response->getContent()); $this->assertFalse($response->headers->has("\x43\157\x6e\x74\x65\156\x74\55\x54\171\x70\x65")); $this->assertFalse($response->headers->has("\103\x6f\156\164\145\156\164\x2d\x4c\x65\x6e\x67\164\x68")); } public function testPrepareRemovesContentLength() { $response = new Response("\x66\x6f\157"); $request = Request::create("\x2f"); $response->headers->set("\103\157\x6e\164\145\156\x74\x2d\x4c\x65\156\147\164\x68", 12345); $response->prepare($request); $this->assertEquals(12345, $response->headers->get("\103\x6f\156\164\x65\156\x74\x2d\x4c\145\156\x67\x74\x68")); $response->headers->set("\x54\x72\x61\x6e\163\146\x65\x72\x2d\105\156\143\x6f\144\151\156\x67", "\x63\x68\x75\156\x6b\145\x64"); $response->prepare($request); $this->assertFalse($response->headers->has("\103\157\x6e\164\145\x6e\x74\55\x4c\145\156\x67\x74\150")); } public function testPrepareSetsPragmaOnHttp10Only() { $request = Request::create("\x2f", "\x47\105\124"); $request->server->set("\x53\105\122\126\x45\x52\137\x50\x52\117\x54\117\103\117\x4c", "\110\x54\x54\x50\x2f\x31\56\60"); $response = new Response("\x66\157\157"); $response->prepare($request); $this->assertEquals("\x6e\157\55\143\x61\143\x68\x65", $response->headers->get("\x70\x72\141\147\155\141")); $this->assertEquals("\55\61", $response->headers->get("\145\170\x70\151\162\145\163")); $response = new Response("\146\157\x6f"); $response->headers->remove("\143\x61\143\150\x65\x2d\x63\x6f\x6e\x74\x72\x6f\x6c"); $response->prepare($request); $this->assertFalse($response->headers->has("\x70\162\x61\x67\155\141")); $this->assertFalse($response->headers->has("\x65\170\160\151\162\145\163")); $request->server->set("\123\105\x52\x56\x45\x52\137\x50\122\117\x54\x4f\x43\117\x4c", "\x48\x54\x54\120\57\61\56\x31"); $response = new Response("\146\x6f\x6f"); $response->prepare($request); $this->assertFalse($response->headers->has("\x70\162\141\147\155\141")); $this->assertFalse($response->headers->has("\145\x78\x70\151\x72\x65\163")); } public function testPrepareSetsCookiesSecure() { $cookie = Cookie::create("\146\x6f\157", "\x62\141\x72"); $response = new Response("\146\x6f\157"); $response->headers->setCookie($cookie); $request = Request::create("\57", "\x47\x45\x54"); $response->prepare($request); $this->assertFalse($cookie->isSecure()); $request = Request::create("\x68\164\164\160\x73\x3a\57\57\x6c\x6f\x63\141\154\150\157\163\x74\x2f", "\107\105\x54"); $response->prepare($request); $this->assertTrue($cookie->isSecure()); } public function testSetCache() { $response = new Response(); try { $response->setCache(array("\x77\x72\x6f\156\x67\x20\x6f\160\164\x69\157\156" => "\x76\141\x6c\x75\x65")); $this->fail("\55\x3e\163\x65\164\x43\141\x63\x68\145\50\x29\40\164\150\162\157\167\x73\x20\x61\x6e\x20\x49\156\166\141\x6c\x69\x64\x41\x72\x67\x75\x6d\x65\156\164\105\170\143\x65\x70\164\x69\157\x6e\40\151\x66\40\141\x6e\x20\157\x70\164\151\x6f\x6e\40\x69\163\x20\156\157\x74\40\x73\165\160\x70\157\162\164\x65\144"); } catch (\Exception $e) { $this->assertInstanceOf(\InvalidArgumentException::class, $e, "\x2d\x3e\x73\x65\x74\103\141\x63\150\x65\50\51\x20\164\150\x72\x6f\x77\163\x20\141\156\40\x49\x6e\x76\x61\154\151\x64\101\162\147\165\x6d\145\156\164\105\170\143\x65\x70\164\x69\x6f\156\x20\151\x66\x20\141\x6e\40\x6f\x70\x74\151\157\x6e\40\151\163\40\156\x6f\164\40\163\x75\x70\160\157\x72\x74\x65\144"); $this->assertStringContainsString("\x22\167\162\157\x6e\147\x20\157\160\164\x69\157\x6e\x22", $e->getMessage()); } $options = array("\x65\164\x61\x67" => "\42\x77\x68\141\164\145\166\145\162\42"); $response->setCache($options); $this->assertEquals("\x22\167\150\141\x74\145\x76\145\x72\x22", $response->getEtag()); $now = $this->createDateTimeNow(); $options = array("\154\141\163\164\x5f\155\157\144\x69\x66\x69\x65\144" => $now); $response->setCache($options); $this->assertEquals($now->getTimestamp(), $response->getLastModified()->getTimestamp()); $options = array("\155\x61\170\137\141\147\145" => 100); $response->setCache($options); $this->assertEquals(100, $response->getMaxAge()); $options = array("\x73\137\155\141\x78\x61\x67\145" => 200); $response->setCache($options); $this->assertEquals(200, $response->getMaxAge()); $this->assertTrue($response->headers->hasCacheControlDirective("\x70\x75\x62\154\151\143")); $this->assertFalse($response->headers->hasCacheControlDirective("\160\x72\151\166\x61\x74\x65")); $response->setCache(array("\x70\x75\142\x6c\x69\143" => true)); $this->assertTrue($response->headers->hasCacheControlDirective("\x70\x75\x62\x6c\x69\143")); $this->assertFalse($response->headers->hasCacheControlDirective("\160\x72\x69\166\x61\164\x65")); $response->setCache(array("\160\165\x62\154\151\x63" => false)); $this->assertFalse($response->headers->hasCacheControlDirective("\160\165\x62\154\x69\143")); $this->assertTrue($response->headers->hasCacheControlDirective("\160\x72\151\166\x61\x74\x65")); $response->setCache(array("\160\x72\x69\166\141\164\145" => true)); $this->assertFalse($response->headers->hasCacheControlDirective("\160\x75\x62\x6c\x69\x63")); $this->assertTrue($response->headers->hasCacheControlDirective("\x70\x72\151\x76\x61\164\x65")); $response->setCache(array("\x70\x72\x69\x76\x61\x74\x65" => false)); $this->assertTrue($response->headers->hasCacheControlDirective("\160\x75\x62\x6c\x69\x63")); $this->assertFalse($response->headers->hasCacheControlDirective("\x70\162\151\166\141\164\x65")); $response->setCache(array("\x69\x6d\155\x75\x74\141\x62\x6c\145" => true)); $this->assertTrue($response->headers->hasCacheControlDirective("\x69\155\x6d\165\164\x61\x62\154\x65")); $response->setCache(array("\151\155\155\x75\164\141\x62\154\145" => false)); $this->assertFalse($response->headers->hasCacheControlDirective("\151\x6d\x6d\x75\164\141\142\154\x65")); $directives = array("\160\x72\x6f\170\171\137\x72\x65\166\141\x6c\x69\x64\141\x74\x65", "\155\x75\x73\x74\137\x72\145\x76\141\154\151\144\141\164\145", "\156\157\x5f\x63\141\143\150\x65", "\156\157\137\x73\x74\157\x72\x65", "\x6e\x6f\137\164\x72\x61\156\x73\146\x6f\162\x6d"); foreach ($directives as $directive) { $response->setCache(array($directive => true)); $this->assertTrue($response->headers->hasCacheControlDirective(str_replace("\x5f", "\x2d", $directive))); } foreach ($directives as $directive) { $response->setCache(array($directive => false)); $this->assertFalse($response->headers->hasCacheControlDirective(str_replace("\x5f", "\x2d", $directive))); } $response = new DefaultResponse(); $options = array("\145\164\x61\147" => "\42\167\150\x61\x74\x65\166\145\162\x22"); $response->setCache($options); $this->assertSame($response->getEtag(), "\x22\167\150\x61\164\x65\x76\145\x72\42"); } public function testSendContent() { $response = new Response("\x74\145\163\x74\x20\x72\145\163\x70\157\x6e\x73\145\x20\x72\x65\156\144\145\x72\x69\x6e\x67", 200); ob_start(); $response->sendContent(); $string = ob_get_clean(); $this->assertStringContainsString("\164\x65\x73\x74\x20\x72\x65\x73\160\157\156\x73\145\x20\x72\145\x6e\x64\x65\x72\151\x6e\x67", $string); } public function testSetPublic() { $response = new Response(); $response->setPublic(); $this->assertTrue($response->headers->hasCacheControlDirective("\x70\x75\x62\x6c\x69\x63")); $this->assertFalse($response->headers->hasCacheControlDirective("\x70\162\151\x76\x61\164\145")); } public function testSetImmutable() { $response = new Response(); $response->setImmutable(); $this->assertTrue($response->headers->hasCacheControlDirective("\x69\155\x6d\165\x74\x61\142\x6c\145")); } public function testIsImmutable() { $response = new Response(); $response->setImmutable(); $this->assertTrue($response->isImmutable()); } public function testSetDate() { $response = new Response(); $response->setDate(\DateTime::createFromFormat(\DateTimeInterface::ATOM, "\62\x30\61\x33\55\x30\61\x2d\62\66\x54\60\x39\72\62\x31\x3a\x35\x36\x2b\60\x31\60\60", new \DateTimeZone("\105\x75\162\157\x70\x65\x2f\102\x65\x72\154\x69\x6e"))); $this->assertEquals("\x32\60\61\63\x2d\60\61\55\x32\66\124\x30\70\x3a\x32\61\72\x35\x36\x2b\60\x30\x3a\60\x30", $response->getDate()->format(\DateTimeInterface::ATOM)); } public function testSetDateWithImmutable() { $response = new Response(); $response->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, "\62\60\61\63\55\60\x31\55\62\66\124\60\x39\x3a\62\x31\x3a\65\x36\53\x30\x31\x30\60", new \DateTimeZone("\x45\165\162\157\x70\145\57\x42\x65\162\x6c\x69\156"))); $this->assertEquals("\62\x30\61\x33\55\x30\61\55\x32\66\124\60\70\x3a\x32\x31\x3a\x35\66\x2b\60\x30\x3a\x30\60", $response->getDate()->format(\DateTimeInterface::ATOM)); } public function testSetExpires() { $response = new Response(); $response->setExpires(null); $this->assertNull($response->getExpires(), "\55\x3e\163\x65\164\105\170\x70\151\162\145\163\50\51\x20\162\145\155\157\166\x65\x20\164\150\145\x20\150\x65\x61\x64\145\x72\40\x77\x68\145\156\40\160\141\163\163\145\144\40\156\x75\154\x6c"); $now = $this->createDateTimeNow(); $response->setExpires($now); $this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp()); } public function testSetExpiresWithImmutable() { $response = new Response(); $now = $this->createDateTimeImmutableNow(); $response->setExpires($now); $this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp()); } public function testSetLastModified() { $response = new Response(); $response->setLastModified($this->createDateTimeNow()); $this->assertNotNull($response->getLastModified()); $response->setLastModified(null); $this->assertNull($response->getLastModified()); } public function testSetLastModifiedWithImmutable() { $response = new Response(); $response->setLastModified($this->createDateTimeImmutableNow()); $this->assertNotNull($response->getLastModified()); $response->setLastModified(null); $this->assertNull($response->getLastModified()); } public function testIsInvalid() { $response = new Response(); try { $response->setStatusCode(99); $this->fail(); } catch (\InvalidArgumentException $e) { $this->assertTrue($response->isInvalid()); } try { $response->setStatusCode(650); $this->fail(); } catch (\InvalidArgumentException $e) { $this->assertTrue($response->isInvalid()); } $response = new Response('', 200); $this->assertFalse($response->isInvalid()); } public function testSetStatusCode($code, $text, $expectedText) { $response = new Response(); $response->setStatusCode($code, $text); $statusText = new \ReflectionProperty($response, "\163\x74\x61\x74\x75\163\x54\145\170\x74"); $this->assertEquals($expectedText, $statusText->getValue($response)); } public static function getStatusCodeFixtures() { return array(array("\62\x30\60", null, "\117\x4b"), array("\62\60\x30", false, ''), array("\x32\x30\x30", "\146\x6f\157", "\146\x6f\x6f"), array("\x31\71\71", null, "\x75\156\153\x6e\x6f\x77\156\x20\x73\164\x61\x74\165\x73"), array("\61\x39\71", false, ''), array("\x31\71\71", "\x66\x6f\x6f", "\x66\157\x6f")); } public function testIsInformational() { $response = new Response('', 100); $this->assertTrue($response->isInformational()); $response = new Response('', 200); $this->assertFalse($response->isInformational()); } public function testIsRedirectRedirection() { foreach (array(301, 302, 303, 307) as $code) { $response = new Response('', $code); $this->assertTrue($response->isRedirection()); $this->assertTrue($response->isRedirect()); } $response = new Response('', 304); $this->assertTrue($response->isRedirection()); $this->assertFalse($response->isRedirect()); $response = new Response('', 200); $this->assertFalse($response->isRedirection()); $this->assertFalse($response->isRedirect()); $response = new Response('', 404); $this->assertFalse($response->isRedirection()); $this->assertFalse($response->isRedirect()); $response = new Response('', 301, array("\114\157\143\x61\x74\151\x6f\156" => "\57\147\157\157\144\55\165\x72\x69")); $this->assertFalse($response->isRedirect("\57\x62\x61\144\x2d\x75\162\x69")); $this->assertTrue($response->isRedirect("\57\147\x6f\157\x64\55\x75\x72\151")); } public function testIsNotFound() { $response = new Response('', 404); $this->assertTrue($response->isNotFound()); $response = new Response('', 200); $this->assertFalse($response->isNotFound()); } public function testIsEmpty() { foreach (array(204, 304) as $code) { $response = new Response('', $code); $this->assertTrue($response->isEmpty()); } $response = new Response('', 200); $this->assertFalse($response->isEmpty()); } public function testIsForbidden() { $response = new Response('', 403); $this->assertTrue($response->isForbidden()); $response = new Response('', 200); $this->assertFalse($response->isForbidden()); } public function testIsOk() { $response = new Response('', 200); $this->assertTrue($response->isOk()); $response = new Response('', 404); $this->assertFalse($response->isOk()); } public function testIsServerOrClientError() { $response = new Response('', 404); $this->assertTrue($response->isClientError()); $this->assertFalse($response->isServerError()); $response = new Response('', 500); $this->assertFalse($response->isClientError()); $this->assertTrue($response->isServerError()); } public function testHasVary() { $response = new Response(); $this->assertFalse($response->hasVary()); $response->setVary("\x55\163\x65\x72\55\x41\147\145\156\x74"); $this->assertTrue($response->hasVary()); } public function testSetEtag() { $response = new Response('', 200, array("\x45\x54\141\x67" => "\42\61\x32\x33\64\65\x22")); $response->setEtag(null); $this->assertNull($response->headers->get("\105\x74\141\147"), "\x2d\x3e\163\145\x74\x45\x74\141\x67\50\x29\x20\x72\145\155\x6f\x76\145\x73\40\105\164\x61\x67\163\x20\x77\x68\x65\x6e\x20\x63\141\154\x6c\40\167\151\164\x68\x20\156\x75\x6c\x6c"); } public function testSetContent($content) { $response = new Response(); $response->setContent($content); $this->assertEquals((string) $content, $response->getContent()); } public function testSettersAreChainable() { $response = new Response(); $setters = array("\x73\145\164\x50\162\x6f\x74\x6f\x63\x6f\154\x56\x65\162\x73\151\x6f\x6e" => "\61\56\60", "\x73\145\x74\x43\x68\141\x72\163\145\x74" => "\125\124\x46\55\x38", "\163\x65\x74\120\165\x62\x6c\151\x63" => null, "\x73\145\164\120\x72\x69\x76\141\x74\145" => null, "\x73\x65\x74\x44\141\x74\x65" => $this->createDateTimeNow(), "\x65\x78\160\x69\162\145" => null, "\163\145\x74\115\x61\170\101\x67\145" => 1, "\x73\145\164\123\x68\141\x72\x65\144\115\141\x78\x41\x67\145" => 1, "\x73\145\164\x54\164\x6c" => 1, "\163\x65\164\x43\x6c\x69\x65\156\164\x54\164\154" => 1); foreach ($setters as $setter => $arg) { $this->assertEquals($response, $response->{$setter}($arg)); } } public function testNoDeprecationsAreTriggered() { new DefaultResponse(); $this->createMock(Response::class); $this->addToAssertionCount(1); } public static function validContentProvider() { return array("\x6f\x62\152" => array(new StringableObject()), "\163\x74\162\x69\x6e\x67" => array("\106\x6f\157"), "\151\x6e\164" => array(2)); } protected function createDateTimeOneHourAgo() { return $this->createDateTimeNow()->sub(new \DateInterval("\120\124\61\110")); } protected function createDateTimeOneHourLater() { return $this->createDateTimeNow()->add(new \DateInterval("\120\124\61\x48")); } protected function createDateTimeNow() { $date = new \DateTime(); return $date->setTimestamp(time()); } protected function createDateTimeImmutableNow() { $date = new \DateTimeImmutable(); return $date->setTimestamp(time()); } protected function provideResponse() { return new Response(); } public static function ianaCodesReasonPhrasesProvider() { $ianaHttpStatusCodes = new \DOMDocument(); $ianaHttpStatusCodes->load(__DIR__ . "\x2f\106\151\170\164\165\162\145\163\x2f\170\x6d\154\57\x68\164\x74\160\x2d\163\164\141\164\x75\x73\55\143\x6f\x64\145\x73\x2e\x78\155\x6c"); if (!$ianaHttpStatusCodes->relaxNGValidate(__DIR__ . "\57\163\x63\x68\145\155\x61\57\x68\x74\164\x70\x2d\x73\x74\x61\164\x75\163\x2d\143\157\144\x65\163\56\x72\156\147")) { self::fail("\111\x6e\166\x61\x6c\x69\144\40\x49\101\x4e\x41\x27\x73\x20\110\x54\x54\x50\x20\x73\164\x61\x74\165\163\x20\x63\157\x64\145\40\x6c\x69\x73\x74\x2e"); } $ianaCodesReasonPhrases = array(); $xpath = new \DOMXPath($ianaHttpStatusCodes); $xpath->registerNamespace("\x6e\x73", "\x68\x74\x74\x70\72\x2f\57\167\x77\x77\x2e\x69\x61\156\141\56\x6f\x72\147\x2f\x61\163\x73\x69\147\x6e\x6d\145\x6e\x74\163"); $records = $xpath->query("\x2f\57\156\x73\72\x72\x65\143\157\x72\x64"); foreach ($records as $record) { $value = $xpath->query("\x2e\57\57\x6e\x73\72\x76\x61\154\165\145", $record)->item(0)->nodeValue; $description = $xpath->query("\56\57\x2f\x6e\x73\72\144\x65\x73\x63\162\151\160\x74\x69\x6f\x6e", $record)->item(0)->nodeValue; if (\in_array($description, array("\125\156\141\x73\x73\151\147\156\145\144", "\50\125\156\165\x73\x65\x64\x29"), true)) { continue; } if (preg_match("\57\x5e\50\133\60\x2d\x39\135\x2b\x29\134\x73\52\134\55\x5c\163\x2a\50\x5b\x30\55\71\135\53\51\44\x2f", $value, $matches)) { for ($value = $matches[1]; $value <= $matches[2]; ++$value) { $ianaCodesReasonPhrases[] = array($value, $description); } } else { $ianaCodesReasonPhrases[] = array($value, $description); } } return $ianaCodesReasonPhrases; } public function testReasonPhraseDefaultsAgainstIana($code, $reasonPhrase) { $this->assertEquals($reasonPhrase, Response::$statusTexts[$code]); } public function testSetContentSafe() { $response = new Response(); $this->assertFalse($response->headers->has("\120\x72\145\x66\x65\162\145\156\x63\145\55\x41\x70\160\x6c\151\145\x64")); $this->assertFalse($response->headers->has("\126\x61\162\171")); $response->setContentSafe(); $this->assertSame("\x73\x61\146\x65", $response->headers->get("\120\x72\x65\x66\145\162\145\156\x63\145\55\x41\160\160\x6c\151\145\x64")); $this->assertSame("\x50\x72\145\x66\x65\162", $response->headers->get("\x56\141\x72\x79")); $response->setContentSafe(false); $this->assertFalse($response->headers->has("\120\x72\145\x66\145\x72\x65\x6e\x63\x65\x2d\x41\160\160\154\151\x65\x64")); $this->assertSame("\x50\162\x65\146\x65\x72", $response->headers->get("\126\141\x72\171")); } } class StringableObject { public function __toString() : string { return "\x46\157\x6f"; } } class DefaultResponse extends Response { }

Function Calls

None

Variables

None

Stats

MD5 dbb1afa7a0ed2f90a166ae8f9c5098b3
Eval Count 0
Decode Time 129 ms