Пример #1
0
 public function testProperties()
 {
     /** test ConfigEntity */
     $this->assertNull($this->configEntity->getClassName());
     $this->assertEmpty($this->configEntity->getId());
     $this->assertNull($this->configEntity->getCreated());
     $this->configEntity->setCreated(new \DateTime('2013-01-01'));
     $this->assertEquals('2013-01-01', $this->configEntity->getCreated()->format('Y-m-d'));
     $this->assertNull($this->configEntity->getUpdated());
     $this->configEntity->setUpdated(new \DateTime('2013-01-01'));
     $this->assertEquals('2013-01-01', $this->configEntity->getUpdated()->format('Y-m-d'));
     /** test ConfigEntity prePersist */
     $this->configEntity->prePersist();
     $currentDate = new \DateTime('now', new \DateTimeZone('UTC'));
     $this->assertEquals($currentDate->format('Y-m-d'), $this->configEntity->getCreated()->format('Y-m-d'));
     /** test ConfigEntity preUpdate */
     $this->configEntity->preUpdate();
     $currentDate = new \DateTime('now', new \DateTimeZone('UTC'));
     $this->assertEquals($currentDate->format('Y-m-d'), $this->configEntity->getUpdated()->format('Y-m-d'));
     /** test ConfigField */
     $this->assertEmpty($this->configField->getId());
     $this->configField->setMode(ConfigModelManager::MODE_READONLY);
     $this->assertEquals(ConfigModelManager::MODE_READONLY, $this->configField->getMode());
     /** test ConfigValue */
     $this->assertEmpty($this->configValue->getId());
     $this->assertEmpty($this->configValue->getScope());
     $this->assertEmpty($this->configValue->getCode());
     $this->assertEmpty($this->configValue->getValue());
     $this->assertEmpty($this->configValue->getField());
     $this->assertFalse($this->configValue->getSerializable());
     $this->configValue->setSerializable(true);
     $this->assertTrue($this->configValue->getSerializable());
     $this->assertEmpty($this->configValue->getEntity());
     $this->configValue->setEntity($this->configEntity);
     $this->assertEquals($this->configEntity, $this->configValue->getEntity());
 }
 /**
  * @param       $scope
  * @param array $values
  * @param array $serializableValues
  */
 public function fromArray($scope, array $values, array $serializableValues = array())
 {
     foreach ($values as $code => $value) {
         $serializable = isset($serializableValues[$code]) && (bool) $serializableValues[$code];
         if (!$serializable && is_bool($value)) {
             $value = (int) $value;
         }
         if (!$serializable && !is_string($value)) {
             $value = (string) $value;
         }
         if ($configValue = $this->getValue($code, $scope)) {
             $configValue->setValue($value);
         } else {
             $configValue = new ConfigModelValue($code, $scope, $value, $serializable);
             if ($this instanceof EntityConfigModel) {
                 $configValue->setEntity($this);
             } else {
                 $configValue->setField($this);
             }
             $this->addValue($configValue);
         }
     }
 }