/** * @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 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()); }