Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-30712: Fixed reverseTransform for midnight value #301

Merged
merged 4 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/FieldType/DataTransformer/TimeValueTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function transform($value)
*/
public function reverseTransform($value)
{
if (empty($value)) {
if (null === $value || $value === '') {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* This file is part of the eZ RepositoryForms package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Tests\FieldType\DataTransformer;

use DateTime;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Exception\TransformationFailedException;
use eZ\Publish\Core\FieldType\Time\Value;
use EzSystems\RepositoryForms\FieldType\DataTransformer\TimeValueTransformer;

class TimeValueTransformerTest extends TestCase
{
public function testTransform()
{
$date = new DateTime();
$value = Value::fromDateTime($date);
$transformer = new TimeValueTransformer();
$time = $date->getTimestamp() - $date->setTime(0, 0, 0)->getTimestamp();

self::assertSame($time, $transformer->transform($value));
}

public function testTransformZero()
{
$value = new Value(0);
$transformer = new TimeValueTransformer();

self::assertSame(0, $transformer->transform($value));
alongosz marked this conversation as resolved.
Show resolved Hide resolved
}

public function testTransformNull()
{
$value = new Value(null);
$transformer = new TimeValueTransformer();

self::assertNull($transformer->transform($value));
}

public function testTransformInvalidValue()
{
$transformer = new TimeValueTransformer();

$this->expectException(TransformationFailedException::class);
$transformer->transform((object) ['time' => 1]);
}
}