public function testCleanCache() { \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\CacheInterface')->save('test', 'catalog_product_999', ['catalog_product_999']); // potential bug: it cleans by cache tags, generated from its ID, which doesn't make much sense $this->_model->setId(999)->cleanCache(); $this->assertFalse(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\CacheInterface')->load('catalog_product_999')); }
protected function prepareProducts() { $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save(); $this->productSecond = clone $this->product; $this->productSecond->setId(null)->setUrlKey('product-second')->save(); $this->productThird = clone $this->product; $this->productThird->setId(null)->setUrlKey('product-third')->setData('test_attribute', 'NO_test_attribute_value')->save(); }
protected function prepareProducts() { $product = $this->product->loadByAttribute('sku', 'simple'); $product->load($product->getId()); $this->product = $product; $this->product->setData('test_attribute', 'test_attribute_value')->save(); $this->productSecond = clone $this->product; $this->productSecond->setId(null)->setUrlKey('product-second')->save(); $this->productThird = clone $this->product; $this->productThird->setId(null)->setUrlKey('product-third')->setData('test_attribute', 'NO_test_attribute_value')->save(); }
/** * @covers \Magento\Catalog\Model\Product::addCustomOption * @covers \Magento\Catalog\Model\Product::setCustomOptions * @covers \Magento\Catalog\Model\Product::getCustomOptions * @covers \Magento\Catalog\Model\Product::getCustomOption * @covers \Magento\Catalog\Model\Product::hasCustomOptions */ public function testCustomOptionsApi() { $this->assertEquals([], $this->_model->getCustomOptions()); $this->assertFalse($this->_model->hasCustomOptions()); $this->_model->setId(99); $this->_model->addCustomOption('one', 'value1'); $option = $this->_model->getCustomOption('one'); $this->assertInstanceOf('Magento\\Framework\\DataObject', $option); $this->assertEquals($this->_model->getId(), $option->getProductId()); $this->assertSame($option->getProduct(), $this->_model); $this->assertEquals('one', $option->getCode()); $this->assertEquals('value1', $option->getValue()); $this->assertEquals(['one' => $option], $this->_model->getCustomOptions()); $this->assertTrue($this->_model->hasCustomOptions()); $this->_model->setCustomOptions(['test']); $this->assertTrue(is_array($this->_model->getCustomOptions())); }
/** * {@inheritdoc} */ public function setId($value) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'setId'); if (!$pluginInfo) { return parent::setId($value); } else { return $this->___callPlugins('setId', func_get_args(), $pluginInfo); } }