/** * 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_Supplier_Manager_Factory::createManager(TestHelper::getContext()); $listManager = $manager->getSubManager('list'); $this->_object = $listManager->getSubManager('type'); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); $target = 'MShop_Common_Manager_Interface'; $manager = MShop_Supplier_Manager_Factory::createManager(TestHelper::getContext(), 'test'); $this->assertInstanceOf($target, $manager); }
/** * Adds the supplier test data. * * @throws MW_Setup_Exception If a required ID is not available */ private function _addSupplierData() { $supplierManager = MShop_Supplier_Manager_Factory::createManager($this->_additional, 'Default'); $supplierAddressManager = $supplierManager->getSubManager('address', 'Default'); $ds = DIRECTORY_SEPARATOR; $path = dirname(__FILE__) . $ds . 'data' . $ds . 'supplier.php'; if (($testdata = (include $path)) == false) { throw new MShop_Exception(sprintf('No file "%1$s" found for supplier domain', $path)); } $supIds = array(); $supplier = $supplierManager->createItem(); $this->_conn->begin(); foreach ($testdata['supplier'] as $key => $dataset) { $supplier->setId(null); $supplier->setCode($dataset['code']); $supplier->setLabel($dataset['label']); $supplier->setStatus($dataset['status']); $supplierManager->saveItem($supplier); $supIds[$key] = $supplier->getId(); } $supAdr = $supplierAddressManager->createItem(); foreach ($testdata['supplier/address'] as $dataset) { if (!isset($supIds[$dataset['refid']])) { throw new MW_Setup_Exception(sprintf('No supplier ID found for "%1$s"', $dataset['refid'])); } $supAdr->setId(null); $supAdr->setCompany($dataset['company']); $supAdr->setVatID(isset($dataset['vatid']) ? $dataset['vatid'] : ''); $supAdr->setVatID($dataset['vatid']); $supAdr->setSalutation($dataset['salutation']); $supAdr->setTitle($dataset['title']); $supAdr->setFirstname($dataset['firstname']); $supAdr->setLastname($dataset['lastname']); $supAdr->setAddress1($dataset['address1']); $supAdr->setAddress2($dataset['address2']); $supAdr->setAddress3($dataset['address3']); $supAdr->setPostal($dataset['postal']); $supAdr->setCity($dataset['city']); $supAdr->setState($dataset['state']); $supAdr->setCountryId($dataset['countryid']); $supAdr->setTelephone($dataset['telephone']); $supAdr->setEmail($dataset['email']); $supAdr->setTelefax($dataset['telefax']); $supAdr->setWebsite($dataset['website']); $supAdr->setLanguageId($dataset['langid']); $supAdr->setRefId($supIds[$dataset['refid']]); $supplierAddressManager->saveItem($supAdr, false); } $this->_conn->commit(); }
/** * Sets up the fixture. This method is called before a test is executed. */ protected function setUp() { $this->_editor = TestHelper::getContext()->getEditor(); $supplierManager = MShop_Supplier_Manager_Factory::createManager(TestHelper::getContext()); $this->_object = $supplierManager->getSubManager('address'); }
protected function _getListItems() { $manager = MShop_Supplier_Manager_Factory::createManager($this->_context, 'Default'); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'supplier.code', 'unitCode001')); $search->setSlice(0, 1); $results = $manager->searchItems($search); if (($item = reset($results)) === false) { throw new Exception('No supplier item found'); } $search = $this->_object->createSearch(); $expr = array($search->compare('==', 'supplier.list.parentid', $item->getId()), $search->compare('==', 'supplier.list.domain', 'text'), $search->compare('==', 'supplier.list.editor', $this->_editor), $search->compare('==', 'supplier.list.type.code', 'default')); $search->setConditions($search->combine('&&', $expr)); $search->setSortations(array($search->sort('+', 'supplier.list.position'))); return $this->_object->searchItems($search); }
/** * Initializes the supplier controller. * * @param MShop_Context_Item_Interface $context MShop context object */ public function __construct(MShop_Context_Item_Interface $context) { parent::__construct($context, 'Supplier'); $this->_manager = MShop_Supplier_Manager_Factory::createManager($context); }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); MShop_Supplier_Manager_Factory::createManager(TestHelper::getContext(), 'unknown'); }
/** * Adds the supplier-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 _addSupplierListData(array $testdata, array $refIds, $type = 'Default') { $supplierManager = MShop_Supplier_Manager_Factory::createManager($this->_additional, $type); $supplierListManager = $supplierManager->getSubManager('list', $type); $supplierListTypeManager = $supplierListManager->getSubmanager('type', $type); $itemCode = array(); foreach ($testdata['supplier/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 = $supplierManager->createSearch(); $search->setConditions($search->compare('==', 'supplier.code', $itemCode)); $parentIds = array(); foreach ($supplierManager->searchItems($search) as $item) { $parentIds['supplier/' . $item->getCode()] = $item->getId(); } $listItemTypeIds = array(); $listItemType = $supplierListTypeManager->createItem(); $this->_conn->begin(); foreach ($testdata['supplier/list/type'] as $key => $dataset) { $listItemType->setId(null); $listItemType->setCode($dataset['code']); $listItemType->setDomain($dataset['domain']); $listItemType->setLabel($dataset['label']); $listItemType->setStatus($dataset['status']); $supplierListTypeManager->saveItem($listItemType); $listItemTypeIds[$key] = $listItemType->getId(); } $listItem = $supplierListManager->createItem(); foreach ($testdata['supplier/list'] as $dataset) { if (!isset($parentIds[$dataset['parentid']])) { throw new MW_Setup_Exception(sprintf('No supplier 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 supplier 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']); $supplierListManager->saveItem($listItem, false); } $this->_conn->commit(); }