/**
  * 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'));
 }
Example #2
0
 /**
  * Return value object related to this config found by given criteria, or creates new one otherwise
  *
  * @param string $section
  * @param string $name
  *
  * @return ConfigValue
  */
 public function getOrCreateValue($section, $name)
 {
     $values = $this->getValues()->filter(function (ConfigValue $item) use($name, $section) {
         return $item->getName() == $name && $item->getSection() == $section;
     });
     /** @var ArrayCollection $values */
     if ($values->first() === false) {
         $value = new ConfigValue();
         $value->setConfig($this);
         $value->setName($name);
         $value->setSection($section);
     } else {
         $value = $values->first();
     }
     return $value;
 }
 /**
  * {@inheritDoc}
  */
 public function setSection($section)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setSection', array($section));
     return parent::setSection($section);
 }