Ejemplo n.º 1
0
 public function testSubmitValidData()
 {
     $scale = new Scale();
     $scale->setName('Scale 1');
     $level = new Level();
     $level->setName('Level 1');
     $level->setValue(0);
     $level->setScale($scale);
     $parent = new Competency();
     $parent->setName('Competency 1');
     $parent->setScale($scale);
     $om = $this->client->getContainer()->get('claroline.persistence.object_manager');
     $om->persist($scale);
     $om->persist($level);
     $om->persist($parent);
     $om->flush();
     $formData = ['name' => 'Foo', 'level' => $level->getId(), 'minActivityCount' => 2];
     $form = $this->factory->create(new AbilityType(), null, ['competency' => $parent]);
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $ability = $form->getData();
     $this->assertInstanceOf('HeVinci\\CompetencyBundle\\Entity\\Ability', $ability);
     $this->assertEquals('Foo', $ability->getName());
     $this->assertEquals($level, $ability->getLevel());
     $this->assertEquals(2, $ability->getMinActivityCount());
     $this->assertViewIsValid($form, $formData);
 }
 public function testSubmitValidData()
 {
     $scale = new Scale();
     $scale->setName('Scale 1');
     $level = new Level();
     $level->setName('Level 1');
     $level->setValue(0);
     $level->setScale($scale);
     $parent = new Competency();
     $parent->setName('Competency 1');
     $parent->setScale($scale);
     $ability = new Ability();
     $ability->setName('Foo');
     $this->om->persist($scale);
     $this->om->persist($level);
     $this->om->persist($parent);
     $this->om->persist($ability);
     $this->om->flush();
     $formData = ['ability' => 'Foo', 'level' => $level->getId()];
     $form = $this->factory->create(new AbilityImportType($this->om), null, ['competency' => $parent]);
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($ability, $form->getData());
     $this->assertEquals($level, $ability->getLevel());
     $this->assertViewIsValid($form, $formData);
 }
Ejemplo n.º 3
0
 protected function persistLevel($name, Scale $scale, $value = 0)
 {
     $level = new Level();
     $level->setName($name);
     $level->setValue($value);
     $level->setScale($scale);
     $scale->addLevel($level);
     $this->om->persist($level);
     return $level;
 }
Ejemplo n.º 4
0
 /**
  * Converts a JSON representation of a competency framework
  * into an entity graph (without persisting it).
  *
  * @param string $jsonFramework
  * @return Competency
  */
 public function convertToEntity($jsonFramework)
 {
     $frameworkData = json_decode($jsonFramework);
     $scaleRepo = $this->om->getRepository('HeVinciCompetencyBundle:Scale');
     if (!($scale = $scaleRepo->findOneBy(['name' => $frameworkData->scale->name]))) {
         $scale = new Scale();
         $scale->setName($frameworkData->scale->name);
         for ($i = 0, $levels = $frameworkData->scale->levels, $max = count($levels); $i < $max; ++$i) {
             $level = new Level();
             $level->setName($levels[$i]);
             $level->setValue($i);
             $level->setScale($scale);
             $scale->addLevel($level);
         }
     }
     $framework = new Competency();
     $framework->setName($frameworkData->name);
     $framework->setDescription($frameworkData->description);
     $framework->setScale($scale);
     return $this->walkJsonNodes($frameworkData, $framework, $scale);
 }