Permalink
Browse files

update test, start implementing

  • Loading branch information...
1 parent 5bb9f26 commit 8c0f2ff364e21ab813773e13cb7113fbd97f2f5a @iampersistent iampersistent committed Jan 22, 2013
@@ -0,0 +1,25 @@
+<?php
+/**
+ * (c) 2013 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.
+ */
+namespace Vespolina\Entity\Pricing\Element;
+
+use Vespolina\Entity\Pricing\PricingElement;
+
+class TotalValueElement extends PricingElement
+{
+ protected $order = 100000;
+
+ protected function doProcess($context, $processed)
+ {
+ $totalValue = $processed['netValue'];
+ // todo: calculate other preset groups 'discounts', 'surcharge', 'taxes'
+
+ $processed['totalValue'] = $totalValue;
+
+ return $processed;
+ }
+}
@@ -8,6 +8,7 @@
namespace Pricing\Entity;
+use Vespolina\Entity\Pricing\Element\TotalValueElement;
use Vespolina\Entity\Pricing\PricingSetInterface;
class PricingSet implements PricingSetInterface
@@ -31,6 +32,8 @@ public function __construct(array $customReturns = array())
foreach ($this->returns as $return) {
$this->processed[$return] = null;
}
+
+ $this->addElement(new TotalValueElement());
}
public function getDiscounts()
@@ -9,15 +9,23 @@ public function testAddElements()
{
$pricingSet = new PricingSet();
- $this->assertNull($pricingSet->getElements(), 'the elements should start empty');
+ $this->assertCount(1, $pricingSet->getElements(), 'the elements should start with the total value element');
$element1 = new PricingElement();
+ $element1->setPosition(100);
$pricingSet->addElement($element1);
- $this->assertCount(1, $pricingSet->getElements());
+ $this->assertCount(2, $pricingSet->getElements());
$element2 = new PricingElement();
+ $element2->setPosition(10);
$pricingSet->addElement($element2);
- $this->assertCount(2, $pricingSet->getElements());
+ $elements = $pricingSet->getElements();
+ $this->assertCount(3, $elements);
+ $this->assertSame($element2, $elements[0], 'the second element should be first since the position is lower');
+ $this->assertSame($element1, $elements[1], 'the first element should be next since the position is higher');
+ $this->assertInstanceOf('', $elements[2], 'the preset element should be last');
+
+
}
public function testProcess()

0 comments on commit 8c0f2ff

Please sign in to comment.