public function testProcessOK() { $controller = \Aimeos\Controller\Frontend\Basket\Factory::createController($this->context); $baseManager = \Aimeos\MShop\Order\Manager\Factory::createManager($this->context)->getSubManager('base'); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $search = $serviceManager->createSearch(); $search->setConditions($search->compare('==', 'service.code', 'unitpaymentcode')); $result = $serviceManager->searchItems($search); if (($serviceItem = reset($result)) === false) { throw new \Exception('No service item found'); } $controller->setService('payment', $serviceItem->getId()); $controller->setAddress('payment', array('order.base.address.languageid' => 'en')); $this->context->setUserId('-1'); $view = \TestHelper::getView(); $param = array('cs_order' => 1); $helper = new \Aimeos\MW\View\Helper\Parameter\Standard($view, $param); $view->addHelper('param', $helper); $this->object->setView($view); $this->object->process(); $search = $baseManager->createSearch(); $search->setConditions($search->compare('==', 'order.base.customerid', '-1')); $result = $baseManager->searchItems($search); if (($item = reset($result)) === false) { throw new \Exception('No order placed'); } $baseManager->deleteItem($item->getId()); $this->assertInstanceOf('\\Aimeos\\MShop\\Order\\Item\\Iface', $view->orderItem); $this->assertEquals($item->getId(), $view->orderItem->getBaseId()); }
public function testSaveDeleteItem() { $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager(\TestHelperExtjs::getContext()); $search = $serviceManager->createSearch(); $search->setConditions($search->compare('==', 'service.label', 'unitlabel')); $resultService = $serviceManager->searchItems($search); if (($item = reset($resultService)) === false) { throw new \Exception('No service item found'); } $params = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('service.lists.type.domain' => 'product')))), 'start' => 0, 'limit' => 1); $serviceListTypeManager = \Aimeos\Controller\ExtJS\Service\Lists\Type\Factory::createController(\TestHelperExtjs::getContext()); $resultType = $serviceListTypeManager->searchItems($params); $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('service.lists.parentid' => $item->getId(), 'service.lists.typeid' => $resultType['items'][0]->{'service.lists.type.id'}, 'service.lists.domain' => 'product', 'service.lists.refid' => -1, 'service.lists.datestart' => '2000-01-01 00:00:00', 'service.lists.dateend' => '2001-01-01 00:00:00', 'service.lists.config' => array('test' => 'unit'), 'service.lists.position' => 1, 'service.lists.status' => 1)); $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('service.lists.refid' => -1))))); $saved = $this->object->saveItems($saveParams); $searched = $this->object->searchItems($searchParams); $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'service.lists.id'}); $this->object->deleteItems($deleteParams); $result = $this->object->searchItems($searchParams); $this->assertInternalType('object', $saved['items']); $this->assertNotNull($saved['items']->{'service.lists.id'}); $this->assertEquals($saved['items']->{'service.lists.id'}, $searched['items'][0]->{'service.lists.id'}); $this->assertEquals($saved['items']->{'service.lists.parentid'}, $searched['items'][0]->{'service.lists.parentid'}); $this->assertEquals($saved['items']->{'service.lists.typeid'}, $searched['items'][0]->{'service.lists.typeid'}); $this->assertEquals($saved['items']->{'service.lists.domain'}, $searched['items'][0]->{'service.lists.domain'}); $this->assertEquals($saved['items']->{'service.lists.refid'}, $searched['items'][0]->{'service.lists.refid'}); $this->assertEquals($saved['items']->{'service.lists.datestart'}, $searched['items'][0]->{'service.lists.datestart'}); $this->assertEquals($saved['items']->{'service.lists.dateend'}, $searched['items'][0]->{'service.lists.dateend'}); $this->assertEquals($saved['items']->{'service.lists.config'}, $searched['items'][0]->{'service.lists.config'}); $this->assertEquals($saved['items']->{'service.lists.position'}, $searched['items'][0]->{'service.lists.position'}); $this->assertEquals($saved['items']->{'service.lists.status'}, $searched['items'][0]->{'service.lists.status'}); $this->assertEquals(1, count($searched['items'])); $this->assertEquals(0, count($result['items'])); }
/** * Adds the service 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 addServiceData(array $testdata) { $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->additional, 'Standard'); $serviceTypeManager = $serviceManager->getSubManager('type', 'Standard'); $typeIds = array(); $type = $serviceTypeManager->createItem(); $this->conn->begin(); foreach ($testdata['service/type'] as $key => $dataset) { $type->setId(null); $type->setCode($dataset['code']); $type->setDomain($dataset['domain']); $type->setLabel($dataset['label']); $type->setStatus($dataset['status']); $serviceTypeManager->saveItem($type); $typeIds[$key] = $type->getId(); } $parent = $serviceManager->createItem(); foreach ($testdata['service'] as $key => $dataset) { if (!isset($typeIds[$dataset['typeid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No service type ID found for "%1$s"', $dataset['typeid'])); } $parent->setId(null); $parent->setTypeId($typeIds[$dataset['typeid']]); $parent->setPosition($dataset['pos']); $parent->setCode($dataset['code']); $parent->setLabel($dataset['label']); $parent->setProvider($dataset['provider']); $parent->setConfig($dataset['config']); $parent->setStatus($dataset['status']); $serviceManager->saveItem($parent, false); } $this->conn->commit(); }
public function testSaveDeleteItem() { $manager = \Aimeos\MShop\Service\Manager\Factory::createManager(\TestHelper::getContext()); $typeManager = $manager->getSubManager('type'); $search = $typeManager->createSearch(); $search->setConditions($search->compare('==', 'service.type.code', 'delivery')); $result = $typeManager->searchItems($search); if (($type = reset($result)) === false) { throw new \Exception('No service type found'); } $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('service.position' => 1, 'service.label' => 'test service', 'service.status' => 1, 'service.code' => 'testcode', 'service.provider' => 'Standard', 'service.config' => array('default.url' => 'www.url.de', 'default.project' => 'test'), 'service.typeid' => $type->getId())); $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => array('==' => (object) array('service.code' => 'testcode'))))); $saved = $this->object->saveItems($saveParams); $searched = $this->object->searchItems($searchParams); $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'service.id'}); $this->object->deleteItems($deleteParams); $result = $this->object->searchItems($searchParams); $this->assertInternalType('object', $saved['items']); $this->assertNotNull($saved['items']->{'service.id'}); $this->assertEquals($saved['items']->{'service.id'}, $searched['items'][0]->{'service.id'}); $this->assertEquals($saved['items']->{'service.position'}, $searched['items'][0]->{'service.position'}); $this->assertEquals($saved['items']->{'service.label'}, $searched['items'][0]->{'service.label'}); $this->assertEquals($saved['items']->{'service.status'}, $searched['items'][0]->{'service.status'}); $this->assertEquals($saved['items']->{'service.code'}, $searched['items'][0]->{'service.code'}); $this->assertEquals($saved['items']->{'service.provider'}, $searched['items'][0]->{'service.provider'}); $this->assertEquals($saved['items']->{'service.config'}, $searched['items'][0]->{'service.config'}); $this->assertEquals($saved['items']->{'service.typeid'}, $searched['items'][0]->{'service.typeid'}); $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() { $context = \TestHelper::getContext(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($context); $serviceItem = $serviceManager->createItem(); $this->object = new \Aimeos\MShop\Service\Provider\Delivery\Manual($context, $serviceItem); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->editor = \TestHelperMShop::getContext()->getEditor(); $manager = \Aimeos\MShop\Service\Manager\Factory::createManager(\TestHelperMShop::getContext()); $listManager = $manager->getSubManager('lists'); $this->object = $listManager->getSubManager('type'); }
/** * Executes the job. * * @throws \Aimeos\Controller\Jobs\Exception If an error occurs */ public function run() { $context = $this->getContext(); /** controller/jobs/order/service/delivery/limit-days * Only start the delivery process of orders that were created in the past within the configured number of days * * The delivery process is normally started immediately after the * notification about a successful payment arrived. This option prevents * orders from being shipped in case anything went wrong or an update * failed and old orders would have been shipped now. * * @param integer Number of days * @since 2014.03 * @category User * @category Developer * @see controller/jobs/order/email/payment/standard/limit-days * @see controller/jobs/order/email/delivery/standard/limit-days */ $days = $context->getConfig()->get('controller/jobs/order/service/delivery/limit-days', 90); $date = date('Y-m-d 00:00:00', time() - 86400 * $days); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($context); $serviceSearch = $serviceManager->createSearch(); $serviceSearch->setConditions($serviceSearch->compare('==', 'service.type.code', 'delivery')); $orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager($context); $orderSearch = $orderManager->createSearch(); $start = 0; do { $serviceItems = $serviceManager->searchItems($serviceSearch); foreach ($serviceItems as $serviceItem) { try { $serviceProvider = $serviceManager->getProvider($serviceItem); $expr = array($orderSearch->compare('==', 'order.siteid', $serviceItem->getSiteId()), $orderSearch->compare('>', 'order.datepayment', $date), $orderSearch->compare('>', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_PENDING), $orderSearch->compare('==', 'order.statusdelivery', \Aimeos\MShop\Order\Item\Base::STAT_UNFINISHED), $orderSearch->compare('==', 'order.base.service.code', $serviceItem->getCode()), $orderSearch->compare('==', 'order.base.service.type', 'delivery')); $orderSearch->setConditions($orderSearch->combine('&&', $expr)); $orderStart = 0; do { $orderItems = $orderManager->searchItems($orderSearch); foreach ($orderItems as $orderItem) { try { $serviceProvider->process($orderItem); $orderManager->saveItem($orderItem); } catch (\Exception $e) { $str = 'Error while processing order with ID "%1$s": %2$s'; $context->getLogger()->log(sprintf($str, $orderItem->getId(), $e->getMessage())); } } $orderCount = count($orderItems); $orderStart += $orderCount; $orderSearch->setSlice($orderStart); } while ($orderCount >= $orderSearch->getSliceSize()); } catch (\Exception $e) { $str = 'Error while processing service with ID "%1$s": %2$s'; $context->getLogger()->log(sprintf($str, $serviceItem->getId(), $e->getMessage())); } } $count = count($serviceItems); $start += $count; $serviceSearch->setSlice($start); } while ($count >= $serviceSearch->getSliceSize()); }
/** * 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->context = \TestHelper::getContext(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $item = $serviceManager->createItem(); $item->setConfig(array('sagepay.testmode' => true)); $this->object = $this->getMockBuilder('Aimeos\\MShop\\Service\\Provider\\Payment\\SagePayPublic')->setMethods(array('getOrder', 'getOrderBase', 'saveOrder', 'saveOrderBase', 'getProvider'))->setConstructorArgs(array($this->context, $item))->getMock(); }
protected function setUp() { $this->context = \TestHelperMShop::getContext(); $servManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $this->servItem = $servManager->createItem(); $this->mockProvider = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Provider\\Decorator\\Example')->disableOriginalConstructor()->getMock(); $this->object = new \Aimeos\MShop\Service\Provider\Decorator\Weight($this->mockProvider, $this->context, $this->servItem); }
/** * 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 = \TestHelperMShop::getContext(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($context); $serviceItem = $serviceManager->createItem(); $serviceItem->setCode('test'); $this->object = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Provider\\Payment\\PostPay')->setMethods(array('getOrder', 'getOrderBase', 'saveOrder', 'saveOrderBase'))->setConstructorArgs(array($context, $serviceItem))->getMock(); }
/** * 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(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($context); $item = $serviceManager->createItem(); $item->setConfig(array('authorizenet.testmode' => true)); $this->object = new AuthorizeAIMPublic($context, $item); }
protected function setUp() { $this->context = \TestHelperMShop::getContext(); $this->context->setUserId(null); $servManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $this->servItem = $servManager->createItem(); $this->mockProvider = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Provider\\Decorator\\OrderCheck')->disableOriginalConstructor()->getMock(); $this->basket = \Aimeos\MShop\Order\Manager\Factory::createManager($this->context)->getSubManager('base')->createItem(); $this->object = new \Aimeos\MShop\Service\Provider\Decorator\OrderCheck($this->mockProvider, $this->context, $this->servItem); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { if (!class_exists('Omnipay\\Omnipay')) { $this->markTestSkipped('Omnipay library not available'); } $this->context = \TestHelper::getContext(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $item = $serviceManager->createItem(); $item->setConfig(array('authorizenet.testmode' => true)); $this->object = $this->getMockBuilder('Aimeos\\MShop\\Service\\Provider\\Payment\\AuthorizeSIMPublic')->setMethods(array('getOrder', 'getOrderBase', 'saveOrder', 'saveOrderBase', 'getProvider'))->setConstructorArgs(array($this->context, $item))->getMock(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { if (!class_exists('Omnipay\\Omnipay')) { $this->markTestSkipped('Omnipay library not available'); } $this->context = \TestHelper::getContext(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $this->serviceItem = $serviceManager->createItem(); $this->serviceItem->setConfig(array('omnipay.type' => 'Dummy')); $this->object = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Provider\\Payment\\OmniPay')->setMethods(array('getOrder', 'getOrderBase', 'saveOrder', 'saveOrderBase', 'getProvider', 'saveTransationRef'))->setConstructorArgs(array($this->context, $this->serviceItem))->getMock(); }
protected function setUp() { $this->context = \TestHelper::getContext(); $servManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $search = $servManager->createSearch(); $search->setConditions($search->compare('==', 'service.provider', 'Standard')); $result = $servManager->searchItems($search, array('price')); if (($item = reset($result)) === false) { throw new \Exception('No order base item found'); } $this->object = new TestBase($this->context, $item); }
protected function setUp() { $this->context = \TestHelperMShop::getContext(); $servManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $search = $servManager->createSearch(); $search->setConditions($search->compare('==', 'service.provider', 'Standard')); $result = $servManager->searchItems($search, array('price')); if (($item = reset($result)) === false) { throw new \RuntimeException('No order base item found'); } $this->mock = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Provider\\Payment\\PrePay')->setConstructorArgs(array($this->context, $item))->setMethods(array('calcPrice', 'checkConfigBE', 'checkConfigFE', 'getConfigBE', 'getConfigFE', 'injectGlobalConfigBE', 'isAvailable', 'isImplemented', 'query', 'cancel', 'capture', 'process', 'refund', 'setCommunication', 'setConfigFE', 'updateAsync', 'updateSync'))->getMock(); $this->object = new TestBase($this->mock, $this->context, $item); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager(\TestHelper::getContext()); $search = $serviceManager->createSearch(); $search->setConditions($search->compare('==', 'service.provider', 'Standard')); $result = $serviceManager->searchItems($search, array('price')); if (($item = reset($result)) === false) { throw new \Exception('No order base item found'); } $item->setConfig(array('default.project' => '8502_TEST')); $item->setCode('test'); $this->object = new \Aimeos\MShop\Service\Provider\Delivery\Standard(\TestHelper::getContext(), $item); }
public function testRunExceptionProcess() { $context = \TestHelper::getContext(); $aimeos = \TestHelper::getAimeos(); $name = 'ControllerJobsServiceAsyncProcessDefaultRun'; $context->getConfig()->set('mshop/service/manager/name', $name); $serviceManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Manager\\Standard')->setMethods(array('getProvider', 'searchItems'))->setConstructorArgs(array($context))->getMock(); \Aimeos\MShop\Service\Manager\Factory::injectManager('\\Aimeos\\MShop\\Service\\Manager\\' . $name, $serviceManagerStub); $serviceItem = $serviceManagerStub->createItem(); $serviceManagerStub->expects($this->once())->method('searchItems')->will($this->onConsecutiveCalls(array($serviceItem), array())); $serviceManagerStub->expects($this->once())->method('getProvider')->will($this->throwException(new \Aimeos\MShop\Service\Exception())); $object = new \Aimeos\Controller\Jobs\Order\Service\Async\Standard($context, $aimeos); $object->run(); }
protected function setUp() { $context = \TestHelperMShop::getContext(); $servManager = \Aimeos\MShop\Service\Manager\Factory::createManager($context); $search = $servManager->createSearch(); $search->setConditions($search->compare('==', 'service.provider', 'Standard')); $result = $servManager->searchItems($search, array('price')); if (($item = reset($result)) === false) { throw new \RuntimeException('No order base item found'); } $item->setConfig(array('default.project' => '8502_TEST')); $serviceProvider = $servManager->getProvider($item); $this->object = new \Aimeos\MShop\Service\Provider\Decorator\Example($serviceProvider, $context, $item); }
/** * Insert product data. */ public function migrate() { $this->msg('Adding service base performance data', 0); $manager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->getContext()); $typeManager = $manager->getSubManager('type'); $search = $typeManager->createSearch(); $expr = array($search->compare('==', 'service.type.domain', 'service'), $search->compare('==', 'service.type.code', 'payment')); $search->setConditions($search->combine('&&', $expr)); $types = $typeManager->searchItems($search); if (($typeItem = reset($types)) === false) { throw new \RuntimeException('Service type item "payment" not found'); } $item = $manager->createItem(); $item->setTypeId($typeItem->getId()); $item->setProvider('PrePay'); $item->setStatus(1); $this->txBegin(); for ($i = 0; $i < 100; $i++) { $code = 'perf-' . str_pad($i, 3, '0', STR_PAD_LEFT); $item->setId(null); $item->setCode($code); $item->setLabel('Payment service ' . $code); $item->setPosition($i); $manager->saveItem($item, false); } $this->txCommit(); $search = $typeManager->createSearch(); $expr = array($search->compare('==', 'service.type.domain', 'service'), $search->compare('==', 'service.type.code', 'delivery')); $search->setConditions($search->combine('&&', $expr)); $types = $typeManager->searchItems($search); if (($typeItem = reset($types)) === false) { throw new \RuntimeException('Service type item "delivery" not found'); } $item = $manager->createItem(); $item->setTypeId($typeItem->getId()); $item->setProvider('Manual'); $item->setStatus(1); $this->txBegin(); for ($i = 0; $i < 100; $i++) { $code = 'perf-' . str_pad($i, 3, '0', STR_PAD_LEFT); $item->setId(null); $item->setCode($code); $item->setLabel('Delivery service ' . $code); $item->setPosition($i); $manager->saveItem($item, false); } $this->txCommit(); $this->status('done'); }
/** * 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->context = \TestHelper::getContext(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $search = $serviceManager->createSearch(); $search->setConditions($search->compare('==', 'service.code', 'paypalexpress')); $serviceItems = $serviceManager->searchItems($search); if (($this->serviceItem = reset($serviceItems)) === false) { throw new \Exception('No paypalexpress service item available'); } $this->object = new \Aimeos\MShop\Service\Provider\Payment\PayPalExpress($this->context, $this->serviceItem); $orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager($this->context); $search = $orderManager->createSearch(); $expr = array($search->compare('==', 'order.type', \Aimeos\MShop\Order\Item\Base::TYPE_WEB), $search->compare('==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED)); $search->setConditions($search->combine('&&', $expr)); $orderItems = $orderManager->searchItems($search); if (($this->order = reset($orderItems)) === false) { throw new \Exception(sprintf('No Order found with statuspayment "%1$s" and type "%2$s"', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, \Aimeos\MShop\Order\Item\Base::TYPE_WEB)); } $this->context->getConfig()->set('mshop/order/manager/name', 'MockPayPal'); $orderMock = $this->getMock('\\Aimeos\\MShop\\Order\\Manager\\Standard', array('saveItem'), array($this->context)); \Aimeos\MShop\Order\Manager\Factory::injectManager('\\Aimeos\\MShop\\Order\\Manager\\MockPayPal', $orderMock); }
public function testProcessNotExistingAttributes() { $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $search = $serviceManager->createSearch(); $search->setConditions($search->compare('==', 'service.code', 'unitpaymentcode')); $result = $serviceManager->searchItems($search); if (($service = reset($result)) === false) { throw new \Exception('Service item not found'); } $view = \TestHelper::getView(); $param = array('c_paymentoption' => $service->getId(), 'c_payment' => array($service->getId() => array('notexisting' => 'invalid value'))); $helper = new \Aimeos\MW\View\Helper\Parameter\Standard($view, $param); $view->addHelper('param', $helper); $this->object->setView($view); $this->setExpectedException('\\Aimeos\\Controller\\Frontend\\Basket\\Exception'); $this->object->process(); }
/** * Returns the service item IDs for the given test data. * * @param array $testdata Test data * @return array List of service IDs */ protected function getServiceIds(array $testdata) { $services = $servIds = array(); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->additional, 'Standard'); foreach ($testdata['order/base/service'] as $key => $dataset) { if (isset($dataset['servid'])) { $services[$key] = $dataset['servid']; } } $search = $serviceManager->createSearch(); $search->setConditions($search->compare('==', 'service.code', $services)); $servicesResult = $serviceManager->searchItems($search); foreach ($servicesResult as $id => $service) { $servIds[$service->getCode()] = $id; } return $servIds; }
/** * Returns the service type IDs for the given domains and codes * * @param array $domain Domain the service type is for * @param array $code Code the service type is for * @return array List of service type IDs */ protected function getServiceTypeIds(array $domain, array $code) { $manager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->additional, 'Standard'); $typeManager = $manager->getSubManager('type', 'Standard'); $search = $typeManager->createSearch(); $expr = array($search->compare('==', 'service.type.domain', $domain), $search->compare('==', 'service.type.code', $code)); $search->setConditions($search->combine('&&', $expr)); $typeids = array(); foreach ($typeManager->searchItems($search) as $item) { $typeids[] = $item->getId(); } return $typeids; }
public function testCopyFrom() { $serviceCopy = new \Aimeos\MShop\Order\Item\Base\Service\Standard($this->price); $manager = \Aimeos\MShop\Service\Manager\Factory::createManager(\TestHelperMShop::getContext()); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'service.provider', 'Standard')); $services = $manager->searchItems($search); if (($service = reset($services)) === false) { throw new \Exception('No service found'); } $return = $serviceCopy->copyFrom($service); $this->assertInstanceOf('\\Aimeos\\MShop\\Order\\Item\\Base\\Service\\Iface', $return); $this->assertEquals('unitcode', $serviceCopy->getCode()); $this->assertEquals('unitlabel', $serviceCopy->getName()); $this->assertEquals('delivery', $serviceCopy->getType()); $this->assertEquals('', $serviceCopy->getMediaUrl()); $this->assertTrue($serviceCopy->isModified()); }
protected function getBasket() { $controller = \Aimeos\Controller\Frontend\Basket\Factory::createController($this->context); $customerManager = \Aimeos\MShop\Customer\Manager\Factory::createManager($this->context); $customer = $customerManager->findItem('UTC001'); $controller->setAddress(\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, $customer->getPaymentAddress()); $controller->setAddress(\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, $customer->getPaymentAddress()); $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context); $product = $productManager->findItem('CNE'); $controller->addProduct($product->getId(), 2, array(), array(), array(), array(), array(), 'default'); $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context); $service = $serviceManager->findItem('unitpaymentcode', array(), 'service', 'payment'); $controller->setService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT, $service->getId()); $service = $serviceManager->findItem('unitcode', array(), 'service', 'delivery'); $controller->setService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY, $service->getId()); return $controller->get(); }
/** * Adds the service-list test data. * * @param array $testdata Associative list of key/list pairs * @param array $refIds Associative list of domains and the keys/IDs of the inserted items * @throws \Aimeos\MW\Setup\Exception If a required ID is not available */ protected function addServiceListData(array $testdata, array $refIds) { $serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager($this->additional, 'Standard'); $serviceTypeManager = $serviceManager->getSubManager('type', 'Standard'); $serviceListManager = $serviceManager->getSubManager('lists', 'Standard'); $serviceListTypeManager = $serviceListManager->getSubmanager('type', 'Standard'); $typeDomain = $typeCode = $itemCode = array(); foreach ($testdata['service/lists'] as $dataset) { $exp = explode('/', $dataset['parentid']); if (count($exp) != 3) { throw new \Aimeos\MW\Setup\Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid'])); } $typeDomain[] = $exp[0]; $typeCode[] = $exp[1]; $itemCode[] = $exp[2]; } $search = $serviceTypeManager->createSearch(); $expr = array($search->compare('==', 'service.type.domain', $typeDomain), $search->compare('==', 'service.type.code', $typeCode)); $search->setConditions($search->combine('&&', $expr)); $typeids = array(); foreach ($serviceTypeManager->searchItems($search) as $item) { $typeids[] = $item->getId(); } $search = $serviceManager->createSearch(); $expr = array($search->compare('==', 'service.code', $itemCode), $search->compare('==', 'service.typeid', $typeids)); $search->setConditions($search->combine('&&', $expr)); $parentIds = array(); foreach ($serviceManager->searchItems($search) as $item) { $parentIds['service/' . $item->getType() . '/' . $item->getCode()] = $item->getId(); } $listItemTypeIds = array(); $listItemType = $serviceListTypeManager->createItem(); $this->conn->begin(); foreach ($testdata['service/lists/type'] as $key => $dataset) { $listItemType->setId(null); $listItemType->setCode($dataset['code']); $listItemType->setDomain($dataset['domain']); $listItemType->setLabel($dataset['label']); $listItemType->setStatus($dataset['status']); $serviceListTypeManager->saveItem($listItemType); $listItemTypeIds[$key] = $listItemType->getId(); } $listItem = $serviceListManager->createItem(); foreach ($testdata['service/lists'] as $dataset) { if (!isset($parentIds[$dataset['parentid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No service ID found for "%1$s"', $dataset['parentid'])); } if (!isset($listItemTypeIds[$dataset['typeid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No service list type ID found for "%1$s"', $dataset['typeid'])); } if (!isset($refIds[$dataset['domain']][$dataset['refid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No "%1$s" ref ID found for "%2$s"', $dataset['refid'], $dataset['domain'])); } $listItem->setId(null); $listItem->setParentId($parentIds[$dataset['parentid']]); $listItem->setTypeId($listItemTypeIds[$dataset['typeid']]); $listItem->setRefId($refIds[$dataset['domain']][$dataset['refid']]); $listItem->setDomain($dataset['domain']); $listItem->setDateStart($dataset['start']); $listItem->setDateEnd($dataset['end']); $listItem->setConfig($dataset['config']); $listItem->setPosition($dataset['pos']); $listItem->setStatus($dataset['status']); $serviceListManager->saveItem($listItem, false); } $this->conn->commit(); }
public function testUpdateNotAvailable() { $context = \TestHelper::getContext(); $object = new \Aimeos\MShop\Plugin\Provider\Order\ServicesUpdate($context, $this->plugin); $priceManager = \Aimeos\MShop\Factory::createManager($context, 'price'); $localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale'); $orderBaseProductManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product'); $orderBaseServiceManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/service'); $priceItem = $priceManager->createItem(); $localeItem = $localeManager->createItem(); $orderProduct = $orderBaseProductManager->createItem(); $serviceDelivery = $orderBaseServiceManager->createItem(); $serviceDelivery->setServiceId(1); $servicePayment = $orderBaseServiceManager->createItem(); $servicePayment->setServiceId(2); $orderStub = $this->getMockBuilder('\\Aimeos\\MShop\\Order\\Item\\Base\\Standard')->setConstructorArgs(array($priceItem, $localeItem))->setMethods(array('getProducts'))->getMock(); $serviceStub = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Manager\\Standard')->setConstructorArgs(array($context))->setMethods(array('searchItems', 'getProvider'))->getMock(); \Aimeos\MShop\Service\Manager\Factory::injectManager('\\Aimeos\\MShop\\Service\\Manager\\PluginServicesUpdate', $serviceStub); $context->getConfig()->set('mshop/service/manager/name', 'PluginServicesUpdate'); $orderStub->setService($serviceDelivery, 'delivery'); $orderStub->setService($servicePayment, 'payment'); $serviceItemDelivery = new \Aimeos\MShop\Service\Item\Standard(array('type' => 'delivery')); $serviceItemPayment = new \Aimeos\MShop\Service\Item\Standard(array('type' => 'payment')); $providerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Manual')->setConstructorArgs(array($context, $serviceStub->createItem()))->setMethods(array('isAvailable'))->getMock(); $orderStub->expects($this->once())->method('getProducts')->will($this->returnValue(array($orderProduct))); $serviceStub->expects($this->once())->method('searchItems')->will($this->returnValue(array(1 => $serviceItemDelivery, 2 => $serviceItemPayment))); $serviceStub->expects($this->exactly(2))->method('getProvider')->will($this->returnValue($providerStub)); $providerStub->expects($this->exactly(2))->method('isAvailable')->will($this->returnValue(false)); $this->assertTrue($object->update($orderStub, 'addProduct.after')); $this->assertEquals(array(), $orderStub->getServices()); }
/** * 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->context = \TestHelper::getContext(); $serviceItem = \Aimeos\MShop\Service\Manager\Factory::createManager($this->context)->createItem(); $this->object = new TestBase($this->context, $serviceItem); }
public function testCreateManagerNotExisting() { $this->setExpectedException('\\Aimeos\\MShop\\Exception'); \Aimeos\MShop\Service\Manager\Factory::createManager(\TestHelperMShop::getContext(), 'unknown'); }