Skip to content

Commit

Permalink
Merge branch '6.7' into 6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Dunogier committed Mar 31, 2017
2 parents 3e5be10 + 1bb2fd0 commit da7402c
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 47 deletions.
Expand Up @@ -126,7 +126,7 @@ public function onKernelRequestRedirect(GetResponseEvent $event)

$headers = [];
if ($request->attributes->has('locationId')) {
$headers[ 'X-Location-Id'] = $request->attributes->get('locationId');
$headers['X-Location-Id'] = $request->attributes->get('locationId');
}
$event->setResponse(
new RedirectResponse(
Expand Down
12 changes: 9 additions & 3 deletions eZ/Bundle/EzPublishIOBundle/EventListener/StreamFileListener.php
Expand Up @@ -51,9 +51,15 @@ public function onKernelRequest(GetResponseEvent $event)
return;
}

$uri = $event->getRequest()->attributes->get('semanticPathinfo');
$request = $event->getRequest();
$urlPrefix = $this->configResolver->getParameter('io.url_prefix');
if (strpos($urlPrefix, '://') !== false) {
$uri = $request->getSchemeAndHttpHost() . $request->getPathInfo();
} else {
$uri = $request->attributes->get('semanticPathinfo');
}

if (!$this->isIoUri($uri)) {
if (!$this->isIoUri($uri, $urlPrefix)) {
return;
}

Expand All @@ -77,7 +83,7 @@ public function onKernelRequest(GetResponseEvent $event)
*
* @return bool
*/
private function isIoUri($uri)
private function isIoUri($uri, $urlPrefix)
{
return strpos(ltrim($uri, '/'), $this->configResolver->getParameter('io.url_prefix')) === 0;
}
Expand Down
Expand Up @@ -35,11 +35,6 @@ public function setUp()
$this->ioServiceMock = $this->getMock('eZ\Publish\Core\IO\IOServiceInterface');

$this->configResolverMock = $this->getMock('eZ\Publish\Core\MVC\ConfigResolverInterface');
$this->configResolverMock
->expects($this->any())
->method('getParameter')
->with('io.url_prefix')
->will($this->returnValue($this->ioUriPrefix));

$this->eventListener = new StreamFileListener($this->ioServiceMock, $this->configResolverMock);
}
Expand All @@ -49,6 +44,26 @@ public function testDoesNotRespondToNonIoUri()
$request = $this->createRequest('/Not-an-image');
$event = $this->createEvent($request);

$this->configureIoUrlPrefix('var/test/storage');
$this->ioServiceMock
->expects($this->never())
->method('loadBinaryFileByUri');

$this->eventListener->onKernelRequest($event);

self::assertNull($event->getResponse());
}

public function testDoesNotRespondToNoIoRequest()
{
$request = $this->createRequest('/Not-an-image', 'bar.fr');
$event = $this->createEvent($request);

$this->configureIoUrlPrefix('http://foo.com/var/test/storage');
$this->ioServiceMock
->expects($this->never())
->method('loadBinaryFileByUri');

$this->eventListener->onKernelRequest($event);

self::assertNull($event->getResponse());
Expand All @@ -57,6 +72,7 @@ public function testDoesNotRespondToNonIoUri()
public function testRespondsToIoUri()
{
$uri = '/var/test/storage/images/image.png';
$this->configureIoUrlPrefix(ltrim($uri, '/'));
$request = $this->createRequest($uri);

$event = $this->createEvent($request);
Expand All @@ -78,12 +94,48 @@ public function testRespondsToIoUri()
);
}

public function testRespondsToIoRequest()
{
$uri = '/var/test/storage/images/image.png';
$host = 'phoenix-rises.fm';
$urlPrefix = "http://$host/var/test/storage";
$this->configureIoUrlPrefix($urlPrefix);
$request = $this->createRequest($uri, $host);

$event = $this->createEvent($request);

$binaryFile = new BinaryFile(array('mtime' => new DateTime()));

$this->ioServiceMock
->expects($this->once())
->method('loadBinaryFileByUri')
->with(sprintf('http://%s%s', $host, $uri))
->will($this->returnValue($binaryFile));

$this->eventListener->onKernelRequest($event);

self::assertTrue($event->hasResponse());
self::assertEquals(
new BinaryStreamResponse($binaryFile, $this->ioServiceMock),
$event->getResponse()
);
}

private function configureIoUrlPrefix($urlPrefix)
{
$this->configResolverMock
->expects($this->any())
->method('getParameter')
->with('io.url_prefix')
->willReturn($urlPrefix);
}

/**
* @return Request
*/
protected function createRequest($semanticPath)
protected function createRequest($semanticPath, $host = 'localhost')
{
$request = new Request();
$request = Request::create(sprintf('http://%s%s', $host, $semanticPath));
$request->attributes->set('semanticPathinfo', $semanticPath);

return $request;
Expand Down
41 changes: 20 additions & 21 deletions eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php
Expand Up @@ -109,7 +109,9 @@ public function getInvalidValidatorConfiguration()
*/
public function getValidCreationFieldData()
{
return DateValue::fromString('Wed, 21 Jul 2013 16:59:50');
// We may only create times from timestamps here, since storing will
// loose information about the timezone.
return DateValue::fromTimestamp(86400);
}

/**
Expand All @@ -119,7 +121,7 @@ public function getValidCreationFieldData()
*/
public function getFieldName()
{
return 'Wednesday 24 July 2013';
return 'Friday 02 January 1970';
}

/**
Expand All @@ -137,11 +139,10 @@ public function assertFieldDataLoadedCorrect(Field $field)
$field->value
);

$dateTime = new DateTime('Wed, 21 Jul 2013 16:59:50');
$dateTime->setTime(0, 0, 0);
$expectedData = array(
'date' => $dateTime,
'date' => new DateTime('@86400'),
);

$this->assertPropertiesCorrect(
$expectedData,
$field->value
Expand Down Expand Up @@ -186,11 +187,11 @@ public function provideInvalidCreationFieldData()
*/
public function getValidUpdateFieldData()
{
return DateValue::fromString('Wed, 21 Jul 2013 17:59:50');
return DateValue::fromTimestamp(86400);
}

/**
* Asserts the the field data was loaded correctly.
* Asserts the field data was loaded correctly.
*
* Asserts that the data provided by {@link getValidUpdateFieldData()}
* was stored and loaded correctly.
Expand All @@ -204,10 +205,8 @@ public function assertUpdatedFieldDataLoadedCorrect(Field $field)
$field->value
);

$dateTime = new DateTime('Wed, 21 Jul 2013 17:59:50');
$dateTime->setTime(0, 0, 0);
$expectedData = array(
'date' => $dateTime,
'date' => new DateTime('@86400'),
);
$this->assertPropertiesCorrect(
$expectedData,
Expand Down Expand Up @@ -276,13 +275,14 @@ public function assertCopiedFieldDataLoadedCorrectly(Field $field)
*/
public function provideToHashData()
{
$dateTime = new DateTime();
$timestamp = 186401;
$dateTime = new DateTime("@{$timestamp}");

return array(
array(
DateValue::fromTimestamp($timestamp = 186401),
DateValue::fromTimestamp($timestamp),
array(
'timestamp' => $dateTime->setTimestamp($timestamp)->setTime(0, 0, 0)->getTimestamp(),
'timestamp' => $dateTime->setTime(0, 0, 0)->getTimestamp(),
'rfc850' => $dateTime->format(DateTime::RFC850),
),
),
Expand Down Expand Up @@ -311,19 +311,22 @@ public function provideToHashData()
*/
public function provideFromHashData()
{
$timestamp = 123456;

$dateTime = new DateTime();
$dateTime->setTimestamp($timestamp)->setTime(0, 0, 0);

return array(
array(
array(
'timestamp' => $dateTime->setTimestamp(123456)->setTime(0, 0, 0)->getTimestamp(),
'timestamp' => $timestamp,
'rfc850' => ($rfc850 = $dateTime->format(DateTime::RFC850)),
),
DateValue::fromString($rfc850),
),
array(
array(
'timestamp' => $dateTime->setTimestamp($timestamp = 123456)->setTime(0, 0, 0)->getTimestamp(),
'timestamp' => $timestamp,
'rfc850' => null,
),
DateValue::fromTimestamp($timestamp),
Expand All @@ -349,16 +352,12 @@ public function providerForTestIsNotEmptyValue()

protected function getValidSearchValueOne()
{
$date = new DateTime('1970-01-02');

return $date->getTimestamp();
return 86400;
}

protected function getValidSearchValueTwo()
{
$date = new DateTime('1970-01-03');

return $date->getTimestamp();
return 172800;
}

protected function getSearchTargetValueOne()
Expand Down
6 changes: 1 addition & 5 deletions eZ/Publish/Core/FieldType/Date/SearchField.php
Expand Up @@ -29,11 +29,7 @@ class SearchField implements Indexable
*/
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
{
// The field type stores date value as a timestamp of the start of the day in the
// environment's timezone.
// We format this as Y-m-d and add Z to signify UTC (zero offset).
$dateTime = new DateTime();
$dateTime->setTimestamp($field->value->data['timestamp']);
$dateTime = new DateTime("@{$field->value->data['timestamp']}");

return array(
new Search\Field(
Expand Down
5 changes: 1 addition & 4 deletions eZ/Publish/Core/FieldType/Date/Value.php
Expand Up @@ -76,10 +76,7 @@ public static function fromString($dateString)
public static function fromTimestamp($timestamp)
{
try {
$dateTime = new DateTime();
$dateTime->setTimestamp($timestamp);

return new static($dateTime);
return new static(new DateTime("@{$timestamp}"));
} catch (Exception $e) {
throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e);
}
Expand Down
10 changes: 4 additions & 6 deletions eZ/Publish/Core/FieldType/Tests/DateTest.php
Expand Up @@ -135,8 +135,6 @@ public function provideInvalidInputForAcceptValue()
*/
public function provideValidInputForAcceptValue()
{
$dateTime = new DateTime();

return array(
array(
null,
Expand All @@ -149,12 +147,12 @@ public function provideValidInputForAcceptValue()
array(
($timestamp = 1346149200),
new DateValue(
clone $dateTime->setTimestamp($timestamp)
new DateTime("@{$timestamp}")
),
),
array(
DateValue::fromTimestamp(1372895999),
new DateValue($dateTime->setTimestamp(1372895999)->setTime(0, 0, 0)),
DateValue::fromTimestamp($timestamp = 1372895999),
new DateValue(new DateTime("@{$timestamp}")),
),
array(
($dateTime = new DateTime()),
Expand Down Expand Up @@ -263,7 +261,7 @@ public function provideInputForFromHash()
array(
'timestamp' => ($timestamp = 1362614400),
),
new DateValue(clone $dateTime->setTimestamp($timestamp)),
new DateValue(new DateTime("@{$timestamp}")),
),
array(
array(
Expand Down

0 comments on commit da7402c

Please sign in to comment.