/** * 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']); }
public function testSaveDeleteItem() { $couponManager = MShop_Coupon_Manager_Factory::createManager(TestHelper::getContext()); $search = $couponManager->createSearch(); $search->setConditions($search->compare('==', 'coupon.label', 'Unit test example')); $result = $couponManager->searchItems($search); if (($couponItem = reset($result)) === false) { throw new Exception('No coupon item found'); } $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('coupon.code.couponid' => $couponItem->getId(), 'coupon.code.code' => 'zzzz', 'coupon.code.count' => -1)); $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => array('==' => (object) array('coupon.code.code' => 'zzzz'))))); $saved = $this->_object->saveItems($saveParams); $searched = $this->_object->searchItems($searchParams); $deleteParams = (object) array('site' => 'unittest', 'items' => array($saved['items']->{'coupon.code.id'})); $this->_object->deleteItems($deleteParams); $result = $this->_object->searchItems($searchParams); $this->assertInternalType('object', $saved['items']); $this->assertNotNull($saved['items']->{'coupon.code.id'}); $this->assertEquals($saved['items']->{'coupon.code.couponid'}, $searched['items'][0]->{'coupon.code.couponid'}); $this->assertEquals($saved['items']->{'coupon.code.code'}, $searched['items'][0]->{'coupon.code.code'}); $this->assertEquals($saved['items']->{'coupon.code.count'}, $searched['items'][0]->{'coupon.code.count'}); $this->assertEquals($saved['items']->{'coupon.code.datestart'}, $searched['items'][0]->{'coupon.code.datestart'}); $this->assertEquals($saved['items']->{'coupon.code.dateend'}, $searched['items'][0]->{'coupon.code.dateend'}); $this->assertEquals(1, count($searched['items'])); $this->assertEquals(0, count($result['items'])); }
/** * 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()); }
/** * 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'); }