public function testSetName()
 {
     $ce = new ConfigurationEntry('foo');
     $this->assertEquals('foo', $ce->getName());
     $ce->setName('bar');
     $this->assertEquals('bar', $ce->getName());
 }
 /**
  * {@inheritdoc}
  */
 public function getReadableValue(ConfigurationEntry $entry)
 {
     $cfg = $entry->getServerHandlerConfig();
     if (!isset($cfg['toStringMethodName'])) {
         throw MissingConfigurationParameterException::create($entry, 'toStringMethodName');
     }
     $entity = $this->em->find($this->getEntityFqcn($entry), $entry->getDenormalizedValue());
     if (!$entity) {
         throw new \RuntimeException(sprintf('Unable to find entity "%s" with id "%s"', $this->getEntityFqcn($entry), $entry->getDenormalizedValue()));
     }
     return $entity->{$cfg['toStringMethodName']}();
 }
 public function testIsValidForSaving_changeNameWithOwner()
 {
     $vasya = new User('vasya');
     $ce1 = new ConfigurationEntry('cf_1');
     $ce1->setValue('foo');
     $ce2 = new ConfigurationEntry('cf_2');
     $ce2->setValue('foo');
     self::$em->persist($vasya);
     self::$em->persist($ce1);
     self::$em->persist($ce2);
     self::$em->flush();
     $ce2->setName('cf_1');
     $uv = new UniquityValidator(self::$em, array('owner_entity' => get_class($vasya)));
     $this->assertFalse($uv->isValidForSaving($ce2));
 }
Esempio n. 4
0
 private function createEntryWithServerConfig($clientValue, array $config)
 {
     $entry = $this->createMock(ConfigurationEntry::clazz(), array(), array(), '', null, false);
     $entry->expects($this->once())->method('getDenormalizedValue')->will($this->returnValue(1));
     $entry->expects($this->atLeastOnce())->method('getServerHandlerConfig')->will($this->returnValue($config));
     return $entry;
 }
 public function setUp()
 {
     $this->handler = new DictionaryHandler();
     $config = array('dictionary' => array('foo' => 'foo-val'));
     $this->entry = $this->createMock(ConfigurationEntry::clazz(), array(), array(), '', null, false);
     $this->entry->expects($this->any())->method('getServerHandlerConfig')->will($this->returnValue($config));
 }
 /**
  * @param LoadClassMetadataEventArgs $args
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     /* @var ClassMetadataInfo $mapping */
     $mapping = $args->getClassMetadata();
     if ($mapping->getName() == ConfigurationEntry::clazz()) {
         $mapping->mapManyToOne(array('fieldName' => 'owner', 'type' => ClassMetadataInfo::MANY_TO_ONE, 'isOwningSide' => true, 'targetEntity' => $this->semanticConfig['owner_entity']));
     }
 }
 public function testGetConfigMapDataOnUpdate()
 {
     $config = $this->c->getConfig();
     $this->assertTrue(is_array($config));
     $this->assertArrayHasKey('map_data_on_update', $config);
     $this->assertTrue(is_callable($config['map_data_on_update']));
     $mapper = $config['map_data_on_update'];
     $entry = \Phake::mock(ConfigurationEntry::clazz());
     $this->teachEntry($entry, 'isReadOnly', true);
 }
Esempio n. 8
0
 /**
  * @param ConfigurationEntry $entry
  *
  * @return bool
  */
 public function isValidForSaving(ConfigurationEntry $entry)
 {
     $query = null;
     if ($this->semanticConfig['owner_entity'] && $entry->getOwner()) {
         $query = sprintf('SELECT e.id FROM %s e WHERE e.name = ?0 AND e.owner = ?1', get_class($entry));
         $query = $this->em->createQuery($query);
         $query->setParameters([$entry->getName(), $entry->getOwner()]);
     } else {
         $query = sprintf('SELECT e.id FROM %s e WHERE e.name = ?0', get_class($entry));
         $query = $this->em->createQuery($query);
         $query->setParameter(0, $entry->getName());
     }
     $result = $query->getArrayResult();
     $isNameInUse = count($result) > 0;
     if ($isNameInUse) {
         // if name is already in use then we will allow to save configuration property if it represents
         // the same records as in database
         return $entry->getId() == $result[0]['id'];
     }
     return true;
 }
Esempio n. 9
0
 /**
  * @return array
  */
 public function getConfig()
 {
     return array('entity' => ConfigurationEntry::clazz(), 'hydration' => array('groups' => array('list' => function (ConfigurationEntry $entry) {
         return array('id' => $entry->getId(), 'name' => $entry->getName(), 'readableName' => $entry->getReadableName(), 'readableValue' => $entry->getReadableValue(), 'value' => $entry->getValue(), 'isReadOnly' => $entry->isReadOnly(), 'editorConfig' => $entry->getClientHandlerConfig());
     }), 'profiles' => ['list']), 'map_data_on_update' => function (array $params, ConfigurationEntry $entry) {
         if ($entry->isReadOnly() || !$entry->isExposed()) {
             return;
         }
         if (isset($params['value'])) {
             $entry->setValue($params['value']);
         }
     });
 }
Esempio n. 10
0
 /**
  * @return \Modera\ConfigBundle\Entity\ConfigurationEntry[]
  */
 public function install()
 {
     $installedEntries = array();
     foreach ($this->provider->getItems() as $entryDef) {
         /* @var ConfigurationEntryInterface $entryDef */
         if (!$this->entryExists($entryDef)) {
             $entry = ConfigurationEntry::createFromDefinition($entryDef);
             $this->em->persist($entry);
             $installedEntries[] = $entryDef;
         }
     }
     $this->em->flush();
     return $installedEntries;
 }
 public function setUp()
 {
     $this->em = $this->createMock('Doctrine\\ORM\\EntityManager', array(), array(), '', false);
     $this->ce = $this->createMock(ConfigurationEntry::clazz(), array(), array(), '', false);
     $this->handler = new EntityRepositoryHandler($this->em);
 }
 /**
  * @param object $owner
  *
  * @return ConfigurationEntryInterface[]
  */
 public function findAllExposed($owner = null)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('e')->from(ConfigurationEntry::clazz(), 'e')->andWhere($qb->expr()->eq('e.isExposed', '?1'));
     $qb->setParameter(1, true);
     if ($this->isOwnerConfigured()) {
         $qb->andWhere($owner ? $qb->expr()->eq('e.owner', '?2') : $qb->expr()->isNull('e.owner'));
         if ($owner) {
             $qb->setParameter(2, $owner);
         }
     }
     return $qb->getQuery()->getResult();
 }
Esempio n. 13
0
 /**
  * {@inheritdoc}
  */
 public function getValue(ConfigurationEntry $entry)
 {
     return $entry->getDenormalizedValue();
 }
 /**
  * {@inheritdoc}
  */
 public static function doTearDownAfterClass()
 {
     self::$st->dropSchema([self::$em->getClassMetadata(ConfigurationEntry::clazz()), self::$em->getClassMetadata(User::clazz())]);
 }
Esempio n. 15
0
 public function setUp()
 {
     $this->entry = $this->createMock(ConfigurationEntry::clazz(), array(), array(), '', null, false);
     $this->handler = new AsIsHandler();
 }
 public function testFindAllExposed()
 {
     $ce1 = new ConfigurationEntry('cf_1');
     $ce1->setValue('foo');
     $ce2 = new ConfigurationEntry('cf_2');
     $ce2->setValue('foo');
     $ce3 = new ConfigurationEntry('cf_3');
     $ce3->setValue('foo');
     $ce3->setExposed(false);
     $this->getManager()->save($ce1);
     $this->getManager()->save($ce2);
     $this->getManager()->save($ce3);
     $result = $this->getManager()->findAllExposed();
     $this->assertEquals(2, count($result));
     $this->assertEquals('cf_1', $result[0]->getName());
     $this->assertEquals('cf_2', $result[1]->getName());
     // ---
     $vasya = new User('vasya');
     self::$em->persist($vasya);
     self::$em->flush();
     $ce1->setOwner($vasya);
     $this->getManager()->save($ce1);
     $result = $this->getManager()->findAllExposed();
     $this->assertEquals(1, count($result));
     $this->assertEquals('cf_2', $result[0]->getName());
     // ---
     $result = $this->getManager()->findAllExposed($vasya);
     $this->assertEquals(1, count($result));
     $this->assertEquals('cf_1', $result[0]->getName());
 }
Esempio n. 17
0
 /**
  * @expectedException RuntimeException
  */
 public function testSetClientValueWithBadValue()
 {
     $ce = new CE('blah');
     $ce->setDenormalizedValue(new \stdClass());
 }