Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add assets to merchandise

  • Loading branch information...
commit d205768c69bfdf042d573393f23552996e7a7099 1 parent 6dbf1e1
@iampersistent iampersistent authored
View
2  lib/Vespolina/Entity/Asset/Asset.php
@@ -1,6 +1,6 @@
<?php
/**
- * (c) Vespolina Project http://www.vespolina-project.org
+ * (c) 2012 Vespolina Project http://www.vespolina-project.org
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
View
3  lib/Vespolina/Entity/Order/BaseOrder.php
@@ -133,8 +133,7 @@ public function mergeItems(array $items)
*/
public function removeItem(ItemInterface $item)
{
- foreach ($this->items as $key => $itemToCompare)
- {
+ foreach ($this->items as $key => $itemToCompare) {
if ($itemToCompare == $item) {
unset($this->items[$key]);
break;
View
54 lib/Vespolina/Entity/Product/Merchandise.php
@@ -8,6 +8,7 @@
namespace Vespolina\Entity\Product;
+use Vespolina\Entity\Asset\AssetInterface;
use Vespolina\Entity\Pricing\PricingSet;
use Vespolina\Entity\Product\BaseProduct;
use Vespolina\Entity\Product\MerchandiseInterface;
@@ -73,6 +74,59 @@ public function getActive()
/**
* @inheritdoc
*/
+ public function addAsset(AssetInterface $asset)
+ {
+ $this->assets[] = $asset;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function addAssets(array $assets)
+ {
+ $this->assets = array_merge($this->assets, $assets);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function clearAssets()
+ {
+ $this->assets = array();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getAssets()
+ {
+ return $this->assets;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function removeAsset(AssetInterface $asset)
+ {
+ foreach ($this->assets as $key => $assetToCompare) {
+ if ($assetToCompare == $asset) {
+ unset($this->assets[$key]);
+ break;
+ }
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setAssets(array $assets)
+ {
+ $this->assets = $assets;
+ }
+
+ /**
+ * @inheritdoc
+ */
public function setDeactivateOn(\DateTime $deactivateOn)
{
$this->deactivateOn = $deactivateOn;
View
41 lib/Vespolina/Entity/Product/MerchandiseInterface.php
@@ -8,6 +8,7 @@
namespace Vespolina\Entity\Product;
+use Vespolina\Entity\Asset\AssetInterface;
use Vespolina\Entity\Pricing\PricingSet;
use Vespolina\Entity\Product\BaseProductInterface;
@@ -48,6 +49,46 @@ function setActive($active);
function getActive();
/**
+ * Add a asset to the collection
+ *
+ * @param \Vespolina\Entity\Asset\AssetInterface $asset
+ */
+ function addAsset(AssetInterface $asset);
+
+ /**
+ * Add a collection of assets
+ *
+ * @param array $assets
+ */
+ function addAssets(array $assets);
+
+ /**
+ * Remove all assets from the collection
+ */
+ function clearAssets();
+
+ /**
+ * Return a collection of assets
+ *
+ * @return array of \Vespolina\Entity\Asset\AssetInterface
+ */
+ function getAssets();
+
+ /**
+ * Remove an asset from the collection
+ *
+ * @param AssetInterface $asset
+ */
+ function removeAsset(AssetInterface $asset);
+
+ /**
+ * Set a collection of assets
+ *
+ * @param array $assets
+ */
+ function setAssets(array $assets);
+
+ /**
* Set the date this merchandise becomes inactive in the store.
*
* @param \DateTime $deactivateOn
View
32 tests/Entity/Product/MerchandiseTest.php
@@ -1,5 +1,6 @@
<?php
+use Vespolina\Entity\Asset\Asset;
use Vespolina\Entity\Product\Product;
use Vespolina\Entity\Product\Merchandise;
@@ -20,6 +21,37 @@ public function testConstructor()
}
}
+ public function testAsset()
+ {
+ $product = $this->createProduct();
+ $merchandise = new Merchandise($product);
+ $this->assertNull($merchandise->getAssets(), 'make sure we start out empty');
+
+ $asset = new Asset();
+ $merchandise->addAsset($asset);
+ $this->assertContains($asset, $merchandise->getAssets());
+ $this->assertCount(1, $merchandise->getAssets());
+
+ $assets = array();
+ $assets[] = new Asset();
+ $assets[] = new Asset();
+ $merchandise->addAssets($assets);
+ $this->assertCount(3, $merchandise->getAssets());
+ $this->assertContains($asset, $merchandise->getAssets());
+
+ $merchandise->removeAsset($asset);
+ $this->assertNotContains($asset, $merchandise->getAssets());
+ $this->assertCount(2, $merchandise->getAssets());
+
+ $merchandise->clearAssets();
+ $this->assertEmpty($merchandise->getAssets());
+
+ $merchandise->addAsset($asset);
+ $merchandise->setAssets($assets);
+ $this->assertNotContains($asset, $merchandise->getAssets(), 'this should have been removed on setting a new array of items');
+ $this->assertCount(2, $merchandise->getAssets());
+ }
+
protected function createProduct()
{
$product = new Product();
Please sign in to comment.
Something went wrong with that request. Please try again.