Merge branch '2.8' into 3.2
* 2.8: HttpCache: New test for revalidating responses with an expired TTL [Serializer] [XML] Ignore Process Instruction
This commit is contained in:
commit
664740698e
@ -849,6 +849,42 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceNotContains('miss');
|
||||
}
|
||||
|
||||
public function testServesResponseWhileFreshAndRevalidatesWithLastModifiedInformation()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$this->setNextResponse(200, array(), 'Hello World', function (Request $request, Response $response) use ($time) {
|
||||
$response->setSharedMaxAge(10);
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
});
|
||||
|
||||
// prime the cache
|
||||
$this->request('GET', '/');
|
||||
|
||||
// next request before s-maxage has expired: Serve from cache
|
||||
// without hitting the backend
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
sleep(15); // expire the cache
|
||||
|
||||
$that = $this;
|
||||
|
||||
$this->setNextResponse(304, array(), '', function (Request $request, Response $response) use ($time, $that) {
|
||||
$that->assertEquals($time->format(DATE_RFC2822), $request->headers->get('IF_MODIFIED_SINCE'));
|
||||
});
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('stale');
|
||||
$this->assertTraceContains('valid');
|
||||
}
|
||||
|
||||
public function testReplacesCachedResponsesWhenValidationResultsInNon304Response()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
@ -95,14 +95,16 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
throw new UnexpectedValueException($error->message);
|
||||
}
|
||||
|
||||
$rootNode = null;
|
||||
foreach ($dom->childNodes as $child) {
|
||||
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
|
||||
throw new UnexpectedValueException('Document types are not allowed.');
|
||||
}
|
||||
if (!$rootNode && $child->nodeType !== XML_PI_NODE) {
|
||||
$rootNode = $child;
|
||||
}
|
||||
}
|
||||
|
||||
$rootNode = $dom->firstChild;
|
||||
|
||||
// todo: throw an exception if the root node name is not correctly configured (bc)
|
||||
|
||||
if ($rootNode->hasChildNodes()) {
|
||||
@ -332,6 +334,10 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
$value = array();
|
||||
|
||||
foreach ($node->childNodes as $subnode) {
|
||||
if ($subnode->nodeType === XML_PI_NODE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$val = $this->parseXml($subnode);
|
||||
|
||||
if ('item' === $subnode->nodeName && isset($val['@key'])) {
|
||||
|
@ -370,6 +370,44 @@ XML;
|
||||
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
|
||||
}
|
||||
|
||||
public function testDecodeXMLWithProcessInstruction()
|
||||
{
|
||||
$source = <<<'XML'
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/xsl" href="/xsl/xmlverbatimwrapper.xsl"?>
|
||||
<?display table-view?>
|
||||
<?sort alpha-ascending?>
|
||||
<response>
|
||||
<foo>foo</foo>
|
||||
<?textinfo whitespace is allowed ?>
|
||||
<bar>a</bar>
|
||||
<bar>b</bar>
|
||||
<baz>
|
||||
<key>val</key>
|
||||
<key2>val</key2>
|
||||
<item key="A B">bar</item>
|
||||
<item>
|
||||
<title>title1</title>
|
||||
</item>
|
||||
<?item ignore-title ?>
|
||||
<item>
|
||||
<title>title2</title>
|
||||
</item>
|
||||
<Barry>
|
||||
<FooBar id="1">
|
||||
<Baz>Ed</Baz>
|
||||
</FooBar>
|
||||
</Barry>
|
||||
</baz>
|
||||
<qux>1</qux>
|
||||
</response>
|
||||
<?instruction <value> ?>
|
||||
XML;
|
||||
$obj = $this->getObject();
|
||||
|
||||
$this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml'));
|
||||
}
|
||||
|
||||
public function testDecodeIgnoreWhiteSpace()
|
||||
{
|
||||
$source = <<<'XML'
|
||||
|
Reference in New Issue
Block a user