/**
  * Find the mapped table for a foreign related class
  * @test
  */
 public function anyToManyRelationToForeignClassBuildsCorrectRelationTableName()
 {
     $domainObjectName1 = 'DomainObject1';
     $description = 'My long domain object description';
     $relationName = 'Relation1';
     $className = '\\TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser';
     $input = array('name' => $domainObjectName1, 'objectsettings' => array('description' => $description, 'aggregateRoot' => TRUE, 'type' => 'Entity'), 'relationGroup' => array('relations' => array(0 => array('relationName' => $relationName, 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => FALSE, 'foreignRelationClass' => $className))));
     $extbaseConfiguration = array('tableName' => 'fe_users');
     $this->configurationManager->expects($this->atLeastOnce())->method('getExtbaseClassConfiguration')->with($className)->will($this->returnValue($extbaseConfiguration));
     $domainObject1 = $this->objectSchemaBuilder->build($input);
     $relation = $domainObject1->getPropertyByName($relationName);
     $this->assertFalse($relation->getUseMMTable(), 'ZeroToMany Relation->getUseMMTable() returned TRUE.');
     $this->assertEquals('fe_users', $relation->getForeignDatabaseTableName());
 }
 /**
  * Write a simple model class for a non aggregate root domain obbject
  * @test
  */
 public function relatedMethodsReflectRenamingARelatedModel()
 {
     $modelName = 'Model8';
     $this->generateInitialModelClassFile($modelName);
     // create an "old" domainObject
     $domainObject = $this->buildDomainObject($modelName);
     self::assertTrue(is_object($domainObject), 'No domain object');
     $relationJsonConfiguration = array('lazyLoading' => 0, 'propertyIsExcludeField' => 1, 'relationDescription' => '', 'relationName' => 'children', 'relationType' => 'manyToMany');
     $relation = $this->objectSchemaBuilder->buildRelation($relationJsonConfiguration, $domainObject);
     $uniqueIdentifier1 = md5(microtime() . 'children');
     $relation->setUniqueIdentifier($uniqueIdentifier1);
     $relation->setForeignModel($this->buildDomainObject('ChildModel'));
     $domainObject->addProperty($relation);
     $uniqueIdentifier2 = md5(microtime() . 'Model8');
     $domainObject->setUniqueIdentifier($uniqueIdentifier2);
     $this->roundTripService->_set('previousDomainObjects', array($domainObject->getUniqueIdentifier() => $domainObject));
     // create an "old" class object.
     $modelClassObject = $this->classBuilder->generateModelClassFileObject($domainObject, $this->modelClassTemplatePath, false)->getFirstClass();
     self::assertTrue(is_object($modelClassObject), 'No class object');
     // Check that the property related methods exist
     self::assertTrue($modelClassObject->methodExists('setChildren'));
     self::assertTrue($modelClassObject->methodExists('getChildren'));
     self::assertTrue($modelClassObject->methodExists('addChild'));
     self::assertTrue($modelClassObject->methodExists('removeChild'));
     // set the class object manually, this is usually parsed
     // from an existing class file
     $this->roundTripService->_set('classObject', $modelClassObject);
     // build a new domain object with the same unique identifiers
     $newDomainObject = $this->buildDomainObject('Model8');
     $newRelation = $this->objectSchemaBuilder->buildRelation($relationJsonConfiguration, $domainObject);
     $newRelation->setUniqueIdentifier($uniqueIdentifier1);
     $newRelation->setForeignModel($this->buildDomainObject('RenamedModel'));
     $newRelation->setName('children');
     $newDomainObject->addProperty($newRelation);
     $newDomainObject->setUniqueIdentifier($uniqueIdentifier2);
     // now the class object should be updated
     $this->roundTripService->_call('updateModelClassProperties', $domainObject, $newDomainObject);
     $modifiedModelClassObject = $this->roundTripService->_get('classObject');
     $newAddMethod = $modifiedModelClassObject->getMethod('addChild');
     $parameters = $newAddMethod->getParameters();
     self::assertEquals(count($parameters), 1);
     $addParameter = current($parameters);
     self::assertEquals($addParameter->getTypeHint(), '\\EBT\\Dummy\\Domain\\Model\\RenamedModel');
     $newRemoveMethod = $modifiedModelClassObject->getMethod('removeChild');
     $parameters = $newRemoveMethod->getParameters();
     self::assertEquals(count($parameters), 1);
     $addParameter = current($parameters);
     self::assertEquals($addParameter->getTypeHint(), '\\EBT\\Dummy\\Domain\\Model\\RenamedModel');
 }
 /**
  *
  * @param array $extensionBuildConfiguration
  * @return \EBT\ExtensionBuilder\Domain\Model\Extension $extension
  */
 public function build(array $extensionBuildConfiguration)
 {
     /** @var $extension \EBT\ExtensionBuilder\Domain\Model\Extension */
     $extension = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Domain\\Model\\Extension');
     $globalProperties = $extensionBuildConfiguration['properties'];
     if (!is_array($globalProperties)) {
         \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Error: Extension properties not submitted! ' . $extension->getOriginalExtensionKey(), 'builder', 3, $globalProperties);
         throw new \Exception('Extension properties not submitted!');
     }
     $this->setExtensionProperties($extension, $globalProperties);
     if (is_array($globalProperties['persons'])) {
         foreach ($globalProperties['persons'] as $personValues) {
             $person = $this->buildPerson($personValues);
             $extension->addPerson($person);
         }
     }
     if (is_array($globalProperties['plugins'])) {
         foreach ($globalProperties['plugins'] as $pluginValues) {
             $plugin = $this->buildPlugin($pluginValues);
             $extension->addPlugin($plugin);
         }
     }
     if (is_array($globalProperties['backendModules'])) {
         foreach ($globalProperties['backendModules'] as $backendModuleValues) {
             $backendModule = $this->buildBackendModule($backendModuleValues);
             $extension->addBackendModule($backendModule);
         }
     }
     // classes
     if (is_array($extensionBuildConfiguration['modules'])) {
         foreach ($extensionBuildConfiguration['modules'] as $singleModule) {
             $domainObject = $this->objectSchemaBuilder->build($singleModule['value']);
             if ($domainObject->isSubClass() && !$domainObject->isMappedToExistingTable()) {
                 // we try to get the table from Extbase configuration
                 $classSettings = $this->configurationManager->getExtbaseClassConfiguration($domainObject->getParentClass());
                 if (isset($classSettings['tableName'])) {
                     $tableName = $classSettings['tableName'];
                 } else {
                     // we use the default table name
                     $tableName = \EBT\ExtensionBuilder\Utility\Tools::parseTableNameFromClassName($domainObject->getParentClass());
                 }
                 if (!isset($GLOBALS['TCA'][$tableName])) {
                     throw new \Exception('Table definitions for table ' . $tableName . ' could not be loaded. You can only map to tables with existing TCA or extend classes of installed extensions!');
                 }
                 $domainObject->setMapToTable($tableName);
             }
             $extension->addDomainObject($domainObject);
         }
         // add child objects - needed to generate correct TCA for inheritance
         foreach ($extension->getDomainObjects() as $domainObject1) {
             foreach ($extension->getDomainObjects() as $domainObject2) {
                 if ($domainObject2->getParentClass() === $domainObject1->getFullQualifiedClassName()) {
                     $domainObject1->addChildObject($domainObject2);
                 }
             }
         }
     }
     // relations
     if (is_array($extensionBuildConfiguration['wires'])) {
         $this->setExtensionRelations($extensionBuildConfiguration, $extension);
     }
     return $extension;
 }