public function testProcess() { $type = MShop_Order_Item_Base_Address_Abstract::TYPE_DELIVERY; $manager = MShop_Customer_Manager_Factory::createManager($this->_context); $addrManager = $manager->getSubManager('address'); $search = $manager->createSearch(); $search->setSlice(0, 1); $result = $manager->searchItems($search); if (($customerItem = reset($result)) === false) { throw new Exception('No customer item found'); } $addrItem = $customerItem->getPaymentAddress(); $addrItem->setId(null); $basketCntl = Controller_Frontend_Basket_Factory::createController($this->_context); $basketCntl->setAddress($type, $addrItem); $view = TestHelper::getView(); $view->orderBasket = $basketCntl->get(); $view->orderBasket->setCustomerId($customerItem->getId()); $this->_object->setView($view); $this->_object->process(); $orderAddress = $view->orderBasket->getAddress($type); $actual = $addrManager->getItem($orderAddress->getAddressId()); $addrManager->deleteItem($actual->getId()); $this->assertEquals($addrItem->getFirstname(), $actual->getFirstname()); $this->assertEquals($addrItem->getLastname(), $actual->getLastname()); $this->assertEquals($addrItem->getPostal(), $actual->getPostal()); $this->assertEquals($addrItem->getTelephone(), $actual->getTelephone()); $this->assertEquals($addrItem->getTelefax(), $actual->getTelefax()); }
/** * Inserts customer items. */ protected function _process() { $this->_msg('Adding customer performance data', 0); $context = $this->_getContext(); $customerManager = MShop_Customer_Manager_Factory::createManager($context); $customerItem = $customerManager->createItem(); $customerItem->setCode('demo-test'); $customerItem->setLabel('Test demo unitperf user'); $customerItem->setPassword(sha1(microtime(true) . getmypid() . rand())); $customerItem->setStatus(1); $addrItem = $customerItem->getPaymentAddress(); $addrItem->setCompany('Test company'); $addrItem->setVatID('DE999999999'); $addrItem->setSalutation('mr'); $addrItem->setFirstname('Testdemo'); $addrItem->setLastname('Perfuser'); $addrItem->setAddress1('Test street'); $addrItem->setAddress2('1'); $addrItem->setPostal('1000'); $addrItem->setCity('Test city'); $addrItem->setLanguageId('en'); $addrItem->setCountryId('DE'); $addrItem->setEmail('me@localhost'); $customerManager->saveItem($customerItem); $this->_status('done'); }
public function testProcess() { $type = MShop_Order_Item_Base_Address_Abstract::TYPE_PAYMENT; $manager = MShop_Customer_Manager_Factory::createManager($this->_context); $search = $manager->createSearch(); $search->setSlice(0, 1); $result = $manager->searchItems($search); if (($customerItem = reset($result)) === false) { throw new Exception('No customer item found'); } $addrItem = $customerItem->getPaymentAddress(); $addrItem->setEmail('*****@*****.**'); $basketCntl = Controller_Frontend_Basket_Factory::createController($this->_context); $basketCntl->setAddress($type, $addrItem); $view = TestHelper::getView(); $view->orderBasket = $basketCntl->get(); $this->_object->setView($view); $orderBaseStub = $this->getMockBuilder('MShop_Order_Manager_Base_Default')->setConstructorArgs(array($this->_context))->setMethods(array('saveItem'))->getMock(); $customerStub = $this->getMockBuilder('MShop_Customer_Manager_Default')->setConstructorArgs(array($this->_context))->setMethods(array('saveItem'))->getMock(); $orderBaseStub->expects($this->once())->method('saveItem'); $customerStub->expects($this->once())->method('saveItem'); MShop_Factory::injectManager($this->_context, 'customer', $customerStub); MShop_Factory::injectManager($this->_context, 'order/base', $orderBaseStub); $this->_object->process(); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); $target = 'MShop_Common_Manager_Interface'; $manager = MShop_Customer_Manager_Factory::createManager(TestHelper::getContext(), 'NotExist'); $this->assertInstanceOf($target, $manager); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_editor = TestHelper::getContext()->getEditor(); $manager = MShop_Customer_Manager_Factory::createManager(TestHelper::getContext(), 'FosUser'); $listManager = $manager->getSubManager('list', 'FosUser'); $this->_object = $listManager->getSubManager('type', 'FosUser'); }
public static function setUpBeforeClass() { $manager = MShop_Customer_Manager_Factory::createManager(TestHelper::getContext()); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', 'UTC001')); $result = $manager->searchItems($search); if ((self::$_customerItem = reset($result)) === false) { throw new Exception('No customer found'); } }
/** * @param string $code */ protected function _getCustomerItem($code) { $manager = MShop_Customer_Manager_Factory::createManager($this->_context); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', $code)); $items = $manager->searchItems($search); if (($item = reset($items)) === false) { throw new Exception(sprintf('No customer item with code "%1$s" found', $code)); } return $item; }
protected function _getBasket() { $customerManager = MShop_Customer_Manager_Factory::createManager($this->_context); $search = $customerManager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', 'UTC001')); $result = $customerManager->searchItems($search); if (($customer = reset($result)) === false) { throw new Exception('Customer item not found'); } $controller = Controller_Frontend_Basket_Factory::createController($this->_context); $controller->setAddress(MShop_Order_Item_Base_Address_Abstract::TYPE_PAYMENT, $customer->getPaymentAddress()); $controller->setAddress(MShop_Order_Item_Base_Address_Abstract::TYPE_DELIVERY, $customer->getPaymentAddress()); return $controller->get(); }
public static function setUpBeforeClass() { $context = TestHelper::getContext(); $manager = MShop_Customer_Manager_Factory::createManager($context); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', 'UTC001')); $result = $manager->searchItems($search); if ((self::$_customerItem = reset($result)) === false) { throw new Exception('No customer found'); } $manager = MShop_Product_Manager_Factory::createManager($context); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'product.code', array('CNC', 'CNE'))); self::$_productItems = $manager->searchItems($search, array('text', 'price', 'media')); }
/** * Gets required customer item ids. * * @param array $keys List with referenced Ids * @return array $refIds List with referenced Ids * @throws MW_Setup_Exception If no type ID is found */ private function _getCustomerData(array $keys) { $customerManager = MShop_Customer_Manager_Factory::createManager($this->_additional, 'Default'); $codes = array(); foreach ($keys as $dataset) { if (($pos = strpos($dataset, '/')) === false || ($str = substr($dataset, $pos + 1)) === false) { throw new MW_Setup_Exception(sprintf('Some keys for ref customer are set wrong "%1$s"', $dataset)); } $codes[] = $str; } $search = $customerManager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', $codes)); $refIds = array(); foreach ($customerManager->searchItems($search) as $item) { $refIds['customer/' . $item->getCode()] = $item->getId(); } return $refIds; }
/** * Adds customer test 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 customer test data', 0); $this->_additional->setEditor('core:unittest'); $ds = DIRECTORY_SEPARATOR; $path = dirname(__FILE__) . $ds . 'data' . $ds . 'customer.php'; if (($testdata = (include $path)) == false) { throw new MShop_Exception(sprintf('No file "%1$s" found for customer domain', $path)); } $customerManager = MShop_Customer_Manager_Factory::createManager($this->_additional, 'Default'); $customerAddressManager = $customerManager->getSubManager('address', 'Default'); $this->_conn->begin(); $parentIds = $this->_addCustomerData($testdata, $customerManager, $customerAddressManager->createItem()); $this->_addCustomerAddressData($testdata, $customerAddressManager, $parentIds); $this->_conn->commit(); $this->_status('done'); }
/** * Adds customer TYPO3 test 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 Fos user bundle customer test data', 0); $this->_additional->setEditor('ai-symfony:unittest'); $parentIds = array(); $ds = DIRECTORY_SEPARATOR; $path = __DIR__ . $ds . 'data' . $ds . 'customer.php'; if (($testdata = (include $path)) === false) { throw new MShop_Exception(sprintf('No file "%1$s" found for customer domain', $path)); } $customerManager = MShop_Customer_Manager_Factory::createManager($this->_additional, 'FosUser'); $customerAddressManager = $customerManager->getSubManager('address', 'FosUser'); foreach ($customerManager->searchItems($customerManager->createSearch()) as $id => $item) { $parentIds['customer/' . $item->getCode()] = $id; } $this->_conn->begin(); $this->_addCustomerAddressData($testdata, $customerAddressManager, $parentIds); $this->_conn->commit(); $this->_status('done'); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); MShop_Customer_Manager_Factory::createManager(TestHelper::getContext(), 'unknown'); }
/** * @param string $company */ protected function _getAddress($company) { $customer = MShop_Customer_Manager_Factory::createManager(TestHelper::getContext(), 'Default'); $addressManager = $customer->getSubManager('address', 'Default'); $search = $addressManager->createSearch(); $search->setConditions($search->compare('==', 'customer.address.company', $company)); $items = $addressManager->searchItems($search); if (($item = reset($items)) === false) { throw new Exception(sprintf('No address item with company "%1$s" found', $company)); } return $item; }
/** * Returns the customer IDs for the given test data. * * @param array $testdata Test data * @return array Customer Ids */ protected function _getCustomerIds(array $testdata) { $customercodes = $customerIds = array(); foreach ($testdata['order/base'] as $key => $dataset) { $customercodes[] = $dataset['customerid']; } $customerManager = MShop_Customer_Manager_Factory::createManager($this->_additional, 'Default'); $search = $customerManager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', $customercodes)); foreach ($customerManager->searchItems($search) as $id => $customerItem) { $customerIds[$customerItem->getCode()] = $id; } return $customerIds; }
public function testProcessExistingAddress() { $customerManager = MShop_Customer_Manager_Factory::createManager($this->_context); $search = $customerManager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', 'UTC001')); $result = $customerManager->searchItems($search); if (($customer = reset($result)) === false) { throw new Exception('Customer item not found'); } $customerAddressManager = $customerManager->getSubManager('address'); $search = $customerAddressManager->createSearch(); $search->setConditions($search->compare('==', 'customer.address.refid', $customer->getId())); $result = $customerAddressManager->searchItems($search); if (($address = reset($result)) === false) { throw new Exception('Customer address item not found'); } $this->_context->setUserId($customer->getId()); $view = TestHelper::getView(); $param = array('ca-delivery-option' => $address->getId()); $helper = new MW_View_Helper_Parameter_Default($view, $param); $view->addHelper('param', $helper); $this->_object->setView($view); $this->_object->process(); $this->_context->setEditor(null); $basket = Controller_Frontend_Basket_Factory::createController($this->_context)->get(); $this->assertEquals('Metaways', $basket->getAddress('delivery')->getCompany()); }
/** * Adds the customer-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 * @param string $type Manager type string * @throws MW_Setup_Exception If a required ID is not available */ protected function _addCustomerListData(array $testdata, array $refIds, $type = 'Default') { $customerManager = MShop_Customer_Manager_Factory::createManager($this->_additional, $type); $customerListManager = $customerManager->getSubManager('list', $type); $customerListTypeManager = $customerListManager->getSubmanager('type', $type); $itemCode = array(); foreach ($testdata['customer/list'] as $dataset) { if (($pos = strpos($dataset['parentid'], '/')) === false || ($str = substr($dataset['parentid'], $pos + 1)) === false) { throw new MW_Setup_Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid'])); } $itemCode[] = $str; } $search = $customerManager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', $itemCode)); $parentIds = array(); foreach ($customerManager->searchItems($search) as $item) { $parentIds['customer/' . $item->getCode()] = $item->getId(); } $listItemTypeIds = array(); $listItemType = $customerListTypeManager->createItem(); $this->_conn->begin(); foreach ($testdata['customer/list/type'] as $key => $dataset) { $listItemType->setId(null); $listItemType->setCode($dataset['code']); $listItemType->setDomain($dataset['domain']); $listItemType->setLabel($dataset['label']); $listItemType->setStatus($dataset['status']); $customerListTypeManager->saveItem($listItemType); $listItemTypeIds[$key] = $listItemType->getId(); } $listItem = $customerListManager->createItem(); foreach ($testdata['customer/list'] as $dataset) { if (!isset($parentIds[$dataset['parentid']])) { throw new MW_Setup_Exception(sprintf('No customer ID found for "%1$s"', $dataset['parentid'])); } if (!isset($refIds[$dataset['domain']][$dataset['refid']])) { throw new MW_Setup_Exception(sprintf('No "%2$s" ref ID found for "%1$s"', $dataset['refid'], $dataset['domain'])); } if (!isset($listItemTypeIds[$dataset['typeid']])) { throw new MW_Setup_Exception(sprintf('No customer list type ID found for "%1$s"', $dataset['typeid'])); } $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']); $customerListManager->saveItem($listItem, false); } $this->_conn->commit(); }
protected function _getListItems() { $manager = MShop_Customer_Manager_Factory::createManager($this->_context, 'FosUser'); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', 'unitCustomer3')); $search->setSlice(0, 1); $results = $manager->searchItems($search); if (($item = reset($results)) === false) { throw new Exception('No customer item found'); } $search = $this->_object->createSearch(); $expr = array($search->compare('==', 'customer.list.parentid', $item->getId()), $search->compare('==', 'customer.list.domain', 'text'), $search->compare('==', 'customer.list.editor', $this->_editor), $search->compare('==', 'customer.list.type.code', 'default')); $search->setConditions($search->combine('&&', $expr)); $search->setSortations(array($search->sort('+', 'customer.list.position'))); return $this->_object->searchItems($search); }
/** * Returns the customer item for the given code * * @param string $code Unique customer code * @throws Exception If no customer item is found * @return MShop_Customer_Item_Interface Customer item object */ protected function _getCustomerItem($code = 'UTC001') { $customerManager = MShop_Customer_Manager_Factory::createManager($this->_context); $search = $customerManager->createSearch(); $search->setConditions($search->compare('==', 'customer.code', $code)); $result = $customerManager->searchItems($search); if (($customer = reset($result)) === false) { throw new Exception('Customer item not found'); } return $customer; }
/** * Sets up the fixture. This method is called before a test is executed. */ protected function setUp() { $this->_editor = TestHelper::getContext()->getEditor(); $manager = MShop_Customer_Manager_Factory::createManager(TestHelper::getContext(), 'Typo3'); $this->_object = $manager->getSubManager('address', 'Typo3'); }