protected function setUp() { $this->context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false, false); $this->orderCollectionFactory = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->orderCollectionFactoryInterface = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class, [], [], '', false); $this->objectManager->expects($this->any())->method('get')->will($this->returnValue($this->orderCollectionFactoryInterface)); \Magento\Framework\App\ObjectManager::setInstance($this->objectManager); $this->customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->setMethods(['getCustomerId'])->disableOriginalConstructor()->getMock(); $this->orderConfig = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Config')->setMethods(['getVisibleOnFrontStatuses'])->disableOriginalConstructor()->getMock(); $this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock(); }
public function testExecute() { $mutableConfig = $this->getMock('Magento\\Framework\\App\\Config\\MutableScopeConfigInterface', [], [], '', false); $logFactory = $this->getMockBuilder('Magento\\Log\\Model\\LogFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $returnValueMap = [['Magento\\Framework\\App\\Config\\MutableScopeConfigInterface', [], $mutableConfig], ['Magento\\Log\\Model\\LogFactory', [], $logFactory]]; $this->objectManager->expects($this->exactly(2))->method('create')->will($this->returnValueMap($returnValueMap)); $mutableConfig->expects($this->once())->method('setValue'); $log = $this->getMock('Magento\\Log\\Model\\Log', [], [], '', false); $logFactory->expects($this->once())->method('create')->willReturn($log); $log->expects($this->once())->method('clean'); $this->commandTester->execute(['--days' => '1']); $this->assertEquals('Log cleaned.' . PHP_EOL, $this->commandTester->getDisplay()); }
/** * Get Data Persistor * * @return DataPersistorInterface */ private function getDataPersistor() { if ($this->dataPersistor === null) { $this->dataPersistor = ObjectManager::getInstance()->get(DataPersistorInterface::class); } return $this->dataPersistor; }
/** * @return Option\Repository */ private function getOptionRepository() { if (null === $this->optionRepository) { $this->optionRepository = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Catalog\\Model\\Product\\Option\\Repository'); } return $this->optionRepository; }
/** * @return AnchorUrlRewriteGenerator * * @deprecated */ private function getAnchorUrlRewriteGenerator() { if ($this->anchorUrlRewriteGenerator === null) { $this->anchorUrlRewriteGenerator = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\CatalogUrlRewrite\\Model\\Product\\AnchorUrlRewriteGenerator'); } return $this->anchorUrlRewriteGenerator; }
protected function _construct() { if ($this->checkConfig()) { $page = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Framework\\View\\Page\\Config'); $page->addPageAsset('Mageplaza_Blog::css/index/mp.css'); } }
public function execute() { $result = $this->resultJsonFactory->create(); $data = array(); try { $params = $this->getRequest()->getParams(); if (isset($params['lastid']) && isset($params['limit'])) { $lastId = $params['lastid']; $limit = $params['limit']; $isadmin = isset($params['isadmin']) ? $params['isadmin'] : false; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $raaDataHelper = $objectManager->create('Retail\\Analytics\\Helper\\Data'); $width = $raaDataHelper->getImageWidth(); $height = $raaDataHelper->getImageHeight(); $imagetype = "small_image"; if (isset($params['width']) && $params['width'] != null && $params['width'] != "") { $width = $params['width']; } if (isset($params['height']) && $params['height'] != null && $params['height'] != "") { $height = $params['height']; } if (isset($params['imagetype']) && $params['imagetype'] != null && $params['imagetype'] != "") { $imagetype = $params['imagetype']; } $producCollection = new \Retail\Analytics\Model\Product(); $data = $producCollection->getProductFinalPrice($lastId, $limit, $imagetype, $width, $height, $isadmin); return $result->setData($data); } } catch (Exception $e) { return $result->setData($data); } }
/** * {@inheritdoc} */ public function __wakeup() { parent::__wakeup(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $this->_resource = $objectManager->get('Magento\\Authorization\\Model\\ResourceModel\\Role'); $this->_resourceCollection = $objectManager->get('Magento\\Authorization\\Model\\ResourceModel\\Role\\Collection'); }
/** * Get HttpClientFactory dependency * * @return \Magento\Framework\HTTP\ZendClientFactory * * @deprecated */ private function getHttpClientFactory() { if ($this->httpClientFactory === null) { $this->httpClientFactory = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Framework\\HTTP\\ZendClientFactory'); } return $this->httpClientFactory; }
public function createTestimonialAction() { $data = $this->getRequest()->getPost(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $testimonial = $objectManager->get('V3N0m21\\Testimonials\\Model\\Testimonial'); $testimonial->setId(); }
public function testNewsletterAction() { $subscriberMock = $this->getMock('\\Magento\\Newsletter\\Model\\Subscriber', array(), array(), '', false); $subscriberMock->expects($this->once())->method('loadByCustomerId'); $this->_objectManager->expects($this->at(1))->method('create')->with('Magento\\Newsletter\\Model\\Subscriber')->will($this->returnValue($subscriberMock)); $this->_testedObject->execute(); }
/** * Tests that the session handler is correctly set when object is created. * * @dataProvider saveHandlerProvider * @param string $deploymentConfigHandler * @param string $iniHandler */ public function testSetSaveHandler($deploymentConfigHandler, $iniHandler) { // Set expected session.save_handler config if ($deploymentConfigHandler) { if ($deploymentConfigHandler !== 'files') { $expected = 'user'; } else { $expected = $deploymentConfigHandler; } } else { if ($iniHandler) { $expected = $iniHandler; } else { $expected = SaveHandlerInterface::DEFAULT_HANDLER; } } // Set ini configuration if ($iniHandler) { ini_set('session.save_handler', $iniHandler); } /** @var DeploymentConfig | \PHPUnit_Framework_MockObject_MockObject $deploymentConfigMock */ $deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)->disableOriginalConstructor()->getMock(); $deploymentConfigMock->expects($this->once())->method('get')->with(Config::PARAM_SESSION_SAVE_METHOD, SaveHandlerInterface::DEFAULT_HANDLER)->willReturn($deploymentConfigHandler ?: SaveHandlerInterface::DEFAULT_HANDLER); new SaveHandler(ObjectManager::getInstance()->get(SaveHandlerFactory::class), $deploymentConfigMock); // Test expectation $this->assertEquals($expected, ObjectManager::getInstance()->get(ConfigInterface::class)->getOption('session.save_handler')); }
/** * Prepare form fields * * @return \Magento\Backend\Block\Widget\Form */ protected function _prepareForm() { $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('manufacturer_'); $form->setFieldNameSuffix('manufacturer'); $model = $this->_coreRegistry->registry('manufacturer_manufacturer'); $om = \Magento\Framework\App\ObjectManager::getInstance(); $reader = $om->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'manufacturer'); $attributeOptions = $reader->getSource()->getAllOptions(true, true); $default = array('value' => '', 'label' => 'Choose Brand'); $i = 0; $manufacturer[$i] = $default; foreach ($attributeOptions as $key => $value) { $i++; if ($key != 0) { $manufacturer[$i] = $value; //$name[$i] = $value['label']; } } $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('General')]); if ($model->getId()) { $fieldset->addField('id', 'hidden', ['name' => 'id']); } $fieldset->addField('mfc_id', 'select', ['name' => 'mfc_id', 'label' => __('Manufacturer'), 'required' => true, 'values' => $manufacturer]); $fieldset->addField('status', 'select', ['name' => 'status', 'label' => __('Status'), 'options' => $this->_manufacturerStatus->toOptionArray()]); $fieldset->addField('position', 'textarea', ['name' => 'position', 'label' => __('Position'), 'required' => true, 'style' => 'height: 15em; width: 30em;']); $fieldset->addField('image_path', 'image', array('name' => 'image_path', 'label' => __('Image'), 'title' => __('Image'))); $wysiwygConfig = $this->_wysiwygConfig->getConfig(); $fieldset->addField('description', 'editor', ['name' => 'description', 'label' => __('Description'), 'required' => true, 'config' => $wysiwygConfig]); $data = $model->getData(); $form->setValues($data); $this->setForm($form); return parent::_prepareForm(); }
/** * Get image uploader * * @return \Magento\Catalog\Model\ImageUploader * * @deprecated */ private function getImageUploader() { if ($this->imageUploader === null) { $this->imageUploader = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Catalog\\CategoryImageUpload'); } return $this->imageUploader; }
public function getItmeProductThumbnailUrl() { $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $thumbnailHelper = $objectManager->get('Magento\\Catalog\\Helper\\Image'); $thumbnail = $thumbnailHelper->init($this->getItmeProduct(), 'thumbnail')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($this->getItmeProduct()->getImage())->resize('160', '160')->getUrl(); return $thumbnail; }
/** * The getter function to get the attributeHelper for real application code * * @deprecated * * @return Attribute */ private function getAttributeHelper() { if ($this->attributeHelper === null) { $this->attributeHelper = ObjectManager::getInstance()->get('Magento\\Eav\\Model\\Entity\\Attribute'); } return $this->attributeHelper; }
/** * Retrieve cookie metadata factory * * @deprecated * @return CookieMetadataFactory */ private function getCookieMetadataFactory() { if (!$this->cookieMetadataFactory) { $this->cookieMetadataFactory = ObjectManager::getInstance()->get(CookieMetadataFactory::class); } return $this->cookieMetadataFactory; }
/** * The getter function to get the new NameFinder dependency * * @return NameFinder * * @deprecated */ private function getNameFinder() { if ($this->nameFinder === null) { $this->nameFinder = \Magento\Framework\App\ObjectManager::getInstance()->get('\\Magento\\Framework\\Reflection\\NameFinder'); } return $this->nameFinder; }
/** * Get config validator * * @return Design\Config\Validator * * @deprecated */ private function getValidator() { if (null === $this->validator) { $this->validator = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Theme\Model\Design\Config\Validator::class); } return $this->validator; }
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 isAuthorized() { $om = \Magento\Framework\App\ObjectManager::getInstance(); $session = $om->get('Magento\\Framework\\App\\Http\\Context'); $isLoggedIn = $session->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); return $isLoggedIn; }
/** * Test execute add success critical exception * * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteAddSuccessCriticalException() { $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false); $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false); $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false); $exception = new \Exception(); $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true); $helper->expects($this->exactly(2))->method('calculate')->willReturn(true); $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item); $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf(); $wishlist->expects($this->once())->method('save')->willReturn(null); $wishlist->expects($this->once())->method('getId')->willReturn(56); $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true); $product->expects($this->once())->method('getName')->willReturn('Test name'); $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2); $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3); $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product); $item->expects($this->once())->method('load')->with(3)->willReturnSelf(); $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12); $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist); $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item); $this->request->expects($this->once())->method('getParams')->willReturn([]); $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper); $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper); $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger); $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true); $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception); $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->getController()->execute()); }
/** * Execute job by calling specific class::method * * @param int $scheduledTime * @param int $currentTime * @param string[] $jobConfig * @param Schedule $schedule * @param string $groupId * @return void * @throws \Exception */ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId) { $scheduleLifetime = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE; if ($scheduledTime < $currentTime - $scheduleLifetime) { $schedule->setStatus(Schedule::STATUS_MISSED); throw new \Exception('Too late for the schedule'); } if (!isset($jobConfig['instance'], $jobConfig['method'])) { $schedule->setStatus(Schedule::STATUS_ERROR); throw new \Exception('No callbacks found'); } $model = $this->_objectManager->create($jobConfig['instance']); $callback = [$model, $jobConfig['method']]; if (!is_callable($callback)) { $schedule->setStatus(Schedule::STATUS_ERROR); throw new \Exception(sprintf('Invalid callback: %s::%s can\'t be called', $jobConfig['instance'], $jobConfig['method'])); } $schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))->save(); try { call_user_func_array($callback, [$schedule]); } catch (\Exception $e) { $schedule->setStatus(Schedule::STATUS_ERROR); throw $e; } $schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp())); }
/** * Get image uploader * * @return \Magento\Catalog\Model\ImageUploader * * @deprecated */ private function getImageUploader() { if ($this->imageUploader === null) { $this->imageUploader = \Magento\Framework\App\ObjectManager::getInstance()->get('Fastgento\\Storelocator\\LocationImageUpload'); } return $this->imageUploader; }
/** * The getter function to get the new RuleFactory dependency * * @return \Magento\SalesRule\Model\RuleFactory * * @deprecated */ private function getRuleFactory() { if ($this->ruleFactory === null) { $this->ruleFactory = ObjectManager::getInstance()->get('Magento\\SalesRule\\Model\\RuleFactory'); } return $this->ruleFactory; }
protected function tearDown() { parent::tearDown(); /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManagerMock*/ $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock); }
/** * @return CollectionFactoryInterface * * @deprecated */ private function getOrderCollectionFactory() { if ($this->orderCollectionFactory === null) { $this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class); } return $this->orderCollectionFactory; }
/** * @return RequestInterface */ private function getRequest() { if ($this->request === null) { $this->request = \Magento\Framework\App\ObjectManager::getInstance()->get(RequestInterface::class); } return $this->request; }
/** * Test case, successfully run job */ public function testDispatchRunJob() { require_once __DIR__ . '/CronJob.php'; $testCronJob = new \Magento\Cron\Model\CronJob(); $jobConfig = ['test_group' => ['test_job1' => ['instance' => 'CronJob', 'method' => 'execute']]]; $scheduleMethods = ['getJobCode', 'tryLockJob', 'getScheduledAt', 'save', 'setStatus', 'setMessages', 'setExecutedAt', 'setFinishedAt', '__wakeup']; $schedule = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->setMethods($scheduleMethods)->disableOriginalConstructor()->getMock(); $schedule->expects($this->any())->method('getJobCode')->will($this->returnValue('test_job1')); $schedule->expects($this->once())->method('getScheduledAt')->will($this->returnValue('-1 day')); $schedule->expects($this->once())->method('tryLockJob')->will($this->returnValue(true)); // cron start to execute some job $schedule->expects($this->any())->method('setExecutedAt')->will($this->returnSelf()); $schedule->expects($this->at(5))->method('save'); // cron end execute some job $schedule->expects($this->at(6))->method('setStatus')->with($this->equalTo(\Magento\Cron\Model\Schedule::STATUS_SUCCESS))->will($this->returnSelf()); $schedule->expects($this->at(8))->method('save'); $this->_collection->addItem($schedule); $this->_config->expects($this->once())->method('getJobs')->will($this->returnValue($jobConfig)); $lastRun = time() + 10000000; $this->_cache->expects($this->any())->method('load')->will($this->returnValue($lastRun)); $this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue(strtotime('+1 day'))); $scheduleMock = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->getMock(); $scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection)); $this->_scheduleFactory->expects($this->once())->method('create')->will($this->returnValue($scheduleMock)); $this->_objectManager->expects($this->once())->method('create')->with($this->equalTo('CronJob'))->will($this->returnValue($testCronJob)); $this->_observer->dispatch(''); $this->assertInstanceOf('Magento\\Cron\\Model\\Schedule', $testCronJob->getParam()); }
/** * @return \Magento\Framework\Data\Form\FormKey\Validator * @deprecated */ private function getFormKeyValidator() { if (!$this->formKeyValidator) { $this->formKeyValidator = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Data\Form\FormKey\Validator::class); } return $this->formKeyValidator; }