Example #1
0
 /**
  * Sets up the fixture, especially creates products.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $orderProducts = array();
     $context = \TestHelper::getContext();
     $this->couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager($context)->createItem();
     $provider = new \Aimeos\MShop\Coupon\Provider\Example($context, $this->couponItem, 'abcd');
     $this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Required($context, $this->couponItem, 'abcd', $provider);
     $this->object->setObject($this->object);
     $orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager($context);
     $orderBaseManager = $orderManager->getSubManager('base');
     $orderProductManager = $orderBaseManager->getSubManager('product');
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($context);
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', array('CNC')));
     $products = $productManager->searchItems($search);
     $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($context);
     $price = $priceManager->createItem();
     $price->setValue(321);
     foreach ($products as $product) {
         $orderProduct = $orderProductManager->createItem();
         $orderProduct->copyFrom($product);
         $orderProducts[$product->getCode()] = $orderProduct;
     }
     $orderProducts['CNC']->setPrice($price);
     $this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard($priceManager->createItem(), $context->getLocale());
     $this->orderBase->addProduct($orderProducts['CNC']);
 }
Example #2
0
 /**
  * Adds the coupon test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @throws \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 private function addCouponData(array $testdata)
 {
     $couponManager = \Aimeos\MShop\Coupon\Manager\Factory::createManager($this->additional, 'Standard');
     $couponCodeManager = $couponManager->getSubmanager('code');
     $couponIds = array();
     $coupon = $couponManager->createItem();
     foreach ($testdata['coupon'] as $key => $dataset) {
         $coupon->setId(null);
         $coupon->setLabel($dataset['label']);
         $coupon->setProvider($dataset['provider']);
         $coupon->setDateStart($dataset['start']);
         $coupon->setDateEnd($dataset['end']);
         $coupon->setConfig($dataset['config']);
         $coupon->setStatus($dataset['status']);
         $couponManager->saveItem($coupon);
         $couponIds[$key] = $coupon->getId();
     }
     $ccode = $couponCodeManager->createItem();
     foreach ($testdata['coupon/code'] as $key => $dataset) {
         if (!isset($couponIds[$dataset['parentid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No coupon ID found for "%1$s"', $dataset['parentid']));
         }
         $ccode->setId(null);
         $ccode->setParentId($couponIds[$dataset['parentid']]);
         $ccode->setCount($dataset['count']);
         $ccode->setDateStart($dataset['start']);
         $ccode->setDateEnd($dataset['end']);
         $ccode->setCode($dataset['code']);
         $couponCodeManager->saveItem($ccode, false);
     }
 }
Example #3
0
 public function testAddCouponInvalidConfig()
 {
     $context = \TestHelperMShop::getContext();
     $couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager(\TestHelperMShop::getContext())->createItem();
     $object = new \Aimeos\MShop\Coupon\Provider\FreeShipping($context, $couponItem, 'zyxw');
     $this->setExpectedException('\\Aimeos\\MShop\\Coupon\\Exception');
     $object->addCoupon($this->orderBase);
 }
Example #4
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->object = \Aimeos\MShop\Coupon\Manager\Factory::createManager(\TestHelperMShop::getContext());
     $this->item = $this->object->createItem();
     $this->item->setProvider('Example');
     $this->item->setConfig(array('key' => 'value'));
     $this->item->setStatus('1');
 }
Example #5
0
 protected function setUp()
 {
     $context = \TestHelperMShop::getContext();
     $priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager($context);
     $item = \Aimeos\MShop\Coupon\Manager\Factory::createManager($context)->createItem();
     // Don't create order base item by createItem() as this would already register the plugins
     $this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard($priceManager->createItem(), $context->getLocale());
     $this->object = new \Aimeos\MShop\Coupon\Provider\None($context, $item, '1234');
 }
Example #6
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $couponManager = \Aimeos\MShop\Coupon\Manager\Factory::createManager(\TestHelperMShop::getContext());
     $search = $couponManager->createSearch();
     $search->setConditions($search->compare('~=', 'coupon.code.code', 'OPQR'));
     $results = $couponManager->searchItems($search);
     if (($item = reset($results)) === false) {
         throw new \RuntimeException('Code item not found');
     }
     $this->object = $couponManager->getSubManager('code');
     $this->code = $this->object->createItem();
     $this->code->setCode('abcd');
     $this->code->setCount('1');
     $this->code->setParentId($item->getId());
 }
Example #7
0
 public function testUpdate()
 {
     $context = \TestHelperCntl::getContext();
     $config = $context->getConfig();
     $name = 'ControllerCommonOrderBlock';
     $config->set('mshop/order/manager/name', $name);
     $config->set('mshop/product/manager/name', $name);
     $config->set('mshop/coupon/manager/name', $name);
     $orderManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Standard')->setMethods(array('getSubManager'))->setConstructorArgs(array($context))->getMock();
     $orderBaseManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard')->setMethods(array('getSubManager'))->setConstructorArgs(array($context))->getMock();
     $orderStatusManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Status\\Standard')->setMethods(array('saveItem', 'searchItems'))->setConstructorArgs(array($context))->getMock();
     $orderProductManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Base\\Product\\Standard')->setMethods(array('searchItems'))->setConstructorArgs(array($context))->getMock();
     $orderCouponManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Manager\\Base\\Coupon\\Standard')->setMethods(array('searchItems'))->setConstructorArgs(array($context))->getMock();
     $productManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Product\\Manager\\Standard')->setMethods(array('getSubManager', 'searchItems'))->setConstructorArgs(array($context))->getMock();
     $productStockManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Product\\Manager\\Stock\\Standard')->setMethods(array('increase'))->setConstructorArgs(array($context))->getMock();
     $couponManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Coupon\\Manager\\Standard')->setMethods(array('getSubManager'))->setConstructorArgs(array($context))->getMock();
     $couponCodeManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Coupon\\Manager\\Code\\Standard')->setMethods(array('increase'))->setConstructorArgs(array($context))->getMock();
     \Aimeos\MShop\Order\Manager\Factory::injectManager('\\Aimeos\\MShop\\Order\\Manager\\' . $name, $orderManagerStub);
     \Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Product\\Manager\\' . $name, $productManagerStub);
     \Aimeos\MShop\Coupon\Manager\Factory::injectManager('\\Aimeos\\MShop\\Coupon\\Manager\\' . $name, $couponManagerStub);
     $orderStatusItemBlocked = $orderStatusManagerStub->createItem();
     $orderStatusItemBlocked->setValue(1);
     $orderStatusItemUnblocked = $orderStatusManagerStub->createItem();
     $orderStatusItemUnblocked->setValue(0);
     $orderManagerStub->expects($this->exactly(12))->method('getSubManager')->will($this->onConsecutiveCalls($orderStatusManagerStub, $orderBaseManagerStub, $orderStatusManagerStub, $orderStatusManagerStub, $orderBaseManagerStub, $orderStatusManagerStub, $orderStatusManagerStub, $orderBaseManagerStub, $orderStatusManagerStub, $orderStatusManagerStub, $orderBaseManagerStub, $orderStatusManagerStub));
     $orderBaseManagerStub->expects($this->exactly(4))->method('getSubManager')->will($this->onConsecutiveCalls($orderProductManagerStub, $orderCouponManagerStub, $orderProductManagerStub, $orderCouponManagerStub));
     $orderStatusManagerStub->expects($this->exactly(4))->method('searchItems')->will($this->onConsecutiveCalls(array($orderStatusItemUnblocked), array($orderStatusItemUnblocked), array($orderStatusItemBlocked), array($orderStatusItemBlocked)));
     $orderStatusManagerStub->expects($this->exactly(4))->method('saveItem');
     $orderProductManagerStub->expects($this->exactly(2))->method('searchItems')->will($this->returnValue(array($orderProductManagerStub->createItem())));
     $productManagerStub->expects($this->exactly(4))->method('getSubManager')->will($this->returnValue($productStockManagerStub));
     $productManagerStub->expects($this->exactly(2))->method('searchItems')->will($this->returnValue(array()));
     $productStockManagerStub->expects($this->exactly(2))->method('increase');
     $orderCouponManagerStub->expects($this->exactly(2))->method('searchItems')->will($this->returnValue(array($orderCouponManagerStub->createItem())));
     $couponManagerStub->expects($this->exactly(2))->method('getSubManager')->will($this->returnValue($couponCodeManagerStub));
     $couponCodeManagerStub->expects($this->exactly(2))->method('increase');
     $orderItem = $orderManagerStub->createItem();
     $orderItem->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_UNFINISHED);
     $object = new \Aimeos\Controller\Common\Order\Standard($context);
     $object->update($orderItem);
     $orderItem = $orderManagerStub->createItem();
     $orderItem->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_PENDING);
     $object = new \Aimeos\Controller\Common\Order\Standard($context);
     $object->update($orderItem);
     $orderItem = $orderManagerStub->createItem();
     $orderItem->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_DELETED);
     $object = new \Aimeos\Controller\Common\Order\Standard($context);
     $object->update($orderItem);
 }
Example #8
0
 public function testImportFile()
 {
     $codeMock = $this->getMockBuilder('\\Aimeos\\MShop\\Coupon\\Manager\\Code\\Standard')->setConstructorArgs(array($this->context))->setMethods(array('saveItem'))->getMock();
     $codeMock->expects($this->exactly(3))->method('saveItem');
     $mock = $this->getMockBuilder('\\Aimeos\\MShop\\Coupon\\Manager\\Standard')->setConstructorArgs(array($this->context))->setMethods(array('getSubManager'))->getMock();
     $mock->expects($this->once())->method('getSubManager')->will($this->returnValue($codeMock));
     $name = 'ControllerExtJSCouponCodeDefaultRun';
     $this->context->getConfig()->set('mshop/coupon/manager/name', $name);
     \Aimeos\MShop\Coupon\Manager\Factory::injectManager('\\Aimeos\\MShop\\Coupon\\Manager\\' . $name, $mock);
     $testfiledir = __DIR__ . DIRECTORY_SEPARATOR . 'testfiles' . DIRECTORY_SEPARATOR;
     exec(sprintf('cp -r %1$s %2$s', escapeshellarg($testfiledir) . '*', escapeshellarg($this->testdir)));
     $params = new \stdClass();
     $params->site = $this->context->getLocale()->getSite()->getCode();
     $params->items = $this->testdir . DIRECTORY_SEPARATOR . 'coupon.zip';
     $params->parentid = '-1';
     $this->object->importFile($params);
 }
 public function testAddCouponInvalidConfig()
 {
     $context = \TestHelper::getContext();
     $couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager(\TestHelper::getContext())->createItem();
     $couponItem->setConfig(array('fixedrebate.rebate' => '2.50'));
     $object = new \Aimeos\MShop\Coupon\Provider\FixedRebate($context, $couponItem, 'zyxw');
     $this->setExpectedException('\\Aimeos\\MShop\\Coupon\\Exception');
     $object->addCoupon($this->orderBase);
 }
Example #10
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('\\Aimeos\\MShop\\Exception');
     \Aimeos\MShop\Coupon\Manager\Factory::createManager(\TestHelper::getContext(), 'unknown');
 }