Пример #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);
 }
Пример #2
0
 public function testSetLevels()
 {
     $scale = new Scale();
     $scale->setLevels(new ArrayCollection([$this->makeLevel('A', 1), $this->makeLevel('B', 2)]));
     $scale->setLevels(new ArrayCollection([$this->makeLevel('A', 1), $this->makeLevel('B', 2), $this->makeLevel('C', 3)]));
     $this->assertEquals(3, $scale->getLevels()->count());
 }
Пример #3
0
 protected function persistScale($name)
 {
     $scale = new Scale();
     $scale->setName($name);
     $this->om->persist($scale);
     return $scale;
 }
 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);
 }
Пример #5
0
 public function testSubmitValidData()
 {
     $scale = new Scale();
     $scale->setName('Scale 1');
     $om = $this->client->getContainer()->get('claroline.persistence.object_manager');
     $om->persist($scale);
     $om->flush();
     $formData = ['name' => 'Foo', 'description' => 'Foo...', 'scale' => $scale->getId()];
     $form = $this->factory->create(new FrameworkType());
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $framework = $form->getData();
     $this->assertInstanceOf('HeVinci\\CompetencyBundle\\Entity\\Competency', $framework);
     $this->assertEquals('Foo', $framework->getName());
     $this->assertEquals('Foo...', $framework->getDescription());
     $this->assertEquals($scale, $framework->getScale());
     $this->assertViewIsValid($form, $formData);
 }
Пример #6
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);
 }
Пример #7
0
 /**
  * Creates a default scale if no scale exists yet.
  */
 public function ensureHasScale()
 {
     if (!$this->hasScales()) {
         $defaultScale = new Scale();
         $defaultScale->setName($this->translator->trans('scale.default_name', [], 'competency'));
         $defaultLevel = new Level();
         $defaultLevel->setValue(0);
         $defaultLevel->setName($this->translator->trans('scale.default_level_name', [], 'competency'));
         $defaultScale->setLevels(new ArrayCollection([$defaultLevel]));
         $this->om->persist($defaultScale);
         $this->om->flush();
     }
 }