コード例 #1
0
 /**
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function setUp()
 {
     /** @var \Magento\Framework\Registry $var */
     $this->coreRegistry = $var = $this->getMockBuilder('\\Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['register'])->getMock();
     $this->category = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'setStoreId', 'load', 'getPathIds'])->getMock();
     $this->categoryFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\CategoryFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->categoryFactory->expects($this->any())->method('create')->will($this->returnValue($this->category));
     $this->store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $this->layer = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getCurrentStore', 'getCurrentCategory'])->getMock();
     $this->layer->expects($this->any())->method('getCurrentStore')->will($this->returnValue($this->store));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Category', ['coreRegistry' => $this->coreRegistry, 'categoryFactory' => $this->categoryFactory, 'layer' => $this->layer]);
 }
コード例 #2
0
 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->category = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->setMethods(['load', 'getId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->categoryFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\CategoryFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->categoryFactory->expects($this->any())->method('create')->will($this->returnValue($this->category));
     $this->registry = $this->getMockBuilder('Magento\\Framework\\Registry')->setMethods(['registry'])->disableOriginalConstructor()->getMock();
     $this->store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getRootCategoryId', 'getFilters', '__wakeup'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->storeManager = $this->getMockBuilder('Magento\\Framework\\StoreManagerInterface')->setMethods(['getStore'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $this->stateKeyGenerator = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Category\\StateKey')->setMethods(['toString'])->disableOriginalConstructor()->getMock();
     $this->collectionFilter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Category\\CollectionFilter')->setMethods(['filter'])->disableOriginalConstructor()->getMock();
     $this->collectionProvider = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\ItemCollectionProviderInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->filter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Filter\\Item')->setMethods(['getFilter', 'getValueString'])->disableOriginalConstructor()->getMock();
     $this->abstractFilter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Filter\\AbstractFilter')->setMethods(['getRequestVar'])->disableOriginalConstructor()->getMock();
     $this->context = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\ContextInterface')->setMethods(['getStateKey', 'getCollectionFilter'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->context->expects($this->any())->method('getStateKey')->will($this->returnValue($this->stateKeyGenerator));
     $this->context->expects($this->any())->method('getCollectionFilter')->will($this->returnValue($this->collectionFilter));
     $this->context->expects($this->any())->method('getCollectionProvider')->will($this->returnValue($this->collectionProvider));
     $this->state = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->getMock();
     $this->stateFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\StateFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->stateFactory->expects($this->any())->method('create')->will($this->returnValue($this->state));
     $this->collection = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product\\Collection')->disableOriginalConstructor()->getMock();
     $this->model = $helper->getObject('Magento\\Catalog\\Model\\Layer', ['registry' => $this->registry, 'categoryFactory' => $this->categoryFactory, 'storeManager' => $this->storeManager, 'context' => $this->context, 'layerStateFactory' => $this->stateFactory]);
 }
コード例 #3
0
 public function testGetCategory()
 {
     $this->category->expects($this->any())->method('getId')->will($this->returnValue(10));
     $this->registry->expects($this->any())->method('registry')->will($this->returnValue($this->category));
     $this->categoryFactory->expects($this->any())->method('create')->will($this->returnValue($this->category));
     $this->category->expects($this->once())->method('load')->will($this->returnValue($this->category));
     $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Category', $this->model->getCategory());
 }
コード例 #4
0
 public function testAddErrorMessageWhenProductWithoutStores()
 {
     $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false);
     $form->expects($this->any())->method('getElement')->will($this->returnValue($this->getMockForAbstractClass('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false)));
     $this->formFactory->expects($this->once())->method('create')->will($this->returnValue($form));
     $fieldset = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false);
     $form->expects($this->once())->method('addFieldset')->will($this->returnValue($fieldset));
     $storeElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', ['setAfterElementHtml', 'setValues'], [], '', false);
     $fieldset->expects($this->at(2))->method('addField')->with('store_id', 'select', ['label' => 'Store', 'title' => 'Store', 'name' => 'store_id', 'required' => true, 'value' => 0])->willReturn($storeElement);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product->expects($this->any())->method('getId')->willReturn('product_id');
     $product->expects($this->once())->method('getStoreIds')->willReturn([]);
     $this->productFactory->expects($this->once())->method('create')->willReturn($product);
     $this->categoryFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false));
     $storeElement->expects($this->once())->method('setAfterElementHtml');
     $storeElement->expects($this->once())->method('setValues')->with([]);
     $this->layout->expects($this->once())->method('createBlock')->willReturn($this->getMock('Magento\\Framework\\Data\\Form\\Element\\Renderer\\RendererInterface'));
     $this->form->toHtml();
 }
コード例 #5
0
 public function testApplyCustomLayoutUpdate()
 {
     $categoryId = 123;
     $pageLayout = 'page_layout';
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Catalog\\Helper\\Category', $this->categoryHelper], ['Magento\\Theme\\Helper\\Layout', $this->layoutHelper]]));
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([[Action::PARAM_NAME_URL_ENCODED], ['id', false, $categoryId]]));
     $this->categoryFactory->expects($this->any())->method('create')->will($this->returnValue($this->category));
     $this->category->expects($this->any())->method('setStoreId')->will($this->returnSelf());
     $this->category->expects($this->any())->method('load')->with($categoryId)->will($this->returnSelf());
     $this->categoryHelper->expects($this->any())->method('canShow')->will($this->returnValue(true));
     $settings = $this->getMock('Magento\\Framework\\Object', ['getPageLayout'], [], '', false);
     $settings->expects($this->atLeastOnce())->method('getPageLayout')->will($this->returnValue($pageLayout));
     $this->catalogDesign->expects($this->any())->method('getDesignSettings')->will($this->returnValue($settings));
     $this->action->execute();
 }