public function testIsValueChanged() { // load the model $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Core\\Model\\Resource\\Config\\Data\\Collection'); $collection->addFieldToFilter('path', self::SAMPLE_CONFIG_PATH)->addFieldToFilter('scope_id', 0)->addFieldToFilter('scope', 'default'); foreach ($collection as $configData) { $this->_model = $configData; break; } $this->assertNotEmpty($this->_model->getId()); // assert $this->assertFalse($this->_model->isValueChanged()); $this->_model->setValue(uniqid()); $this->assertTrue($this->_model->isValueChanged()); }
/** * After save handler * * @param \Magento\Framework\App\Config\Value $subject * @param mixed $result * * @return mixed */ public function afterSave(\Magento\Framework\App\Config\Value $subject, $result) { if ($subject->isValueChanged()) { $this->_eavIndexerProcessor->markIndexerAsInvalid(); } return $result; }
/** * Invalidate WebApi cache if needed. * * @param \Magento\Framework\App\Config\Value $subject * @param \Magento\Framework\App\Config\Value $result * @return \Magento\Framework\App\Config\Value * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterAfterSave(\Magento\Framework\App\Config\Value $subject, \Magento\Framework\App\Config\Value $result) { if ($subject->getPath() == \Magento\WebapiSecurity\Model\Plugin\AnonymousResourceSecurity::XML_ALLOW_INSECURE && $subject->isValueChanged()) { $this->cacheTypeList->invalidate(\Magento\Framework\App\Cache\Type\Webapi::TYPE_IDENTIFIER); } return $result; }
/** * @param string $oldValue * @param string $value * @param bool $result * @dataProvider dataIsValueChanged */ public function testIsValueChanged($oldValue, $value, $result) { $this->configMock->expects($this->once())->method('getValue')->with(null, 'default')->will($this->returnValue($oldValue)); $this->model->setValue($value); $this->assertEquals($result, $this->model->isValueChanged()); }