/** * testCreate * * @return void * @access public * @see ____func_see____ * @since 1.0.0 */ public function testCreate() { $newMethod = new \XLite\Model\Shipping\Method(); $newMethod->setName('Test'); $newMethod->setProcessor('offline'); $newMethod->setCarrier('ups'); $newMethod->setEnabled(1); $newMethod->setPosition(888); \XLite\Core\Database::getEM()->persist($newMethod); \XLite\Core\Database::getEM()->flush(); $methodId = $newMethod->getMethodId(); $this->assertTrue(isset($methodId), 'Object could not be created'); if (isset($methodId)) { $method = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->find($methodId); $this->assertEquals('Test', $method->getName(), 'Wrong method name'); $this->assertEquals('offline', $method->getProcessor(), 'Wrong processor'); $this->assertEquals('ups', $method->getCarrier(), 'Wrong carrier'); $this->assertEquals(1, $method->getEnabled(), 'Wrong status'); $this->assertEquals(888, $method->getPosition(), 'Wrong position'); } }
/** * Add shipping method to the database * * @param array $postage Array of data for shipping method * * @return void */ protected function addShippingMethod($postage) { $method = null; // Check if method has alreaby been added in current session to prevent duplicates if (!in_array($postage['CLASSID'], $this->newMethods)) { $lastMethod = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->findOneMaxPositionByProcessor($this->getProcessorId()); $method = new \XLite\Model\Shipping\Method(); $method->setProcessor($this->getProcessorId()); $method->setCarrier($this->getProcessorId()); $method->setCode($postage['CLASSID']); $method->setEnabled(\XLite\Core\Config::getInstance()->CDev->USPS->autoenable_new_methods); $method->setName($postage['MailService']); if ($lastMethod) { $method->setPosition($lastMethod->getPosition() + 1); } \XLite\Core\Database::getEM()->persist($method); \XLite\Core\Database::getEM()->flush(); $this->newMethods[] = $postage['CLASSID']; } return $method; }