/** * Retrieve router instance by id * * @param string $routerId * @return RouterInterface */ protected function getRouterInstance($routerId) { if (!isset($this->routerList[$routerId]['object'])) { $this->routerList[$routerId]['object'] = $this->objectManager->create($this->routerList[$routerId]['class']); } return $this->routerList[$routerId]['object']; }
public function testGetGridParentHtml() { $this->_block = $this->_objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Cart', '', array()); $mockCollection = $this->getMockBuilder('\\Magento\\Framework\\Data\\Collection')->disableOriginalConstructor()->getMock(); $this->_block->setCollection($mockCollection); $this->assertContains("<div class=\"grid-actions\">", $this->_block->getGridParentHtml()); }
/** * @covers \Magento\Framework\App\RequestFactory::__construct * @covers \Magento\Framework\App\RequestFactory::create */ public function testCreate() { $arguments = ['some_key' => 'same_value']; $appRequest = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\App\\RequestInterface', $arguments)->will($this->returnValue($appRequest)); $this->assertEquals($appRequest, $this->model->create($arguments)); }
public function testCreateCheckout() { $checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods([])->getMock(); $instance = $this->getMockBuilder('Magento\\Paypal\\Helper\\Shortcut\\ValidatorInterface')->getMock(); $this->objectManagerMock->expects($this->once())->method('create')->with(Factory::CHECKOUT_VALIDATOR)->will($this->returnValue($instance)); $this->assertInstanceOf('Magento\\Paypal\\Helper\\Shortcut\\ValidatorInterface', $this->factory->create($checkoutMock)); }
protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->builder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetailsBuilder'); $this->itemBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetails\\ItemBuilder'); $this->addressBuilder = $this->objectManager->create('\\Magento\\Customer\\Service\\V1\\Data\\AddressBuilder'); }
/** * Modify price * * @param mixed $price * @param Product $product * @return mixed */ public function modifyPrice($price, Product $product) { foreach ($this->modifiers as $modifierClass) { $price = $this->objectManager->get($modifierClass)->modifyPrice($price, $product); } return $price; }
public function testCreate() { $type = '1'; $data = ['data2', 'data3']; $this->objectManagerMock->expects($this->once())->method('create')->with($type, $data); $this->conditionFactory->create($type, $data); }
protected function setUp() { $this->_session = $this->getMock('Magento\\Customer\\Model\\Session', array(), array(), '', false); $this->_agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', array('load', 'getId', 'getCustomerId', 'getReferenceId', 'canCancel', 'cancel', '__wakeup'), array(), '', false); $this->_agreement->expects($this->once())->method('load')->with(15)->will($this->returnSelf()); $this->_agreement->expects($this->once())->method('getId')->will($this->returnValue(15)); $this->_agreement->expects($this->once())->method('getCustomerId')->will($this->returnValue(871)); $this->_objectManager = $this->getMock('Magento\\Framework\\ObjectManager'); $this->_objectManager->expects($this->atLeastOnce())->method('get')->will($this->returnValueMap(array(array('Magento\\Customer\\Model\\Session', $this->_session)))); $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Paypal\\Model\\Billing\\Agreement')->will($this->returnValue($this->_agreement)); $this->_request = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->_request->expects($this->once())->method('getParam')->with('agreement')->will($this->returnValue(15)); $response = $this->getMock('Magento\\Framework\\App\\ResponseInterface'); $redirect = $this->getMock('Magento\\Framework\\App\\Response\\RedirectInterface'); $this->_messageManager = $this->getMock('Magento\\Framework\\Message\\ManagerInterface'); $context = $this->getMock('Magento\\Framework\\App\\Action\\Context', array(), array(), '', false); $context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->_objectManager)); $context->expects($this->any())->method('getRequest')->will($this->returnValue($this->_request)); $context->expects($this->any())->method('getResponse')->will($this->returnValue($response)); $context->expects($this->any())->method('getRedirect')->will($this->returnValue($redirect)); $context->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->_messageManager)); $this->_registry = $this->getMock('Magento\\Framework\\Registry', array(), array(), '', false); $title = $this->getMock('Magento\\Framework\\App\\Action\\Title', array(), array(), '', false); $this->_controller = new Cancel($context, $this->_registry, $title); }
/** * Create link builder instance * * @param string $instance * @param array $arguments * @return CopyConstructorInterface * @throws \InvalidArgumentException */ public function create($instance, array $arguments = array()) { if (!is_subclass_of($instance, '\\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface')) { throw new \InvalidArgumentException($instance . ' does not implement \\Magento\\Catalog\\Model\\Product\\CopyConstructorInterface'); } return $this->objectManager->create($instance, $arguments); }
/** * Create cache model * * @return CacheInterface */ protected function _getCache() { if (null == $this->_cache) { $this->_cache = $this->_objectManager->get('Magento\\Framework\\App\\Cache'); } return $this->_cache; }
/** * Create state object * * @param string $cardType * @return \Magento\Centinel\Model\AbstractState|false */ public function createState($cardType) { if (!isset($this->_stateClassMap[$cardType])) { return false; } return $this->_objectManager->create($this->_stateClassMap[$cardType]); }
protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->builder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\TaxRuleSearchResultsBuilder'); $this->searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Service\\V1\\Data\\SearchCriteriaBuilder'); $this->taxRuleBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\TaxRuleBuilder'); }
public function testGet() { $actionInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\ActionInterface', array(), '', false); $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Mview\\ActionInterface')->will($this->returnValue($actionInterfaceMock)); $this->model->get('Magento\\Framework\\Mview\\ActionInterface'); $this->assertInstanceOf('Magento\\Framework\\Mview\\ActionInterface', $actionInterfaceMock); }
/** * Create new calculator * * @param string $type Type of calculator * @param int $storeId * @param Address $billingAddress * @param Address $shippingAddress * @param null|int $customerTaxClassId * @param null|int $customerId * @return \Magento\Tax\Model\Calculation\AbstractCalculator * @throws \InvalidArgumentException */ public function create($type, $storeId, Address $billingAddress = null, Address $shippingAddress = null, $customerTaxClassId = null, $customerId = null) { switch ($type) { case self::CALC_UNIT_BASE: $className = 'Magento\\Tax\\Model\\Calculation\\UnitBaseCalculator'; break; case self::CALC_ROW_BASE: $className = 'Magento\\Tax\\Model\\Calculation\\RowBaseCalculator'; break; case self::CALC_TOTAL_BASE: $className = 'Magento\\Tax\\Model\\Calculation\\TotalBaseCalculator'; break; default: throw new \InvalidArgumentException('Unknown calculation type: ' . $type); } /** @var \Magento\Tax\Model\Calculation\AbstractCalculator $calculator */ $calculator = $this->objectManager->create($className, ['storeId' => $storeId]); if (null != $shippingAddress) { $calculator->setShippingAddress($shippingAddress); } if (null != $billingAddress) { $calculator->setBillingAddress($billingAddress); } if (null != $customerTaxClassId) { $calculator->setCustomerTaxClassId($customerTaxClassId); } if (null != $customerId) { $calculator->setCustomerId($customerId); } return $calculator; }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Specification must implement SpecificationInterface */ public function testWrongTypeException() { $className = 'WrongClass'; $methodMock = $this->getMock($className); $this->objectManagerMock->expects($this->once())->method('get')->with($className)->will($this->returnValue($methodMock)); $this->factory->create($className); }
/** * Replace {{skin url=""}} with {{view url=""}} for given table field * * @param \Magento\Framework\ObjectManager $objectManager * @param string $table * @param string $col * @return void */ function updateFieldForTable($objectManager, $table, $col) { /** @var $installer \Magento\Framework\Module\Setup */ $installer = $objectManager->create('Magento\\Framework\\Module\\Setup'); $installer->startSetup(); $table = $installer->getTable($table); echo '-----' . "\n"; if ($installer->getConnection()->isTableExists($table)) { echo 'Table `' . $table . "` processed\n"; $indexList = $installer->getConnection()->getIndexList($table); $pkField = array_shift($indexList[$installer->getConnection()->getPrimaryKeyName($table)]['fields']); /** @var $select \Magento\Framework\DB\Select */ $select = $installer->getConnection()->select()->from($table, array('id' => $pkField, 'content' => $col)); $result = $installer->getConnection()->fetchPairs($select); echo 'Records count: ' . count($result) . ' in table: `' . $table . "`\n"; $logMessages = array(); foreach ($result as $recordId => $string) { $content = str_replace('{{skin', '{{view', $string, $count); if ($count) { $installer->getConnection()->update($table, array($col => $content), $installer->getConnection()->quoteInto($pkField . '=?', $recordId)); $logMessages['replaced'][] = 'Replaced -- Id: ' . $recordId . ' in table `' . $table . '`'; } else { $logMessages['skipped'][] = 'Skipped -- Id: ' . $recordId . ' in table `' . $table . '`'; } } if (count($result)) { printLog($logMessages); } } else { echo 'Table `' . $table . "` was not found\n"; } $installer->endSetup(); echo '-----' . "\n"; }
protected function setUp() { $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_builder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\CustomerDetailsBuilder'); $this->_customerBuilder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder'); $this->_addressBuilder = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder'); }
/** * @param array $data * @dataProvider createTaxRateModelDataProvider */ public function testCreateTaxRateModel($data) { $taxRateDataObjectBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\TaxRateBuilder'); $zipRangeDataObjectBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\ZipRangeBuilder'); /** @var $converter \Magento\Tax\Model\Calculation\Rate\Converter */ $converter = $this->objectManager->create('Magento\\Tax\\Model\\Calculation\\Rate\\Converter', ['taxRateDataObjectBuilder' => $taxRateDataObjectBuilder, 'zipRangeDataObjectBuilder' => $zipRangeDataObjectBuilder]); $taxRateDataObject = $taxRateDataObjectBuilder->populateWithArray($data)->create(); $taxRateModel = $converter->createTaxRateModel($taxRateDataObject); //Assertion $this->assertEquals($taxRateDataObject->getId(), $taxRateModel->getId()); $this->assertEquals($taxRateDataObject->getCountryId(), $taxRateModel->getTaxCountryId()); $this->assertEquals($taxRateDataObject->getRegionId(), $taxRateModel->getTaxRegionId()); $this->assertEquals($taxRateDataObject->getPostcode(), $taxRateModel->getTaxPostcode()); $this->assertEquals($taxRateDataObject->getcode(), $taxRateModel->getCode()); $this->assertEquals($taxRateDataObject->getPercentageRate(), $taxRateModel->getRate()); if ($taxRateDataObject->getZipRange()) { if ($taxRateDataObject->getZipRange()->getFrom()) { $this->assertEquals($taxRateDataObject->getZipRange()->getFrom(), $taxRateModel->getZipFrom()); } else { $this->assertNull($taxRateModel->getZipFrom()); } if ($taxRateDataObject->getZipRange()->getTo()) { $this->assertEquals($taxRateDataObject->getZipRange()->getTo(), $taxRateModel->getZipTo()); } else { $this->assertNull($taxRateModel->getTo()); } } else { $this->assertNull($taxRateModel->getZipFrom()); $this->assertNull($taxRateModel->getZipTo()); } }
/** * @expectedException \Magento\Framework\Model\Exception * @expectedExceptionMessage WrongClass doesn't extends \Magento\Framework\Filter\Template */ public function testWrongTypeException() { $className = 'WrongClass'; $filterMock = $this->getMock($className, array(), array(), '', false); $this->_objectManagerMock->expects($this->once())->method('create')->will($this->returnValue($filterMock)); $this->_factory->create($className); }
/** * Retrieve subject * * @return \Magento\Backend\Model\Config\Structure\Element\Group */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = $this->_objectManager->create('Magento\\Backend\\Model\\Config\\Structure\\Element\\Group'); } return $this->_subject; }
/** * Run application * * @param string $applicationName * @param array $arguments * @return void */ public function run($applicationName, array $arguments = array()) { try { \Magento\Framework\Profiler::start('magento'); if (!$this->_locator) { $locatorFactory = new \Magento\Framework\App\ObjectManagerFactory(); $this->_locator = $locatorFactory->create($this->_rootDir, $this->_parameters); } $application = $this->_locator->create($applicationName, $arguments); $response = $application->launch(); \Magento\Framework\Profiler::stop('magento'); $response->sendResponse(); } catch (\Exception $exception) { if (isset($this->_parameters[State::PARAM_MODE]) && $this->_parameters[State::PARAM_MODE] == State::MODE_DEVELOPER) { echo $exception->getMessage() . "\n\n"; echo $exception->getTraceAsString(); } else { $message = "Error happened during application run.\n"; try { if (!$this->_locator) { throw new \DomainException(); } $this->_locator->get('Magento\\Framework\\Logger')->logException($exception); } catch (\Exception $e) { $message .= "Could not write error message to log. Please use developer mode to see the message.\n"; } echo $message; } } }
/** * Get Installer Db type instance * * @param string $type * @return \Magento\Install\Model\Installer\Db\AbstractDb | bool * @throws \InvalidArgumentException */ public function get($type) { if (!empty($type) && isset($this->_types[(string) $type])) { return $this->_objectManager->get($this->_types[(string) $type]); } return false; }
/** * @param string $className * @return \Magento\ImportExport\Model\Export\Entity\AbstractEntity|\Magento\ImportExport\Model\Export\AbstractEntity * @throws \InvalidArgumentException */ public function create($className) { if (!$className) { throw new \InvalidArgumentException('Incorrect class name'); } return $this->_objectManager->create($className); }
public function testGetNonShared() { $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Mview\\Config\\Data')->will($this->returnValue($this->dataMock)); $this->dataMock->expects($this->once())->method('get')->with('some_path', 'default')->will($this->returnValue('some_value')); $this->model = new Proxy($this->objectManagerMock, 'Magento\\Framework\\Mview\\Config\\Data', false); $this->assertEquals('some_value', $this->model->get('some_path', 'default')); }
public function __wakeup() { $this->pluginLocator = \Magento\Framework\App\ObjectManager::getInstance(); $this->pluginList = $this->pluginLocator->get('Magento\\Framework\\Interception\\PluginList'); $this->chain = $this->pluginLocator->get('Magento\\Framework\\Interception\\Chain'); $this->subjectType = get_parent_class($this); }
public function setUp() { $directoryList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem\\DirectoryList', array('root' => \Magento\Framework\App\Filesystem::ROOT_DIR, 'directories' => array(\Magento\Framework\App\Filesystem::MODULES_DIR => array('path' => dirname(__DIR__))))); $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem', array('directoryList' => $directoryList)); $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_model = $this->_objectManager->create('Magento\\Persistent\\Model\\Persistent\\Config', array('filesystem' => $filesystem)); }
/** * @param string $indexerInstanceName * @return \Magento\Index\Model\Indexer\AbstractIndexer|null */ public function create($indexerInstanceName) { if ($indexerInstanceName) { return $this->_objectManager->create($indexerInstanceName); } return null; }
protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->appliedTaxBuilder = $this->objectManager->create('\\Magento\\Tax\\Service\\V1\\Data\\TaxDetails\\AppliedTaxBuilder'); $this->taxDetailsItemBuilder = $this->objectManager->create('\\Magento\\Tax\\Service\\V1\\Data\\TaxDetails\\ItemBuilder'); $this->taxDetailsBuilder = $this->objectManager->create('\\Magento\\Tax\\Service\\V1\\Data\\TaxDetailsBuilder'); }
/** * @param mixed $class * @param array $arguments * @param string $expectedClassName * @dataProvider createDataProvider */ public function testCreate($class, $arguments, $expectedClassName) { $createdModel = $this->getMock('Magento\\Sales\\Model\\Order\\Pdf\\Total\\DefaultTotal', array(), array(), (string) $class, false); $this->_objectManager->expects($this->once())->method('create')->with($expectedClassName, $arguments)->will($this->returnValue($createdModel)); $actual = $this->_factory->create($class, $arguments); $this->assertSame($createdModel, $actual); }
/** * Retrieve subject * * @return \Magento\Backend\Model\Config\Structure\SearchInterface */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = $this->_objectManager->get('Magento\\Backend\\Model\\Config\\Structure'); } return $this->_subject; }