Ejemplo n.º 1
0
 protected function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->any())->method('quoteInto')->willReturnCallback(function ($query, $expression) {
         return str_replace('?', $expression, $query);
     });
     $this->resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->resource->method('getTableName')->willReturnCallback(function ($table) {
         return 'prefix_' . $table;
     });
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->website = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\WebsiteInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->website->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
     $this->store = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->store->expects($this->any())->method('getId')->willReturn(self::STORE_ID);
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->any())->method('getWebsite')->willReturn($this->website);
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
     $this->attributeCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection')->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory->expects($this->once())->method('create')->willReturn($this->attributeCollection);
     $this->target = $objectManager->getObject('\\Magento\\CatalogSearch\\Model\\Search\\TableMapper', ['resource' => $this->resource, 'storeManager' => $this->storeManager, 'attributeCollectionFactory' => $attributeCollectionFactory]);
     $this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMock();
 }
 /**
  * @test
  */
 public function validateNonNumericWebsite()
 {
     $existingWebsiteCode = 'my-cool-website';
     $this->mockWebsiteOne->expects($this->any())->method('getCode')->will($this->returnValue($existingWebsiteCode));
     $this->assertTrue($this->validator->validate('websites', $existingWebsiteCode));
     $this->assertFalse($this->validator->validate('websites', 'am i real?'));
 }
Ejemplo n.º 3
0
 public function testCreateInSingleStoreMode()
 {
     $scope = 'default';
     $scopeId = 0;
     $data = ['header_default_title' => 'value'];
     $metadata = ['header_default_title' => ['path' => 'design/header/default_title', 'fieldset' => 'head'], 'head_default_description' => ['path' => 'design/head/default_description', 'fieldset' => 'head']];
     $this->scopeValidator->expects($this->once())->method('isValidScope')->with($scope, $scopeId)->willReturn(true);
     $this->storeManager->expects($this->once())->method('isSingleStoreMode')->willReturn(true);
     $this->storeManager->expects($this->once())->method('getWebsites')->willReturn([$this->website]);
     $this->website->expects($this->once())->method('getId')->willReturn(1);
     $this->designConfigFactory->expects($this->once())->method('create')->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('setScope')->willReturn('websites');
     $this->designConfig->expects($this->once())->method('setScopeId')->willReturn(1);
     $this->metadataProvider->expects($this->once())->method('get')->willReturn($metadata);
     $this->designConfigDataFactory->expects($this->exactly(2))->method('create')->willReturn($this->designConfigData);
     $this->designConfigData->expects($this->exactly(2))->method('setPath')->withConsecutive(['design/header/default_title'], ['design/head/default_description']);
     $this->designConfigData->expects($this->exactly(2))->method('setFieldConfig')->withConsecutive([['path' => 'design/header/default_title', 'fieldset' => 'head', 'field' => 'header_default_title']], [['path' => 'design/head/default_description', 'fieldset' => 'head', 'field' => 'head_default_description']]);
     $this->designConfigData->expects($this->once())->method('setValue')->with('value');
     $this->configExtensionFactory->expects($this->once())->method('create')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('setDesignConfigData')->with([$this->designConfigData, $this->designConfigData]);
     $this->designConfig->expects($this->once())->method('setExtensionAttributes')->with($this->designConfigExtension);
     $this->assertSame($this->designConfig, $this->factory->create($scope, $scopeId, $data));
 }
Ejemplo n.º 4
0
 /**
  * @covers \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper::initialize
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testInitialize()
 {
     $this->websiteMock->expects($this->once())->method('getId')->willReturn($this->websiteId);
     $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
     $this->storeManagerMock->expects($this->once())->method('getStore')->with(true)->willReturn($this->storeMock);
     $this->customOptionMock->expects($this->once())->method('setProductSku');
     $this->customOptionMock->expects($this->once())->method('setOptionId');
     $optionsData = ['option1' => ['is_delete' => true, 'name' => 'name1', 'price' => 'price1'], 'option2' => ['is_delete' => false, 'name' => 'name1', 'price' => 'price1']];
     $productData = ['stock_data' => ['stock_data'], 'options' => $optionsData];
     $attributeNonDate = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)->disableOriginalConstructor()->getMock();
     $attributeDate = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)->disableOriginalConstructor()->getMock();
     $attributeNonDateBackEnd = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend::class)->disableOriginalConstructor()->getMock();
     $attributeDateBackEnd = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Backend\Datetime::class)->disableOriginalConstructor()->getMock();
     $attributeNonDate->expects($this->any())->method('getBackend')->willReturn($attributeNonDateBackEnd);
     $attributeDate->expects($this->any())->method('getBackend')->willReturn($attributeDateBackEnd);
     $this->productMock->expects($this->any())->method('getProductLinks')->willReturn([]);
     $attributeNonDateBackEnd->expects($this->any())->method('getType')->willReturn('non-datetime');
     $attributeDateBackEnd->expects($this->any())->method('getType')->willReturn('datetime');
     $attributesArray = [$attributeNonDate, $attributeDate];
     $useDefaults = ['attributeCode1', 'attributeCode2'];
     $this->requestMock->expects($this->at(0))->method('getPost')->with('product')->willReturn($productData);
     $this->requestMock->expects($this->at(1))->method('getPost')->with('use_default')->willReturn($useDefaults);
     $this->linkResolverMock->expects($this->once())->method('getLinks')->willReturn([]);
     $this->stockFilterMock->expects($this->once())->method('filter')->with(['stock_data'])->willReturn(['stock_data']);
     $this->storeManagerMock->expects($this->once())->method('hasSingleStore')->willReturn(true);
     $this->productMock->expects($this->once())->method('isLockedAttribute')->with('media')->willReturn(true);
     $this->productMock->expects($this->once())->method('unlockAttribute')->with('media');
     $this->productMock->expects($this->any())->method('getProductLinks')->willReturn([]);
     $this->productMock->expects($this->once())->method('lockAttribute')->with('media');
     $this->productMock->expects($this->once())->method('getAttributes')->willReturn($attributesArray);
     $productData['category_ids'] = [];
     $productData['website_ids'] = [];
     unset($productData['options']);
     $this->productMock->expects($this->once())->method('addData')->with($productData);
     $this->productMock->expects($this->once())->method('getSku')->willReturn('sku');
     $this->productMock->expects($this->once())->method('setWebsiteIds')->with([$this->websiteId]);
     $this->productMock->expects($this->any())->method('getOptionsReadOnly')->willReturn(false);
     $this->customOptionFactoryMock->expects($this->any())->method('create')->with(['data' => $optionsData['option2']])->willReturn($this->customOptionMock);
     $this->productMock->expects($this->once())->method('setOptions')->with([$this->customOptionMock]);
     $this->assertEquals($this->productMock, $this->helper->initialize($this->productMock));
 }
 /**
  * @param \Magento\Store\Api\Data\WebsiteInterface $website
  * @param int                                      $limit
  *
  * @return mixed
  */
 public function getWishlistToImport(\Magento\Store\Api\Data\WebsiteInterface $website, $limit = 100)
 {
     $collection = $this->wishlistCollection->create()->addFieldToFilter('wishlist_imported', ['null' => true])->addFieldToFilter('store_id', ['in' => $website->getStoreIds()])->addFieldToFilter('item_count', ['gt' => 0]);
     $collection->getSelect()->limit($limit);
     return $collection;
 }