コード例 #1
0
 public function testAddFiltersVerifyAddConditionsToRegistry()
 {
     $registry = new \Magento\Framework\Registry();
     $values = array('sku' => 'simple');
     $this->skuAttribute->expects($this->once())->method('getTable')->will($this->returnValue('catalog_product_entity'));
     $this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(array('like' => '%simple%')));
     $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $this->engine->expects($this->any())->method('getResource')->will($this->returnValue($this->resource));
     $this->engine->expects($this->any())->method('getAdvancedResultCollection')->will($this->returnValue($this->collection));
     $this->engineProvider->expects($this->any())->method('get')->will($this->returnValue($this->engine));
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue('sku'));
     $this->attribute->expects($this->any())->method('getStoreLabel')->will($this->returnValue('SKU'));
     $this->attribute->expects($this->any())->method('getFrontendInput')->will($this->returnValue('text'));
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->skuAttribute));
     $this->attribute->expects($this->any())->method('getBackendType')->will($this->returnValue('static'));
     $this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator(array($this->attribute))));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     /** @var \Magento\CatalogSearch\Model\Advanced $instance */
     $instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', array('registry' => $registry, 'engineProvider' => $this->engineProvider, 'data' => array('attributes' => $this->dataCollection)));
     $instance->addFilters($values);
     $this->assertNotNull($registry->registry('advanced_search_conditions'));
 }
コード例 #2
0
ファイル: ActionTest.php プロジェクト: Coplex/magento2
 public function testUpdateAttributes()
 {
     $productIds = [1, 2, 2, 4];
     $productIdsUnique = [0 => 1, 1 => 2, 3 => 4];
     $attrData = [1];
     $storeId = 1;
     $this->resource->expects($this->any())->method('updateAttributes')->with($productIds, $attrData, $storeId)->will($this->returnSelf());
     $this->categoryIndexer->expects($this->any())->method('isScheduled')->will($this->returnValue(false));
     $this->categoryIndexer->expects($this->any())->method('reindexList')->will($this->returnValue($productIds));
     $this->prepareIndexer();
     $this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttribute));
     $this->eavAttribute->expects($this->any())->method('isIndexable')->will($this->returnValue(false));
     $this->assertEquals($this->model, $this->model->updateAttributes($productIds, $attrData, $storeId));
     $this->assertEquals($this->model->getDataByKey('product_ids'), $productIdsUnique);
     $this->assertEquals($this->model->getDataByKey('attributes_data'), $attrData);
     $this->assertEquals($this->model->getDataByKey('store_id'), $storeId);
 }
コード例 #3
0
 /**
  * @dataProvider validateDataProvider
  *
  * @param string $attributeValue
  * @param string|array $parsedValue
  * @param string $newValue
  * @param string $operator
  * @param array $input
  */
 public function testValidateWithDatetimeValue($attributeValue, $parsedValue, $newValue, $operator, $input)
 {
     $this->product->setData('attribute', 'attribute_key');
     $this->product->setData('value_parsed', $parsedValue);
     $this->product->setData('operator', $operator);
     $this->config->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource));
     $this->eavAttributeResource->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(false));
     $this->eavAttributeResource->expects($this->any())->method($input['method'])->will($this->returnValue($input['type']));
     $this->productModel->expects($this->any())->method('hasData')->will($this->returnValue(true));
     $this->productModel->expects($this->at(0))->method('getData')->will($this->returnValue(['1' => ['1' => $attributeValue]]));
     $this->productModel->expects($this->any())->method('getData')->will($this->returnValue($newValue));
     $this->productModel->expects($this->any())->method('getId')->will($this->returnValue('1'));
     $this->productModel->expects($this->once())->method('getStoreId')->will($this->returnValue('1'));
     $this->productModel->expects($this->any())->method('getResource')->will($this->returnValue($this->productResource));
     $this->productResource->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource));
     $this->product->collectValidatedAttributes($this->productModel);
     $this->assertTrue($this->product->validate($this->productModel));
 }