diff --git a/src/SE/Component/BMEcat/Node/ArticleNode.php b/src/SE/Component/BMEcat/Node/ArticleNode.php index f156099..74ae536 100644 --- a/src/SE/Component/BMEcat/Node/ArticleNode.php +++ b/src/SE/Component/BMEcat/Node/ArticleNode.php @@ -68,6 +68,16 @@ class ArticleNode extends AbstractNode */ protected $features = []; + /** + * @Serializer\Expose + * @Serializer\SerializedName("MIME_INFO") + * @Serializer\Type("array") + * @Serializer\XmlList( entry="MIME") + * + * @var \SE\Component\BMEcat\Node\MimeNode[] + */ + protected $mimeInfo = []; + /** * * @param \SE\Component\BMEcat\Node\ArticleDetailsNode $detail @@ -97,7 +107,6 @@ public function addFeature(ArticleFeatureNode $feature) } $this->features []= $feature; } - /** * * @param \SE\Component\BMEcat\Node\ArticlePriceNode $price @@ -110,6 +119,19 @@ public function addPrice(ArticlePriceNode $price) $this->prices []= $price; } + + /** + * + * @param \SE\Component\BMEcat\Node\MimeNode $mime + */ + public function addMime(MimeNode $mime) + { + if($this->mimeInfo === null) { + $this->mimeInfo = []; + } + $this->mimeInfo []= $mime; + } + /** * * @Serializer\PreSerialize @@ -134,6 +156,17 @@ public function nullPrices() } } + /** + * @Serializer\PreSerialize + * @Serializer\PostSerialize + */ + public function nullMimeInfo() + { + if(empty($this->mimeInfo) === true) { + $this->mimeInfo = null; + } + } + /** * * @param string $id @@ -177,4 +210,17 @@ public function getPrices() return $this->prices; } + + /** + * + * @return \SE\Component\BMEcat\Node\MimeNode[] + */ + public function getMimeInfo() + { + if($this->mimeInfo === null) { + return []; + } + + return $this->mimeInfo; + } } \ No newline at end of file diff --git a/src/SE/Component/BMEcat/Node/MimeNode.php b/src/SE/Component/BMEcat/Node/MimeNode.php new file mode 100644 index 0000000..0a5b4b3 --- /dev/null +++ b/src/SE/Component/BMEcat/Node/MimeNode.php @@ -0,0 +1,99 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SE\Component\BMEcat\Node; + +use \JMS\Serializer\Annotation as Serializer; +use \SE\Component\BMEcat\Node\AbstractNode; + +/** + * Class MimeInfoNode + * @package SE\Component\BMEcat\Node + * @author Jan Kahnt + * + * @Serializer\XmlRoot("MIME") + */ +class MimeNode extends AbstractNode { + + /** + * @Serializer\Expose + * @Serializer\Type("string") + * @Serializer\SerializedName("MIME_TYPE") + * + * @var string + */ + protected $type; + + /** + * @Serializer\Expose + * @Serializer\Type("string") + * @Serializer\SerializedName("MIME_SOURCE") + * + * @var string + */ + protected $source; + + /** + * @Serializer\Expose + * @Serializer\Type("string") + * @Serializer\SerializedName("MIME_PURPOSE") + * + * @var string + */ + protected $purpose; + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getSource() + { + return $this->source; + } + + /** + * @param string $source + */ + public function setSource($source) + { + $this->source = $source; + } + + /** + * @return string + */ + public function getPurpose() + { + return $this->purpose; + } + + /** + * @param string $purpose + */ + public function setPurpose($purpose) + { + $this->purpose = $purpose; + } +} \ No newline at end of file diff --git a/tests/SE/Component/BMEcat/Tests/DocumentTest.php b/tests/SE/Component/BMEcat/Tests/DocumentTest.php index 2b13e32..78c00e3 100644 --- a/tests/SE/Component/BMEcat/Tests/DocumentTest.php +++ b/tests/SE/Component/BMEcat/Tests/DocumentTest.php @@ -76,6 +76,22 @@ public function setUp() $article->addFeature($feature); } + foreach([ + ['image/jpeg', 'http://a.b/c/d.jpg', 'normal'], + ['image/bmp', 'http://w.x/y/z.bmp', 'thumbnail'] + ] as $value) { + + list($type, $source, $purpose) = $value; + + $mime = new \SE\Component\BMEcat\Node\MimeNode(); + + $mime->setType($type); + $mime->setSource($source); + $mime->setPurpose($purpose); + + $article->addMime($mime); + } + $catalog->addArticle($article); } diff --git a/tests/SE/Component/BMEcat/Tests/Fixtures/document_with_null_values.xml b/tests/SE/Component/BMEcat/Tests/Fixtures/document_with_null_values.xml index 6873d29..07df957 100644 --- a/tests/SE/Component/BMEcat/Tests/Fixtures/document_with_null_values.xml +++ b/tests/SE/Component/BMEcat/Tests/Fixtures/document_with_null_values.xml @@ -43,6 +43,18 @@ + + + + + + + + + + + +
@@ -69,6 +81,18 @@ + + + + + + + + + + + +
@@ -95,6 +119,18 @@ + + + + + + + + + + + +
diff --git a/tests/SE/Component/BMEcat/Tests/Fixtures/document_without_null_values.xml b/tests/SE/Component/BMEcat/Tests/Fixtures/document_without_null_values.xml index f58cb50..6bff279 100644 --- a/tests/SE/Component/BMEcat/Tests/Fixtures/document_without_null_values.xml +++ b/tests/SE/Component/BMEcat/Tests/Fixtures/document_without_null_values.xml @@ -42,6 +42,18 @@ + + + + + + + + + + + +
@@ -67,6 +79,18 @@ + + + + + + + + + + + +
@@ -92,6 +116,18 @@ + + + + + + + + + + + +
diff --git a/tests/SE/Component/BMEcat/Tests/Fixtures/empty_article_with_null_values.xml b/tests/SE/Component/BMEcat/Tests/Fixtures/empty_article_with_null_values.xml index d651140..2ef0810 100644 --- a/tests/SE/Component/BMEcat/Tests/Fixtures/empty_article_with_null_values.xml +++ b/tests/SE/Component/BMEcat/Tests/Fixtures/empty_article_with_null_values.xml @@ -4,4 +4,5 @@ + diff --git a/tests/SE/Component/BMEcat/Tests/Fixtures/empty_mime_info_with_null_values.xml b/tests/SE/Component/BMEcat/Tests/Fixtures/empty_mime_info_with_null_values.xml new file mode 100644 index 0000000..06799d0 --- /dev/null +++ b/tests/SE/Component/BMEcat/Tests/Fixtures/empty_mime_info_with_null_values.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/SE/Component/BMEcat/Tests/Fixtures/empty_mime_info_without_null_values.xml b/tests/SE/Component/BMEcat/Tests/Fixtures/empty_mime_info_without_null_values.xml new file mode 100644 index 0000000..7e92a84 --- /dev/null +++ b/tests/SE/Component/BMEcat/Tests/Fixtures/empty_mime_info_without_null_values.xml @@ -0,0 +1,2 @@ + + diff --git a/tests/SE/Component/BMEcat/Tests/Node/ArticleNodeTest.php b/tests/SE/Component/BMEcat/Tests/Node/ArticleNodeTest.php index 949c681..e00b889 100644 --- a/tests/SE/Component/BMEcat/Tests/Node/ArticleNodeTest.php +++ b/tests/SE/Component/BMEcat/Tests/Node/ArticleNodeTest.php @@ -99,6 +99,30 @@ public function Add_Get_Prices() $this->assertSame($prices, $node->getPrices()); } + /** + * + * @test + */ + public function Add_Get_MimeInfo() + { + $mimeInfo = [ + new \SE\Component\BMEcat\Node\MimeNode(), + new \SE\Component\BMEcat\Node\MimeNode(), + new \SE\Component\BMEcat\Node\MimeNode() + ]; + + $node = new \SE\Component\BMEcat\Node\ArticleNode(); + $this->assertEmpty($node->getMimeInfo()); + $node->nullMimeInfo(); + $this->assertEquals([], $node->getMimeInfo()); + + foreach($mimeInfo as $mime) { + $node->addMime($mime); + } + + $this->assertSame($mimeInfo, $node->getMimeInfo()); + } + /** * * @test diff --git a/tests/SE/Component/BMEcat/Tests/Node/MimeNodeTest.php b/tests/SE/Component/BMEcat/Tests/Node/MimeNodeTest.php new file mode 100644 index 0000000..b170238 --- /dev/null +++ b/tests/SE/Component/BMEcat/Tests/Node/MimeNodeTest.php @@ -0,0 +1,93 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SE\Component\BMEcat\Tests\Node; + +/** + * + * @package SE\Component\BMEcat\Tests + * @author Jan Kahnt + */ +class MimeNodeTest extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->serializer = \JMS\Serializer\SerializerBuilder::create()->build(); + } + + /** + * @test + */ + public function Set_Get_Type() + { + $node = new \SE\Component\BMEcat\Node\MimeNode(); + $value = sha1(uniqid(microtime(false), true)); + + $this->assertNull($node->getType()); + $node->setType($value); + $this->assertEquals($value, $node->getType()); + } + + /** + * @test + */ + public function Set_Get_Source() + { + $node = new \SE\Component\BMEcat\Node\MimeNode(); + $value = sha1(uniqid(microtime(false), true)); + + $this->assertNull($node->getSource()); + $node->setSource($value); + $this->assertEquals($value, $node->getSource()); + } + + /** + * @test + */ + public function Set_Get_Purpose() + { + $node = new \SE\Component\BMEcat\Node\MimeNode(); + $value = sha1(uniqid(microtime(false), true)); + + $this->assertNull($node->getPurpose()); + $node->setPurpose($value); + $this->assertEquals($value, $node->getPurpose()); + } + + /** + * + * @test + */ + public function Serialize_With_Null_Values() + { + $node = new \SE\Component\BMEcat\Node\MimeNode(); + $context = \JMS\Serializer\SerializationContext::create()->setSerializeNull(true); + + $expected = file_get_contents(__DIR__.'/../Fixtures/empty_mime_info_with_null_values.xml'); + $actual = $this->serializer->serialize($node, 'xml', $context); + + $this->assertEquals($expected, $actual); + } + + /** + * + * @test + */ + public function Serialize_Without_Null_Values() + { + $node = new \SE\Component\BMEcat\Node\MimeNode(); + $context = \JMS\Serializer\SerializationContext::create()->setSerializeNull(false); + + $expected = file_get_contents(__DIR__.'/../Fixtures/empty_mime_info_without_null_values.xml'); + $actual = $this->serializer->serialize($node, 'xml', $context); + + $this->assertEquals($expected, $actual); + } +}