/**
  * @test
  */
 public function classBuilderGeneratesMethodsForRelationProperty()
 {
     $modelName2 = 'Model2';
     $propertyName = 'relNames';
     $domainObject1 = $this->buildDomainObject($this->modelName, true, true);
     $relatedDomainObject = $this->buildDomainObject($modelName2);
     $relationProperty = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ManyToManyRelation($propertyName);
     $relationProperty->setForeignModel($relatedDomainObject);
     $domainObject1->addProperty($relationProperty);
     $modelClassObject = $this->classBuilder->generateModelClassObject($domainObject1);
     $this->assertTrue($modelClassObject->methodExists('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))), 'Add method was not generated');
     $this->assertTrue($modelClassObject->methodExists('remove' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))), 'Remove method was not generated');
     $this->assertTrue($modelClassObject->methodExists('set' . ucfirst($propertyName)), 'Setter was not generated');
     $this->assertTrue($modelClassObject->methodExists('set' . ucfirst($propertyName)), 'Setter was not generated');
     $addMethod = $modelClassObject->getMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName)));
     $this->assertTrue($addMethod->isTaggedWith('param'), 'No param tag set for setter method');
     $paramTagValues = $addMethod->getTagsValues('param');
     $this->assertTrue(strpos($paramTagValues, $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues);
     $parameters = $addMethod->getParameters();
     $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in add method');
     $parameter = current($parameters);
     $this->assertTrue($parameter->getName() == Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName), 'Wrong parameter name in add method');
     $this->assertTrue($parameter->getTypeHint() == $relatedDomainObject->getClassName(), 'Wrong type hint for add method parameter:' . $parameter->getTypeHint());
 }
 /**
  * @depends writeModelClassWithManyToManyRelation
  * @depends writeAggregateRootClassesFromDomainObject
  *
  * TODO: A lot of more testing possible here (file content etc.) But this is in fact not a unit test anymore...
  *
  * @test
  */
 function writeExtensionFiles()
 {
     $modelName = 'ModelCgt8';
     $relatedModelName = 'RelatedModel';
     $propertyName = 'relNames';
     $domainObject = $this->buildDomainObject($modelName, true, true);
     $relatedDomainObject = $this->buildDomainObject($relatedModelName, true);
     $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ManyToManyRelation($propertyName);
     $relation->setForeignModel($relatedDomainObject);
     $relation->setInlineEditing(false);
     $domainObject->addProperty($relation);
     $this->extension->addDomainObject($domainObject);
     $this->extension->addDomainObject($relatedDomainObject);
     $plugin = new Tx_ExtensionBuilder_Domain_Model_Plugin();
     $plugin->setName('Test');
     $plugin->setKey('test');
     $this->extension->addPlugin($plugin);
     $this->codeGenerator->build($this->extension);
     $extensionDir = $this->extension->getExtensionDir();
     $extensionFiles = array('ext_emconf.php', 'ext_tables.php', 'ext_tables.sql', 'ext_localconf.php');
     foreach ($extensionFiles as $extensionFile) {
         $this->assertFileExists($extensionDir . $extensionFile, 'File was not generated: ' . $extensionFile);
     }
     $this->assertFileExists($extensionDir . 'Configuration/TCA/' . $domainObject->getName() . '.php');
     $this->assertFileExists($extensionDir . 'Configuration/ExtensionBuilder/settings.yaml');
     $this->assertFileExists($extensionDir . 'Resources/Private/Language/locallang_db.xml');
     $this->assertFileExists($extensionDir . 'Resources/Private/Language/locallang.xml');
     $this->assertFileExists($extensionDir . 'Resources/Private/Partials/' . $domainObject->getName() . '/Properties.html');
     $this->assertFileExists($extensionDir . 'Resources/Private/Partials/' . $domainObject->getName() . '/FormFields.html');
 }
 /**
  * @test
  */
 public function domainObjectHasExpectedRelations()
 {
     $name = 'MyDomainObject';
     $description = 'My long domain object description';
     $input = array('name' => $name, 'objectsettings' => array('description' => $description, 'aggregateRoot' => TRUE, 'type' => 'Entity'), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'relation 1', 'relationType' => 'manyToMany', 'propertyIsExcludeField' => FALSE, 'foreignRelationClass' => 'Tx_Extbase_Domain_Model_FrontendUser'), 1 => array('relationName' => 'relation 2', 'relationType' => 'manyToMany', 'propertyIsExcludeField' => FALSE, 'foreignRelationClass' => 'Tx_Extbase_Domain_Model_FrontendUser'))));
     $expected = new Tx_ExtensionBuilder_Domain_Model_DomainObject();
     $expected->setName($name);
     $expected->setDescription($description);
     $expected->setEntity(TRUE);
     $expected->setAggregateRoot(TRUE);
     $relation1 = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ManyToManyRelation('relation 1');
     $relation1->setForeignClassName('Tx_Extbase_Domain_Model_FrontendUser');
     $relation1->setRelatedToExternalModel(TRUE);
     $relation1->setExcludeField(FALSE);
     $relation1->setForeignDatabaseTableName('fe_users');
     $relation2 = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ManyToManyRelation('relation 2');
     $relation2->setForeignClassName('Tx_Extbase_Domain_Model_FrontendUser');
     $relation2->setRelatedToExternalModel(TRUE);
     $relation2->setExcludeField(FALSE);
     $relation2->setForeignDatabaseTableName('fe_users');
     $expected->addProperty($relation1);
     $expected->addProperty($relation2);
     $actual = $this->objectSchemaBuilder->build($input);
     $this->assertEquals($actual, $expected, 'Domain Object not built correctly.');
 }