/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $pluginManager = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext()); $this->_plugin = $pluginManager->createItem(); $this->_plugin->setTypeId(2); $this->_plugin->setProvider('PropertyMatch'); $this->_plugin->setConfig(array('product.suppliercode' => 'unitSupplier')); $this->_plugin->setStatus('1'); $orderManager = MShop_Order_Manager_Factory::createManager(TestHelper::getContext()); $orderBaseManager = $orderManager->getSubManager('base'); $orderBaseProductManager = $orderBaseManager->getSubManager('product'); $manager = MShop_Product_Manager_Factory::createManager(TestHelper::getContext()); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'product.code', array('CNE', 'CNC'))); $products = $manager->searchItems($search); if (count($products) !== 2) { throw new Exception('Wrong number of products'); } $this->_products = array(); foreach ($products as $product) { $item = $orderBaseProductManager->createItem(); $item->copyFrom($product); $this->_products[$product->getCode()] = $item; } $this->_order = $orderBaseManager->createItem(); $this->_object = new MShop_Plugin_Provider_Order_PropertyMatch(TestHelper::getContext(), $this->_plugin); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); $target = 'MShop_Common_Manager_Interface'; $manager = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext(), 'NotExist'); $this->assertInstanceOf($target, $manager); }
public function testSaveDeleteItem() { $manager = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext()); $typeManager = $manager->getSubManager('type'); $search = $typeManager->createSearch(); $search->setConditions($search->compare('==', 'plugin.type.code', 'order')); $result = $typeManager->searchItems($search); if (($type = reset($result)) === false) { throw new Exception('No plugin type found'); } $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('plugin.status' => 1, 'plugin.position' => 2, 'plugin.provider' => 'test provider', 'plugin.config' => array('url' => 'www.url.de'), 'plugin.typeid' => $type->getId(), 'plugin.label' => 'test plugin')); $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => array('==' => (object) array('plugin.provider' => 'test provider'))))); $saved = $this->_object->saveItems($saveParams); $searched = $this->_object->searchItems($searchParams); $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'plugin.id'}); $this->_object->deleteItems($deleteParams); $result = $this->_object->searchItems($searchParams); $this->assertInternalType('object', $saved['items']); $this->assertNotNull($saved['items']->{'plugin.id'}); $this->assertEquals($saved['items']->{'plugin.id'}, $searched['items'][0]->{'plugin.id'}); $this->assertEquals($saved['items']->{'plugin.status'}, $searched['items'][0]->{'plugin.status'}); $this->assertEquals($saved['items']->{'plugin.position'}, $searched['items'][0]->{'plugin.position'}); $this->assertEquals($saved['items']->{'plugin.provider'}, $searched['items'][0]->{'plugin.provider'}); $this->assertEquals($saved['items']->{'plugin.config'}, $searched['items'][0]->{'plugin.config'}); $this->assertEquals($saved['items']->{'plugin.typeid'}, $searched['items'][0]->{'plugin.typeid'}); $this->assertEquals($saved['items']->{'plugin.label'}, $searched['items'][0]->{'plugin.label'}); $this->assertEquals(1, count($searched['items'])); $this->assertEquals(0, count($result['items'])); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $orderManager = MShop_Order_Manager_Factory::createManager(TestHelper::getContext()); $orderBaseManager = $orderManager->getSubManager('base'); $this->_order = $orderBaseManager->createItem(); $orderBaseProductManager = $orderBaseManager->getSubManager('product'); $search = $orderBaseProductManager->createSearch(); $search->setConditions($search->combine('&&', array($search->compare('==', 'order.base.product.prodcode', array('CNE', 'CNC')), $search->compare('==', 'order.base.product.price', array('600.00', '36.00'))))); $items = $orderBaseProductManager->searchItems($search); if (count($items) < 2) { throw new Exception('Please fix the test data in your database.'); } foreach ($items as $item) { $this->_products[$item->getProductCode()] = $item; } $this->_products['CNE']->setQuantity(2); $this->_products['CNC']->setQuantity(1); $config = array('min-value' => array('EUR' => '75.00'), 'max-value' => array('EUR' => '625.00'), 'min-products' => '2', 'max-products' => 5); $pluginManager = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext()); $plugin = $pluginManager->createItem(); $plugin->setTypeId(2); $plugin->setProvider('BasketLimits'); $plugin->setConfig($config); $plugin->setStatus('1'); $this->_object = new MShop_Plugin_Provider_Order_BasketLimits(TestHelper::getContext(), $plugin); }
/** * 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(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $this->_plugin = $pluginManager->createItem(); $this->_plugin->setProvider('ProductGone'); $this->_plugin->setStatus(1); $this->_orderManager = MShop_Order_Manager_Factory::createManager($context); $orderBaseManager = $this->_orderManager->getSubManager('base'); $search = $orderBaseManager->createSearch(); $search->setConditions($search->compare('==', 'order.base.price', 672.0)); $search->setSlice(0, 1); $items = $orderBaseManager->searchItems($search); if (($baseItem = reset($items)) === false) { throw new Exception('No order base item found.'); } $this->_order = $baseItem; // create a product to mess with in the tests $productManager = MShop_Product_Manager_Factory::createManager(TestHelper::getContext()); $search = $productManager->createSearch(); $search->setConditions($search->compare('==', 'product.code', 'CNE')); $search->setSlice(0, 1); $items = $productManager->searchItems($search); if (($newProduct = reset($items)) === false) { throw new Exception('Product code "CNE" not found.'); } $newProduct->setId(null); $newProduct->setLabel('Bad Product'); $newProduct->setCode('WTF'); $productManager->saveItem($newProduct); $this->_product = $newProduct; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $pluginManager = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext()); $plugin = $pluginManager->createItem(); $plugin->setTypeId(2); $plugin->setProvider('Example'); $plugin->setConfig(array('key' => 1)); $plugin->setStatus('1'); $this->_object = new MShop_Plugin_Provider_Order_Example(TestHelper::getContext(), $plugin); }
/** * 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(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $this->_plugin = $pluginManager->createItem(); $this->_plugin->setProvider('Coupon'); $this->_plugin->setStatus(1); $priceItem = MShop_Price_Manager_Factory::createManager($context)->createItem(); $this->_order = new MShop_Order_Item_Base_Default($priceItem, $context->getLocale()); }
/** * 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(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $item = $pluginManager->createItem(); $provider = new MShop_Plugin_Provider_Order_Example($context, $item); $priceItem = MShop_Price_Manager_Factory::createManager($context)->createItem(); $this->_order = new MShop_Order_Item_Base_Default($priceItem, $context->getLocale()); $this->_object = new MShop_Plugin_Provider_Decorator_Log($context, $item, $provider); }
/** * 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(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $this->_plugin = $pluginManager->createItem(); $this->_plugin->setProvider('Autofill'); $this->_plugin->setStatus(1); $this->_orderManager = MShop_Order_Manager_Factory::createManager($context); $orderBaseManager = $this->_orderManager->getSubManager('base'); $this->_order = $orderBaseManager->createItem(); }
/** * 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(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $this->_plugin = $pluginManager->createItem(); $this->_plugin->setProvider('AddressesAvailable'); $this->_plugin->setStatus(1); $orderBaseManager = MShop_Order_Manager_Factory::createManager($context)->getSubManager('base'); $orderBaseAddressManager = $orderBaseManager->getSubManager('address'); $this->_order = $orderBaseManager->createItem(); $this->_address = $orderBaseAddressManager->createItem(); $this->_address->setLastName('Available'); }
/** * 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(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $plugin = $pluginManager->createItem(); $plugin->setTypeId(2); $plugin->setProvider('Shipping'); $plugin->setConfig(array('threshold' => array('EUR' => '34.00'))); $plugin->setStatus('1'); $orderManager = MShop_Order_Manager_Factory::createManager($context); $orderBaseManager = $orderManager->getSubManager('base'); $orderBaseProductManager = $orderBaseManager->getSubManager('product'); $manager = MShop_Product_Manager_Factory::createManager($context); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'product.code', array('CNE', 'CNC', 'IJKL'))); $pResults = $manager->searchItems($search, array('price')); if (count($pResults) !== 3) { throw new Exception('Wrong number of products'); } $products = array(); foreach ($pResults as $prod) { $products[$prod->getCode()] = $prod; } if (($price = current($products['IJKL']->getRefItems('price'))) === false) { throw new Exception('No price item found'); } $price->setValue(10.0); $this->_product = $orderBaseProductManager->createItem(); $this->_product->copyFrom($products['CNE']); $this->_product->setPrice($price); $product2 = $orderBaseProductManager->createItem(); $product2->copyFrom($products['CNC']); $product2->setPrice($price); $product3 = $orderBaseProductManager->createItem(); $product3->copyFrom($products['IJKL']); $product3->setPrice($price); $orderBaseServiceManager = $orderBaseManager->getSubManager('service'); $serviceSearch = $orderBaseServiceManager->createSearch(); $exp = array($serviceSearch->compare('==', 'order.base.service.type', 'delivery'), $serviceSearch->compare('==', 'order.base.service.costs', '5.00')); $serviceSearch->setConditions($serviceSearch->combine('&&', $exp)); $results = $orderBaseServiceManager->searchItems($serviceSearch); if (($delivery = reset($results)) === false) { throw new Exception('No order base item found'); } $this->_order = $orderBaseManager->createItem(); $this->_order->setService($delivery, 'delivery'); $this->_order->addProduct($this->_product); $this->_order->addProduct($product2); $this->_order->addProduct($product3); $this->_object = new MShop_Plugin_Provider_Order_Shipping($context, $plugin); }
/** * Adds locale data. */ protected function _process() { $iface = 'MShop_Context_Item_Interface'; if (!$this->_additional instanceof $iface) { throw new MW_Setup_Exception(sprintf('Additionally provided object is not of type "%1$s"', $iface)); } $this->_msg('Adding default plugin data', 0); $this->_status(''); $ds = DIRECTORY_SEPARATOR; $pluginManager = MShop_Plugin_Manager_Factory::createManager($this->_additional, 'Default'); $filename = dirname(__FILE__) . $ds . 'default' . $ds . 'data' . $ds . 'plugin.php'; if (($data = (include $filename)) == false) { throw new MW_Setup_Exception(sprintf('No data file "%1$s" found', $filename)); } if (isset($data['plugin'])) { $this->_addPluginData($pluginManager, $data['plugin']); } }
/** * 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->_editor = TestHelper::getContext()->getEditor(); $this->_object = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext()); $type = $this->_object->getSubManager('type'); $search = $type->createSearch(); $conditions = array($search->compare('==', 'plugin.type.code', 'order'), $search->compare('==', 'plugin.type.editor', $this->_editor)); $search->setConditions($search->combine('&&', $conditions)); $results = $type->searchItems($search); if (($typeItem = reset($results)) === false) { throw new Exception('No item found'); } $this->_examplePlugin = $this->_object->createItem(); $this->_examplePlugin->setTypeId($typeItem->getId()); $this->_examplePlugin->setProvider('Example'); $this->_examplePlugin->setConfig(array("limit" => "10")); $this->_examplePlugin->setStatus(1); $this->_examplePlugin2 = clone $this->_examplePlugin; }
/** * 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(); $pluginManager = MShop_Plugin_Manager_Factory::createManager($context); $this->_plugin = $pluginManager->createItem(); $this->_plugin->setProvider('ProductPrice'); $this->_plugin->setStatus(1); $this->_order = MShop_Factory::createManager($context, 'order/base')->createItem(); $orderBaseProductManager = MShop_Factory::createManager($context, 'order/base/product'); $search = $orderBaseProductManager->createSearch(); $search->setConditions($search->compare('==', 'order.base.product.prodcode', 'CNC')); $productItems = $orderBaseProductManager->searchItems($search); if (($productItem = reset($productItems)) === false) { throw new Exception('No order base product item found.'); } $productItem->getPrice()->setValue(600.0); $productItem->getPrice()->setCosts(30.0); $productItem->getPrice()->setRebate(0.0); $productItem->getPrice()->setTaxrate(19.0); $this->_order->addProduct($productItem); $this->_price = clone $productItem->getPrice(); $this->_price->setValue(13.13); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $priceManager = MShop_Price_Manager_Factory::createManager(TestHelper::getContext()); $orderManager = MShop_Order_Manager_Factory::createManager(TestHelper::getContext()); $orderBaseManager = $orderManager->getSubManager('base'); $orderAddressManager = $orderBaseManager->getSubManager('address'); $orderProductManager = $orderBaseManager->getSubManager('product'); $orderServiceManager = $orderBaseManager->getSubManager('service'); $this->_values = array('id' => 1, 'siteid' => 99, 'customerid' => 'testuser', 'comment' => 'this is a comment from unittest', 'status' => 1, 'mtime' => '2011-01-01 00:00:02', 'ctime' => '2011-01-01 00:00:01', 'editor' => 'unitTestUser'); $this->_locale = MShop_Locale_Manager_Factory::createManager(TestHelper::getContext())->createItem(); $this->_object = new MShop_Order_Item_Base_Default($priceManager->createItem(), $this->_locale, $this->_values); $price = $priceManager->createItem(); $price->setRebate('3.01'); $price->setValue('43.12'); $price->setCosts('1.11'); $price->setTaxRate('0.00'); $price->setCurrencyId('EUR'); $prod1 = $orderProductManager->createItem(); $prod1->setProductCode('prod1'); $prod1->setPrice($price); $price = $priceManager->createItem(); $price->setRebate('4.00'); $price->setValue('20.00'); $price->setCosts('2.00'); $price->setTaxRate('0.50'); $price->setCurrencyId('EUR'); $prod2 = $orderProductManager->createItem(); $prod2->setProductCode('prod2'); $prod2->setPrice($price); $this->_products = array($prod1, $prod2); $this->_coupons = array('OPQR' => array($prod1)); $this->_addresses = array(MShop_Order_Item_Base_Address_Abstract::TYPE_PAYMENT => $orderAddressManager->createItem(), MShop_Order_Item_Base_Address_Abstract::TYPE_DELIVERY => $orderAddressManager->createItem()); $this->_services = array('payment' => $orderServiceManager->createItem(), 'delivery' => $orderServiceManager->createItem()); //registering order object for plugin use $pluginManager = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext()); $pluginManager->register($this->_object, 'order'); }
/** * Adds the plugin test data. * * @throws MW_Setup_Exception If no type ID is found */ private function _addPluginData() { $pluginManager = MShop_Plugin_Manager_Factory::createManager($this->_additional, 'Default'); $pluginTypeManager = $pluginManager->getSubManager('type', 'Default'); $ds = DIRECTORY_SEPARATOR; $path = dirname(__FILE__) . $ds . 'data' . $ds . 'plugin.php'; if (($testdata = (include $path)) == false) { throw new MShop_Exception(sprintf('No file "%1$s" found for plugin domain', $path)); } $plugTypeIds = array(); $type = $pluginTypeManager->createItem(); $this->_conn->begin(); foreach ($testdata['plugin/type'] as $key => $dataset) { $type->setId(null); $type->setCode($dataset['code']); $type->setLabel($dataset['label']); $type->setDomain($dataset['domain']); $type->setStatus($dataset['status']); $pluginTypeManager->saveItem($type); $plugTypeIds[$key] = $type->getId(); } $plugin = $pluginManager->createItem(); foreach ($testdata['plugin'] as $dataset) { if (!isset($plugTypeIds[$dataset['typeid']])) { throw new MW_Setup_Exception(sprintf('No plugin type ID found for "%1$s"', $dataset['typeid'])); } $plugin->setId(null); $plugin->setTypeId($plugTypeIds[$dataset['typeid']]); $plugin->setLabel($dataset['label']); $plugin->setStatus($dataset['status']); $plugin->setConfig($dataset['config']); $plugin->setProvider($dataset['provider']); $pluginManager->saveItem($plugin, false); } $this->_conn->commit(); }
/** * 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->_editor = TestHelper::getContext()->getEditor(); $manager = MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext()); $this->_object = $manager->getSubManager('type'); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); MShop_Plugin_Manager_Factory::createManager(TestHelper::getContext(), 'unknown'); }
/** * Initializes the plugin type controller. * * @param MShop_Context_Item_Interface $context MShop context object */ public function __construct(MShop_Context_Item_Interface $context) { parent::__construct($context, 'Plugin_Type'); $manager = MShop_Plugin_Manager_Factory::createManager($context); $this->_manager = $manager->getSubManager('type'); }
/** * Initializes the plugin controller. * * @param MShop_Context_Item_Interface $context MShop context object */ public function __construct(MShop_Context_Item_Interface $context) { parent::__construct($context, 'Plugin'); $this->_manager = MShop_Plugin_Manager_Factory::createManager($context); $this->_context = $context; }