Commit e0d7de37 authored by Julien Fastré's avatar Julien Fastré
Browse files

add test + fix possible bug with null value

parent 570bd5b9
Pipeline #612 skipped
......@@ -22,7 +22,6 @@ namespace Chill\ICPC2Bundle\CustomField;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\CustomFields\AbstractCustomField;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -139,6 +138,10 @@ class CustomFieldICPC2Code extends AbstractCustomField
*/
public function serialize($value, CustomField $customField)
{
if ($value === NULL) {
return null;
}
return $value->getCode();
}
......
......@@ -78,13 +78,68 @@ class CustomFieldICPC2CodeTest extends KernelTestCase
{
$cf = $this->generateCustomField();
$data = array(
'slug' => null
);
$data = $this->cfICPC2->deserialize(null, $cf);;
$isEmpty = $this->cfICPC2->isEmptyValue($data, $cf);
$this->assertTrue($isEmpty);
}
public function testIsEmtpyWithNonEmptyValue()
{
$cf = $this->generateCustomField();
$data = $this->cfICPC2->deserialize('A05', $cf);
$isEmpty = $this->cfICPC2->isEmptyValue($data, $cf);
$this->assertFalse($isEmpty);
$cf = $this->generateCustomField();
}
/////////////////////////////////////////
//
// test function deserialize
//
////////////////////////////////////////
public function testDeserialized()
{
$cf = $this->generateCustomField();
$code1 = $this->cfICPC2->deserialize('A05', $cf);
$code2 = $this->cfICPC2->deserialize('D01', $cf);
$codeNull = $this->cfICPC2->deserialize(null, $cf);
$this->assertInstanceOf('Chill\ICPC2Bundle\Entity\Code', $code1);
$this->assertInstanceOf('Chill\ICPC2Bundle\Entity\Code', $code2);
$this->assertNull($codeNull);
}
/////////////////////////////////////////
//
// test function serialize
//
////////////////////////////////////////
public function testSerialize()
{
$repository = self::$kernel->getContainer()->get('doctrine.orm.entity_manager')
->getRepository('ChillICPC2Bundle:Code');
$codeA07 = $repository->findOneBy(array('code' => 'A07'));
$code32 = $repository->findOneBy(array('code' => -32));
$cf = $this->generateCustomField();
$serializedA07 = $this->cfICPC2->serialize($codeA07, $cf);
$serialized32 = $this->cfICPC2->serialize($code32, $cf);
$serializedNull = $this->cfICPC2->serialize(null, $cf);
$this->assertEquals('A07', $serializedA07);
$this->assertEquals(-32, $serialized32);
$this->assertNull($serializedNull);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment