/**
  * 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();
     $couponManager = MShop_Coupon_Manager_Factory::createManager($context);
     $this->_couponItem = $couponManager->createItem();
     $provider = new MShop_Coupon_Provider_Example($context, $this->_couponItem, 'abcd');
     $this->_object = new MShop_Coupon_Provider_Decorator_BasketValues($context, $this->_couponItem, 'abcd', $provider);
     $this->_object->setObject($this->_object);
     $orderManager = MShop_Order_Manager_Factory::createManager($context);
     $orderBaseManager = $orderManager->getSubManager('base');
     $orderProductManager = $orderBaseManager->getSubManager('product');
     $productManager = MShop_Product_Manager_Factory::createManager($context);
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', array('CNC')));
     $products = $productManager->searchItems($search);
     $priceManager = 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 MShop_Order_Item_Base_Default($priceManager->createItem(), $context->getLocale());
     $this->_orderBase->addProduct($orderProducts['CNC']);
 }
 /**
  * Adds the coupon test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @throws MW_Setup_Exception If a required ID is not available
  */
 private function _addCouponData(array $testdata)
 {
     $couponManager = MShop_Coupon_Manager_Factory::createManager($this->_additional, 'Default');
     $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['couponid']])) {
             throw new MW_Setup_Exception(sprintf('No coupon ID found for "%1$s"', $dataset['couponid']));
         }
         $ccode->setId(null);
         $ccode->setCouponId($couponIds[$dataset['couponid']]);
         $ccode->setCount($dataset['count']);
         $ccode->setDateStart($dataset['start']);
         $ccode->setDateEnd($dataset['end']);
         $ccode->setCode($dataset['code']);
         $couponCodeManager->saveItem($ccode, false);
     }
 }
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     $target = 'MShop_Common_Manager_Interface';
     $manager = MShop_Coupon_Manager_Factory::createManager(TestHelper::getContext(), 'test');
     $this->assertInstanceOf($target, $manager);
 }
 public function testAddCouponInvalidConfig()
 {
     $context = TestHelper::getContext();
     $couponItem = MShop_Coupon_Manager_Factory::createManager(TestHelper::getContext())->createItem();
     $object = new MShop_Coupon_Provider_Present($context, $couponItem, 'zyxw');
     $this->setExpectedException('MShop_Coupon_Exception');
     $object->addCoupon($this->_orderBase);
 }
 /**
  * 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 = MShop_Coupon_Manager_Factory::createManager(TestHelper::getContext());
     $this->_item = $this->_object->createItem();
     $this->_item->setProvider('Example');
     $this->_item->setConfig(array('key' => 'value'));
     $this->_item->setStatus('1');
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $priceManager = MShop_Price_Manager_Factory::createManager($context);
     $item = 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 MShop_Order_Item_Base_Default($priceManager->createItem(), $context->getLocale());
     $this->_object = new MShop_Coupon_Provider_Example($context, $item, '1234');
 }
 /**
  * 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 = MShop_Coupon_Manager_Factory::createManager(TestHelper::getContext());
     $search = $couponManager->createSearch();
     $search->setConditions($search->compare('~=', 'coupon.code.code', 'OPQR'));
     $results = $couponManager->searchItems($search);
     if (($item = reset($results)) === false) {
         throw new Exception('Code item not found');
     }
     $this->_object = $couponManager->getSubManager('code');
     $this->_code = $this->_object->createItem();
     $this->_code->setCode('abcd');
     $this->_code->setCount('1');
     $this->_code->setCouponId($item->getId());
 }
 public function testImportFile()
 {
     $codeMock = $this->getMockBuilder('MShop_Coupon_Manager_Code_Default')->setConstructorArgs(array($this->_context))->setMethods(array('saveItem'))->getMock();
     $codeMock->expects($this->exactly(3))->method('saveItem');
     $mock = $this->getMockBuilder('MShop_Coupon_Manager_Default')->setConstructorArgs(array($this->_context))->setMethods(array('getSubManager'))->getMock();
     $mock->expects($this->once())->method('getSubManager')->will($this->returnValue($codeMock));
     $name = 'ControllerExtJSCouponCodeDefaultRun';
     $this->_context->getConfig()->set('classes/coupon/manager/name', $name);
     MShop_Coupon_Manager_Factory::injectManager('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->couponid = '-1';
     $this->_object->importFile($params);
 }
Exemple #9
0
 /**
  * Initializes the coupon controller.
  *
  * @param MShop_Context_Item_Interface $context MShop context object
  */
 public function __construct(MShop_Context_Item_Interface $context)
 {
     parent::__construct($context, 'Coupon_Code');
     $this->_manager = MShop_Coupon_Manager_Factory::createManager($context)->getSubManager('code');
 }
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     MShop_Coupon_Manager_Factory::createManager(TestHelper::getContext(), 'unknown');
 }