public function testPreUpdate()
 {
     $obj = new ConfigValue();
     $this->assertNull($obj->getUpdatedAt());
     $obj->doPreUpdate();
     $this->assertInstanceOf('\\DateTime', $obj->getUpdatedAt());
 }
Exemple #2
0
 /**
  * Test getOrCreateValue
  */
 public function testGetOrCreateValue()
 {
     $object = $this->object;
     $value = $object->getOrCreateValue('oro_user', 'level');
     $this->assertEquals('oro_user', $value->getSection());
     $this->assertEquals('level', $value->getName());
     $this->assertEquals($object, $value->getConfig());
     $values = new ArrayCollection();
     $configValue = new ConfigValue();
     $configValue->setValue('test')->setSection('test')->setName('test');
     $values->add($configValue);
     $object->setValues($values);
     $value = $object->getOrCreateValue('test', 'test');
     $this->assertEquals('test', (string) $value);
     $this->assertEquals('test', $value->getSection());
     $this->assertEquals('test', $value->getName());
 }
 /**
  * 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'));
 }
Exemple #4
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;
 }
 public function getOrCreateValue($section, $key)
 {
     $value = $this->getValues()->filter(function (ConfigValue $item) use($key, $section) {
         return $item->getName() == $key && $item->getSection() == $section;
     });
     if ($value->first() === false) {
         $value = new ConfigValue();
         $value->setConfig($this)->setName($key)->setSection($section);
     } else {
         $value = $value->first();
     }
     return $value;
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }