Beispiel #1
0
 /**
  * @dataProvider setNameProvider
  */
 public function testSetName($sourceName, $expected)
 {
     // Arrange
     $a = new NodeType();
     $a->setName($sourceName);
     // Assert
     $this->assertEquals($expected, $a->getName());
 }
 public function serializeToJsonProvider()
 {
     // Node type #1
     $nt1 = new NodeType();
     $nt1->setName('page type');
     // Node type #2
     $nt2 = new NodeType();
     $nt2->setName('blog post');
     $nt2->setDisplayName('Un blog post');
     $ntf1 = new NodeTypeField();
     $ntf1->setName('Title');
     $ntf1->setType(NodeTypeField::MARKDOWN_T);
     $nt2->addField($ntf1);
     return array(array(new NodeType(), ROADIZ_ROOT . '/tests/Fixtures/Handlers/nodeTypeHandler01.json'), array($nt1, ROADIZ_ROOT . '/tests/Fixtures/Handlers/nodeTypeHandler02.json'), array($nt2, ROADIZ_ROOT . '/tests/Fixtures/Handlers/nodeTypeHandler03.json'));
 }
 private function executeCreation(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $nt = new NodeType();
     $nt->setName($name);
     $question0 = new Question('<question>Enter your node-type display name</question>: ', 'Neutral');
     $displayName = $this->questionHelper->ask($input, $output, $question0);
     $nt->setDisplayName($displayName);
     $question1 = new Question('<question>Enter your node-type description</question>: ', '');
     $description = $this->questionHelper->ask($input, $output, $question1);
     $nt->setDescription($description);
     $this->entityManager->persist($nt);
     $i = 1;
     while (true) {
         // Fields
         $field = new NodeTypeField();
         $field->setPosition($i);
         $questionfName = new Question('<question>[Field ' . $i . '] Enter field name</question>: ', 'content');
         $fName = $this->questionHelper->ask($input, $output, $questionfName);
         $field->setName($fName);
         $questionfLabel = new Question('<question>[Field ' . $i . '] Enter field label</question>: ', 'Your content');
         $fLabel = $this->questionHelper->ask($input, $output, $questionfLabel);
         $field->setLabel($fLabel);
         $questionfType = new Question('<question>[Field ' . $i . '] Enter field type</question>: ', 'MARKDOWN_T');
         $fType = $this->questionHelper->ask($input, $output, $questionfType);
         $fType = constant('RZ\\Roadiz\\Core\\Entities\\NodeTypeField::' . $fType);
         $field->setType($fType);
         $questionIndexed = new ConfirmationQuestion('<question>[Field ' . $i . '] Must field be indexed?</question>: ', false);
         if ($this->questionHelper->ask($input, $output, $questionIndexed)) {
             $field->setIndexed(true);
         }
         // Need to populate each side
         $nt->getFields()->add($field);
         $this->entityManager->persist($field);
         $field->setNodeType($nt);
         $questionAdd = new ConfirmationQuestion('<question>Do you want to add another field?</question>: ', true);
         if (!$this->questionHelper->ask($input, $output, $questionAdd)) {
             break;
         }
         $i++;
     }
     $this->entityManager->flush();
     $nt->getHandler()->regenerateEntityClass();
     $success = '<question>Node type ' . $nt->getName() . ' has been created.</question>' . PHP_EOL . '<info>Do not forget to update database schema!</info>';
     return $success;
 }