Skip to content

Commit

Permalink
Added MimeInfo Node + Test update (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkahnt authored and sveneisenschmidt committed Dec 30, 2018
1 parent 24154b7 commit c761067
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/SE/Component/BMEcat/Node/ArticleNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ class ArticleNode extends AbstractNode
*/
protected $features = [];

/**
* @Serializer\Expose
* @Serializer\SerializedName("MIME_INFO")
* @Serializer\Type("array<SE\Component\BMEcat\Node\MimeNode>")
* @Serializer\XmlList( entry="MIME")
*
* @var \SE\Component\BMEcat\Node\MimeNode[]
*/
protected $mimeInfo = [];

/**
*
* @param \SE\Component\BMEcat\Node\ArticleDetailsNode $detail
Expand Down Expand Up @@ -97,7 +107,6 @@ public function addFeature(ArticleFeatureNode $feature)
}
$this->features []= $feature;
}

/**
*
* @param \SE\Component\BMEcat\Node\ArticlePriceNode $price
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
99 changes: 99 additions & 0 deletions src/SE/Component/BMEcat/Node/MimeNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* This file is part of the BMEcat php library
*
* (c) Sven Eisenschmidt <sven.eisenschmidt@gmail.com>
*
* 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 <j.kahnt@impericon.com>
*
* @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;
}
}
16 changes: 16 additions & 0 deletions tests/SE/Component/BMEcat/Tests/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
<FVALUE><![CDATA[Y]]></FVALUE>
</FEATURE>
</ARTICLE_FEATURES>
<MIME_INFO>
<MIME>
<MIME_TYPE><![CDATA[image/jpeg]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://a.b/c/d.jpg]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[normal]]></MIME_PURPOSE>
</MIME>
<MIME>
<MIME_TYPE><![CDATA[image/bmp]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://w.x/y/z.bmp]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[thumbnail]]></MIME_PURPOSE>
</MIME>
</MIME_INFO>
</ARTICLE>
<ARTICLE>
<SUPPLIER_AID><![CDATA[2]]></SUPPLIER_AID>
Expand All @@ -69,6 +81,18 @@
<FVALUE><![CDATA[Y]]></FVALUE>
</FEATURE>
</ARTICLE_FEATURES>
<MIME_INFO>
<MIME>
<MIME_TYPE><![CDATA[image/jpeg]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://a.b/c/d.jpg]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[normal]]></MIME_PURPOSE>
</MIME>
<MIME>
<MIME_TYPE><![CDATA[image/bmp]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://w.x/y/z.bmp]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[thumbnail]]></MIME_PURPOSE>
</MIME>
</MIME_INFO>
</ARTICLE>
<ARTICLE>
<SUPPLIER_AID><![CDATA[3]]></SUPPLIER_AID>
Expand All @@ -95,6 +119,18 @@
<FVALUE><![CDATA[Y]]></FVALUE>
</FEATURE>
</ARTICLE_FEATURES>
<MIME_INFO>
<MIME>
<MIME_TYPE><![CDATA[image/jpeg]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://a.b/c/d.jpg]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[normal]]></MIME_PURPOSE>
</MIME>
<MIME>
<MIME_TYPE><![CDATA[image/bmp]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://w.x/y/z.bmp]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[thumbnail]]></MIME_PURPOSE>
</MIME>
</MIME_INFO>
</ARTICLE>
</T_NEW_CATALOG>
</BMEcat>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
<FVALUE><![CDATA[Y]]></FVALUE>
</FEATURE>
</ARTICLE_FEATURES>
<MIME_INFO>
<MIME>
<MIME_TYPE><![CDATA[image/jpeg]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://a.b/c/d.jpg]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[normal]]></MIME_PURPOSE>
</MIME>
<MIME>
<MIME_TYPE><![CDATA[image/bmp]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://w.x/y/z.bmp]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[thumbnail]]></MIME_PURPOSE>
</MIME>
</MIME_INFO>
</ARTICLE>
<ARTICLE>
<SUPPLIER_AID><![CDATA[2]]></SUPPLIER_AID>
Expand All @@ -67,6 +79,18 @@
<FVALUE><![CDATA[Y]]></FVALUE>
</FEATURE>
</ARTICLE_FEATURES>
<MIME_INFO>
<MIME>
<MIME_TYPE><![CDATA[image/jpeg]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://a.b/c/d.jpg]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[normal]]></MIME_PURPOSE>
</MIME>
<MIME>
<MIME_TYPE><![CDATA[image/bmp]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://w.x/y/z.bmp]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[thumbnail]]></MIME_PURPOSE>
</MIME>
</MIME_INFO>
</ARTICLE>
<ARTICLE>
<SUPPLIER_AID><![CDATA[3]]></SUPPLIER_AID>
Expand All @@ -92,6 +116,18 @@
<FVALUE><![CDATA[Y]]></FVALUE>
</FEATURE>
</ARTICLE_FEATURES>
<MIME_INFO>
<MIME>
<MIME_TYPE><![CDATA[image/jpeg]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://a.b/c/d.jpg]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[normal]]></MIME_PURPOSE>
</MIME>
<MIME>
<MIME_TYPE><![CDATA[image/bmp]]></MIME_TYPE>
<MIME_SOURCE><![CDATA[http://w.x/y/z.bmp]]></MIME_SOURCE>
<MIME_PURPOSE><![CDATA[thumbnail]]></MIME_PURPOSE>
</MIME>
</MIME_INFO>
</ARTICLE>
</T_NEW_CATALOG>
</BMEcat>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<ARTICLE_DETAILS xsi:nil="true"/>
<ARTICLE_PRICE_DETAILS xsi:nil="true"/>
<ARTICLE_FEATURES xsi:nil="true"/>
<MIME_INFO xsi:nil="true"/>
</ARTICLE>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<MIME xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MIME_TYPE xsi:nil="true"/>
<MIME_SOURCE xsi:nil="true"/>
<MIME_PURPOSE xsi:nil="true"/>
</MIME>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<MIME/>
24 changes: 24 additions & 0 deletions tests/SE/Component/BMEcat/Tests/Node/ArticleNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit c761067

Please sign in to comment.