/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->editor = \TestHelper::getContext()->getEditor(); $manager = \Aimeos\MShop\Supplier\Manager\Factory::createManager(\TestHelper::getContext()); $listManager = $manager->getSubManager('lists'); $this->object = $listManager->getSubManager('type'); }
/** * Adds the supplier test data. * * @throws \Aimeos\MW\Setup\Exception If a required ID is not available */ private function addSupplierData() { $supplierManager = \Aimeos\MShop\Supplier\Manager\Factory::createManager($this->additional, 'Standard'); $supplierAddressManager = $supplierManager->getSubManager('address', 'Standard'); $ds = DIRECTORY_SEPARATOR; $path = __DIR__ . $ds . 'data' . $ds . 'supplier.php'; if (($testdata = (include $path)) == false) { throw new \Aimeos\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['parentid']])) { throw new \Aimeos\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->setLatitude($dataset['latitude']); $supAdr->setLongitude($dataset['longitude']); $supAdr->setParentId($supIds[$dataset['parentid']]); $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 = \Aimeos\MShop\Supplier\Manager\Factory::createManager(\TestHelper::getContext()); $this->object = $supplierManager->getSubManager('address'); }
protected function getListItems() { $manager = \Aimeos\MShop\Supplier\Manager\Factory::createManager($this->context, 'Standard'); $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.lists.parentid', $item->getId()), $search->compare('==', 'supplier.lists.domain', 'text'), $search->compare('==', 'supplier.lists.editor', $this->editor), $search->compare('==', 'supplier.lists.type.code', 'default')); $search->setConditions($search->combine('&&', $expr)); $search->setSortations(array($search->sort('+', 'supplier.lists.position'))); return $this->object->searchItems($search); }
/** * 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 \Aimeos\MW\Setup\Exception If a required ID is not available */ protected function addSupplierListData(array $testdata, array $refIds, $type = 'Standard') { $supplierManager = \Aimeos\MShop\Supplier\Manager\Factory::createManager($this->additional, $type); $supplierListManager = $supplierManager->getSubManager('lists', $type); $supplierListTypeManager = $supplierListManager->getSubmanager('type', $type); $itemCode = array(); foreach ($testdata['supplier/lists'] as $dataset) { if (($pos = strpos($dataset['parentid'], '/')) === false || ($str = substr($dataset['parentid'], $pos + 1)) === false) { throw new \Aimeos\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/lists/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/lists'] as $dataset) { if (!isset($parentIds[$dataset['parentid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No supplier ID found for "%1$s"', $dataset['parentid'])); } if (!isset($refIds[$dataset['domain']][$dataset['refid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No "%2$s" ref ID found for "%1$s"', $dataset['refid'], $dataset['domain'])); } if (!isset($listItemTypeIds[$dataset['typeid']])) { throw new \Aimeos\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(); }
public function testCreateManagerNotExisting() { $this->setExpectedException('\\Aimeos\\MShop\\Exception'); \Aimeos\MShop\Supplier\Manager\Factory::createManager(\TestHelperMShop::getContext(), 'unknown'); }