Пример #1
0
 /**
  *  Test protected `_toHtml` method via public `toHtml` method.
  */
 public function testToHtml()
 {
     $eventManager = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->disableOriginalConstructor()->setMethods(['dispatch'])->getMock();
     $eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true));
     $scopeConfig = $this->getMockBuilder('\\Magento\\Framework\\App\\Config')->setMethods(['getValue'])->disableOriginalConstructor()->getMock();
     $scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()->will($this->returnValue(false));
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep'])->getMock();
     $product->expects($this->once())->method('setStoreId')->will($this->returnSelf());
     $product->expects($this->once())->method('load')->will($this->returnSelf());
     $product->expects($this->once())->method('getId')->will($this->returnValue(1));
     $optionsBlock = $this->getMockBuilder('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\Options\\Option')->setMethods(['setIgnoreCaching', 'setProduct', 'getOptionValues'])->disableOriginalConstructor()->getMock();
     $optionsBlock->expects($this->once())->method('setIgnoreCaching')->with(true)->will($this->returnSelf());
     $optionsBlock->expects($this->once())->method('setProduct')->with($product)->will($this->returnSelf());
     $optionsBlock->expects($this->once())->method('getOptionValues')->will($this->returnValue([]));
     $layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Element\\Layout')->disableOriginalConstructor()->setMethods(['createBlock'])->getMock();
     $layout->expects($this->once())->method('createBlock')->with('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\Options\\Option')->will($this->returnValue($optionsBlock));
     $request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->setMethods(['getParam'])->disableOriginalConstructor()->getMock();
     $request->expects($this->once())->method('getParam')->with('store')->will($this->returnValue(0));
     $this->context->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager));
     $this->context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig));
     $this->context->expects($this->once())->method('getLayout')->will($this->returnValue($layout));
     $this->context->expects($this->once())->method('getRequest')->will($this->returnValue($request));
     $this->registry->expects($this->once())->method('registry')->with('import_option_products')->will($this->returnValue([1]));
     $this->productFactory->expects($this->once())->method('create')->will($this->returnValue($product));
     $this->block = $this->objectManagerHelper->getObject('Magento\\Catalog\\Block\\Adminhtml\\Product\\Options\\Ajax', ['context' => $this->context, 'jsonEncoder' => $this->encoderInterface, 'productFactory' => $this->productFactory, 'registry' => $this->registry]);
     $this->block->toHtml();
 }
Пример #2
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_with_options.php
  */
 public function testToHtml()
 {
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $objectManager->get('Magento\\Framework\\Registry')->register('import_option_products', [1]);
     $result = json_decode($this->_block->toHtml(), true);
     $this->assertEquals('test_option_code_1', $result[0]['title']);
 }
Пример #3
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_with_options.php
  */
 public function testToHtml()
 {
     /** @var \Magento\TestFramework\ObjectManager $objectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
     $productRepository = $objectManager->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $objectManager->get('Magento\\Framework\\Registry')->register('import_option_products', [$productRepository->get('simple')->getId()]);
     $result = json_decode($this->_block->toHtml(), true);
     $this->assertEquals('test_option_code_1', $result[0]['title']);
 }