/** * Test saving settings */ public function testSave() { $config = new Config(); $configValue1 = new ConfigValue(); $configValue1->setSection('oro_user')->setName('update')->setValue('old value')->setType('scalar'); $configValue2 = new ConfigValue(); $configValue2->setSection('oro_user')->setName('remove')->setValue('test')->setType('scalar'); $config->getValues()->add($configValue1); $config->getValues()->add($configValue2); $settings = ['oro_user.update' => ['value' => 'updated value', 'use_parent_scope_value' => false], 'oro_user.remove' => ['use_parent_scope_value' => true], 'oro_user.add' => ['value' => 'new value', 'use_parent_scope_value' => false]]; $this->repo->expects($this->once())->method('findByEntity')->with('app', 0)->will($this->returnValue($config)); $this->cache->expects($this->once())->method('save')->with('app_0', ['oro_user' => ['update' => ['value' => 'updated value', 'use_parent_scope_value' => false, 'createdAt' => null, 'updatedAt' => null], 'add' => ['value' => 'new value', 'use_parent_scope_value' => false, 'createdAt' => null, 'updatedAt' => null]]]); $this->em->expects($this->once())->method('persist')->with($this->identicalTo($config)); $this->em->expects($this->once())->method('flush'); $result = $this->manager->save($settings); $this->assertEquals([['oro_user.update' => 'updated value', 'oro_user.add' => 'new value'], ['oro_user.remove']], $result); $this->assertEquals('updated value', $this->manager->getSettingValue('oro_user.update')); $this->assertNull($this->manager->getSettingValue('oro_user.remove')); $this->assertEquals('new value', $this->manager->getSettingValue('oro_user.add')); }
/** * {@inheritDoc} */ public function getValues() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getValues', array()); return parent::getValues(); }
/** * @param Config $config * * @return array */ protected function convertToSettings(Config $config) { $settings = []; foreach ($config->getValues() as $value) { $settings[$value->getSection()][$value->getName()] = ['value' => $value->getValue(), 'use_parent_scope_value' => false, 'createdAt' => $value->getCreatedAt(), 'updatedAt' => $value->getUpdatedAt()]; } return $settings; }