public function testExecute() { $this->objectManager->expects($this->once()) ->method('get') ->with('Magento\Framework\App\Cache') ->willReturn($this->cacheMock); $this->cacheMock->expects($this->once())->method('clean'); $writeDirectory = $this->getMock('Magento\Framework\Filesystem\Directory\WriteInterface'); $writeDirectory->expects($this->atLeastOnce())->method('delete'); $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory); $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true); $progressBar = $this->getMockBuilder( 'Symfony\Component\Console\Helper\ProgressBar' ) ->disableOriginalConstructor() ->getMock(); $this->objectManager->expects($this->once())->method('configure'); $this->objectManager ->expects($this->once()) ->method('create') ->with('Symfony\Component\Console\Helper\ProgressBar') ->willReturn($progressBar); $this->manager->expects($this->exactly(6))->method('addOperation'); $this->manager->expects($this->once())->method('process'); $tester = new CommandTester($this->command); $tester->execute([]); $this->assertContains( 'Generated code and dependency injection configuration successfully.', explode(PHP_EOL, $tester->getDisplay()) ); }
/** * {@inheritDoc} */ protected function setUp() { parent::setUp(); $this->dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Filter\Date') ->disableOriginalConstructor() ->getMock(); $this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data') ->disableOriginalConstructor() ->getMock(); $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') ->disableOriginalConstructor() ->getMock(); $this->objectManagerMock ->expects($this->any()) ->method('get') ->willReturn($this->helperMock); $this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->exportViewedCsv = $objectManager->getObject( 'Magento\Reports\Controller\Adminhtml\Report\Product\ExportViewedCsv', [ 'context' => $this->contextMock, 'fileFactory' => $this->fileFactoryMock, 'dateFilter' => $this->dateMock, ] ); }
/** * Get proxied instance * * @return \Magento\Framework\Stdlib\DateTime\DateTime */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = true === $this->_isShared ? $this->_objectManager->get($this->_instanceName) : $this->_objectManager->create($this->_instanceName); } return $this->_subject; }
/** * @covers \Magento\Setup\Controller\Session::testUnloginAction */ public function testUnloginAction() { $deployConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', ['isAvailable'], [], '', false); $deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); $stateMock = $this->getMock('Magento\Framework\App\State', ['setAreaCode'], [], '', false); $stateMock->expects($this->once())->method('setAreaCode'); $sessionConfigMock = $this->getMock('Magento\Backend\Model\Session\AdminConfig', ['setCookiePath'], [], '', false); $sessionConfigMock->expects($this->once())->method('setCookiePath'); $returnValueMap = [ ['Magento\Framework\App\DeploymentConfig', $deployConfigMock], ['Magento\Framework\App\State', $stateMock], ['Magento\Backend\Model\Session\AdminConfig', $sessionConfigMock] ]; $this->objectManager->expects($this->atLeastOnce()) ->method('get') ->will($this->returnValueMap($returnValueMap)); $sessionMock = $this->getMock('Magento\Backend\Model\Auth\Session', ['prolong'], [], '', false); $this->objectManager->expects($this->once()) ->method('create') ->will($this->returnValue($sessionMock)); $controller = new Session($this->objectManagerProvider); $controller->prolongAction(); }
/** * Processing section runtime errors * * @return void */ protected function exceptionResponse() { $dataMock = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', ['jsonEncode'], [], '', false); $this->objectManagerMock->expects($this->once())->method('get')->will($this->returnValue($dataMock)); $dataMock->expects($this->once())->method('jsonEncode')->will($this->returnValue('{json-data}')); $this->responseMock->expects($this->once())->method('representJson')->with('{json-data}'); }
/** * Set up */ public function setUp() { $this->objectManager = Bootstrap::getObjectManager(); $this->accountManagement = $this->objectManager->create('Magento\\Customer\\Api\\AccountManagementInterface'); $this->securityManager = $this->objectManager->create('Magento\\Security\\Model\\SecurityManager'); $this->passwordResetRequestEvent = $this->objectManager->get('Magento\\Security\\Model\\PasswordResetRequestEvent'); }
/** * Create link builder instance * * @param string $instance * @param array $arguments * @return CopyConstructorInterface * @throws \InvalidArgumentException */ public function create($instance, array $arguments = []) { 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); }
protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->groupRepository = $this->objectManager->create('Magento\\Customer\\Api\\GroupRepositoryInterface'); $this->groupFactory = $this->objectManager->create('Magento\\Customer\\Api\\Data\\GroupInterfaceFactory'); $this->searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder'); }
public function testCreate() { $this->objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager); $this->objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\Module\\Status'); $this->moduleStatusFactory = new ModuleStatusFactory($this->objectManagerProvider); $this->moduleStatusFactory->create(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { /* parse arguments */ $argIds = $input->getArgument(static::ARG_IDS); if (is_null($argIds)) { $ids = null; $output->writeln('<info>List of all products will be pulled from Odoo.<info>'); } else { $ids = explode(',', $argIds); $output->writeln("<info>Products with Odoo IDs ({$argIds}) will be pulled from Odoo.<info>"); } /* setup session */ $this->_setAreaCode(); /* call service operation */ /** @var ProductsFromOdooRequest $req */ $req = $this->_manObj->create(ProductsFromOdooRequest::class); $req->setOdooIds($ids); /** @var ProductsFromOdooResponse $resp */ $resp = $this->_callReplicate->productsFromOdoo($req); if ($resp->isSucceed()) { $output->writeln('<info>Replication is done.<info>'); } else { $output->writeln('<info>Replication is failed.<info>'); } }
/** * @param string $requestName * @return AbstractCollection * @throws \Exception */ public function getReport($requestName) { if (!isset($this->collections[$requestName])) { throw new \Exception(sprintf('Not registered handle %s', $requestName)); } return $this->objectManager->create($this->collections[$requestName]); }
/** * Retrieve subject * * @return \Magento\Config\Model\Config\Structure\SearchInterface */ protected function _getSubject() { if (!$this->_subject) { $this->_subject = $this->_objectManager->get('Magento\\Config\\Model\\Config\\Structure'); } return $this->_subject; }
/** * @return \Magento\Framework\View\Result\Layout */ public function create() { /** @var \Magento\Framework\View\Result\Layout $resultLayout */ $resultLayout = $this->objectManager->create($this->instanceName); $resultLayout->addDefaultHandle(); return $resultLayout; }
/** * Retrieve indexer instance by id * * @param string $indexerId * @return IndexerInterface */ public function get($indexerId) { if (!isset($this->indexers[$indexerId])) { $this->indexers[$indexerId] = $this->objectManager->create('Magento\\Indexer\\Model\\IndexerInterface')->load($indexerId); } return $this->indexers[$indexerId]; }
protected function getConfigurableAttributeOptions() { /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $optionCollection */ $optionCollection = $this->objectManager->create('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Option\\Collection'); $options = $optionCollection->setAttributeFilter($this->configurableAttribute->getId())->getData(); return $options; }
/** * Replace {{skin url=""}} with {{view url=""}} for given table field * * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param string $table * @param string $col * @return void */ function updateFieldForTable($objectManager, $table, $col) { /** @var $installer \Magento\Framework\Setup\ModuleDataSetupInterface */ $installer = $objectManager->create('\\Magento\\Framework\\Setup\\ModuleDataSetupInterface'); $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, ['id' => $pkField, 'content' => $col]); $result = $installer->getConnection()->fetchPairs($select); echo 'Records count: ' . count($result) . ' in table: `' . $table . "`\n"; $logMessages = []; foreach ($result as $recordId => $string) { $content = str_replace('{{skin', '{{view', $string, $count); if ($count) { $installer->getConnection()->update($table, [$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"; }
public function testCreate() { $actionInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\Indexer\\ActionInterface', [], '', false); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Indexer\\ActionInterface', [])->willReturn($actionInterfaceMock); $this->model->create('Magento\\Framework\\Indexer\\ActionInterface'); $this->assertInstanceOf('Magento\\Framework\\Indexer\\ActionInterface', $actionInterfaceMock); }
/** * Tests list of order transactions * @dataProvider filtersDataProvider */ public function testTransactionList($filters) { /** @var Order $order */ $order = $this->objectManager->create('Magento\\Sales\\Model\\Order'); /** * @var $transactionRepository \Magento\Sales\Model\Order\Payment\Transaction\Repository */ $transactionRepository = 'Magento\\Sales\\Model\\Order\\Payment\\Transaction\\Repository'; $transactionRepository = $this->objectManager->create($transactionRepository); $order->loadByIncrementId('100000006'); /** @var Payment $payment */ $payment = $order->getPayment(); /** @var Transaction $transaction */ $transaction = $transactionRepository->getByTransactionId('trx_auth', $payment->getId(), $order->getId()); $childTransactions = $transaction->getChildTransactions(); $childTransaction = reset($childTransactions); /** @var $searchCriteriaBuilder \Magento\Framework\Api\SearchCriteriaBuilder */ $searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder'); $searchCriteriaBuilder->addFilters($filters); $searchData = $searchCriteriaBuilder->create()->__toArray(); $requestData = ['searchCriteria' => $searchData]; $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_READ_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_READ_NAME . 'getList']]; $result = $this->_webApiCall($serviceInfo, $requestData); $this->assertArrayHasKey('items', $result); $transactionData = $this->getPreparedTransactionData($transaction); $childTransactionData = $this->getPreparedTransactionData($childTransaction); $transactionData['child_transactions'][] = $childTransactionData; $expectedData = [$transactionData, $childTransactionData]; $this->assertEquals($expectedData, $result['items']); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage WrongClass class doesn't implement \Magento\Payment\Model\MethodInterface */ public function testWrongTypeException() { $className = 'WrongClass'; $methodMock = $this->getMock($className, [], [], '', false); $this->_objectManagerMock->expects($this->once())->method('create')->with($className, [])->will($this->returnValue($methodMock)); $this->_factory->create($className); }
/** * @magentoApiDataFixture Magento/Sales/_files/shipment.php */ public function testShipmentGet() { /** @var \Magento\Sales\Model\Order\Shipment $shipment */ $shipmentCollection = $this->objectManager->get('Magento\\Sales\\Model\\ResourceModel\\Order\\Shipment\\Collection'); $shipment = $shipmentCollection->getFirstItem(); $shipment->load($shipment->getId()); $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $shipment->getId(), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_READ_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_READ_NAME . 'get']]; $result = $this->_webApiCall($serviceInfo, ['id' => $shipment->getId()]); $data = $result; $this->assertArrayHasKey('items', $result); $this->assertArrayHasKey('tracks', $result); unset($data['items']); unset($data['packages']); unset($data['tracks']); foreach ($data as $key => $value) { if (!empty($value)) { $this->assertEquals($shipment->getData($key), $value, $key); } } $shipmentItem = $this->objectManager->get('Magento\\Sales\\Model\\Order\\Shipment\\Item'); foreach ($result['items'] as $item) { $shipmentItem->load($item['entity_id']); foreach ($item as $key => $value) { $this->assertEquals($shipmentItem->getData($key), $value, $key); } } $shipmentTrack = $this->objectManager->get('Magento\\Sales\\Model\\Order\\Shipment\\Track'); foreach ($result['tracks'] as $item) { $shipmentTrack->load($item['entity_id']); foreach ($item as $key => $value) { $this->assertEquals($shipmentTrack->getData($key), $value, $key); } } }
/** * Creates operation * * @param string $operationAlias * @param mixed $arguments * @return OperationInterface * @throws OperationException */ public function create($operationAlias, $arguments = null) { if (!array_key_exists($operationAlias, $this->operationsDefinitions)) { throw new OperationException(sprintf('Unrecognized operation "%s"', $operationAlias), OperationException::UNAVAILABLE_OPERATION); } return $this->objectManager->create($this->operationsDefinitions[$operationAlias], ['data' => $arguments]); }
public function setUp() { $directoryList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem\\DirectoryList', ['root' => DirectoryList::ROOT]); $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem', ['directoryList' => $directoryList]); $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_model = $this->_objectManager->create('Magento\\Persistent\\Model\\Persistent\\Config', ['filesystem' => $filesystem]); }
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')); }
/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { $thumbDirtmp = str_replace($this->_imageprocessor->getSliderMediaPath(), $this->_imageprocessor->getSliderMediaPath('thumb'), $row->getSliderImagePath()); return '<span class="grid-row-title"> <img src="' . $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $thumbDirtmp . '" > </span>'; }
/** * Get datetime * * @return \Magento\Framework\Stdlib\DateTime\DateTime */ private function getDateTime() { if ($this->dateTime === null) { $this->dateTime = $this->objectManager->get('Magento\\Setup\\Model\\DateTime\\DateTimeProvider')->get(); } return $this->dateTime; }
public function testGet() { $actionInterfaceMock = $this->getMockForAbstractClass('Magento\\Indexer\\Model\\ActionInterface', [], '', false); $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Indexer\\Model\\ActionInterface')->will($this->returnValue($actionInterfaceMock)); $this->model->get('Magento\\Indexer\\Model\\ActionInterface'); $this->assertInstanceOf('Magento\\Indexer\\Model\\ActionInterface', $actionInterfaceMock); }
/** * @param string $className * @return \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter * @throws \InvalidArgumentException */ public function create($className) { if (!$className) { throw new \InvalidArgumentException('Incorrect class name'); } return $this->_objectManager->create($className); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { try { /** @var \Magento\Deploy\Model\Mode $modeController */ $modeController = $this->objectManager->create('Magento\\Deploy\\Model\\Mode', ['input' => $input, 'output' => $output]); $toMode = $input->getArgument(self::MODE_ARGUMENT); $skipCompilation = $input->getOption(self::SKIP_COMPILATION_OPTION); switch ($toMode) { case State::MODE_DEVELOPER: $modeController->enableDeveloperMode(); break; case State::MODE_PRODUCTION: if ($skipCompilation) { $modeController->enableProductionModeMinimal(); } else { $modeController->enableProductionMode(); } break; default: throw new LocalizedException(__('Cannot switch into given mode "%1"', $toMode)); } $output->writeln('Enabled ' . $toMode . ' mode.'); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln($e->getTraceAsString()); } return; } }
/** * @magentoAppArea adminhtml * @magentoDbIsolation enabled * @magentoAppIsolation enabled */ public function testBundleImport() { // import data from CSV file $pathToFile = __DIR__ . '/../../_files/import_bundle.csv'; $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class); $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]); $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData(); $this->assertTrue($errors->getErrorsCount() == 0); $this->model->importData(); $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class); $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME); $this->assertTrue(is_numeric($productId)); /** @var \Magento\Catalog\Model\Product $product */ $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class); $product->load($productId); $this->assertFalse($product->isObjectNew()); $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName()); $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId()); $this->assertEquals(1, $product->getShipmentType()); $optionIdList = $resource->getProductsIdsBySkus($this->optionSkuList); $bundleOptionCollection = $product->getExtensionAttributes()->getBundleProductOptions(); $this->assertEquals(2, count($bundleOptionCollection)); foreach ($bundleOptionCollection as $optionKey => $option) { $this->assertEquals('checkbox', $option->getData('type')); $this->assertEquals('Option ' . ($optionKey + 1), $option->getData('title')); $this->assertEquals(self::TEST_PRODUCT_NAME, $option->getData('sku')); $this->assertEquals($optionKey + 1, count($option->getData('product_links'))); foreach ($option->getData('product_links') as $linkKey => $productLink) { $optionSku = 'Simple ' . ($optionKey + 1 + $linkKey); $this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id')); $this->assertEquals($optionSku, $productLink->getData('sku')); } } }
/** * Get applied to layer filter items * * @return Item[] */ public function getFilters() { try { if ($this->bxHelperData->isFilterLayoutEnabled($this->_layer)) { $category = $this->_categoryViewBlock->getCurrentCategory(); if ($category != null && $category->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PAGE) { return parent::getFilters(); } $filters = array(); $facets = $this->p13nHelper->getFacets(); if ($facets) { foreach ($this->bxHelperData->getAllFacetFieldNames() as $fieldName) { if ($facets->isSelected($fieldName)) { $filter = $this->objectManager->create("Boxalino\\Intelligence\\Model\\LayerFilterItem"); $filter->setFacets($facets); $filter->setFieldName($fieldName); $filters[] = $filter; } } } return $filters; } return parent::getFilters(); } catch (\Exception $e) { $this->bxHelperData->setFallback(true); $this->_logger->critical($e); return parent::getFilters(); } }