/**
  * @test
  */
 public function changeVendorNameResultsInUpdatedTagsInModelClass()
 {
     $this->fixtureExtension->setOriginalVendorName('FIXTURE');
     $this->fixtureExtension->setVendorName('VENDOR');
     $modelClassFile = $this->roundTripService->getDomainModelClassFile($this->fixtureExtension->getDomainObjectByName('Main'));
     $modelClassObject = $modelClassFile->getFirstClass();
     $properties = $modelClassObject->getProperties();
     self::assertEquals('\\VENDOR\\TestExtension\\Domain\\Model\\Child1', $properties['child1']->getTagValue('var'));
     self::assertEquals('\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage<\\VENDOR\\TestExtension\\Domain\\Model\\Child2>', $properties['children2']->getTagValue('var'));
     self::assertEquals('\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage<\\VENDOR\\TestExtension\\Domain\\Model\\Child4>', $properties['children4']->getTagValue('var'));
 }
 /**
  * @param array $extensionBuildConfiguration
  * @param \EBT\ExtensionBuilder\Domain\Model\Extension $extension
  * @throws \Exception
  */
 protected function setExtensionRelations($extensionBuildConfiguration, &$extension)
 {
     $existingRelations = array();
     foreach ($extensionBuildConfiguration['wires'] as $wire) {
         if ($wire['tgt']['terminal'] !== 'SOURCES') {
             if ($wire['src']['terminal'] == 'SOURCES') {
                 // this happens if a relation wire was drawn from child to parent
                 // swap the two arrays
                 $tgtModuleId = $wire['src']['moduleId'];
                 $wire['src'] = $wire['tgt'];
                 $wire['tgt'] = array('moduleId' => $tgtModuleId, 'terminal' => 'SOURCES');
             } else {
                 throw new \Exception('A wire has always to connect a relation with a model, not with another relation');
             }
         }
         $srcModuleId = $wire['src']['moduleId'];
         $relationId = substr($wire['src']['terminal'], 13);
         // strip "relationWire_"
         $relationJsonConfiguration = $extensionBuildConfiguration['modules'][$srcModuleId]['value']['relationGroup']['relations'][$relationId];
         if (!is_array($relationJsonConfiguration)) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Error in JSON relation configuration!', 'extension_builder', 3, $extensionBuildConfiguration);
             $errorMessage = 'Missing relation config in domain object: ' . $extensionBuildConfiguration['modules'][$srcModuleId]['value']['name'];
             throw new \Exception($errorMessage);
         }
         $foreignModelName = $extensionBuildConfiguration['modules'][$wire['tgt']['moduleId']]['value']['name'];
         $localModelName = $extensionBuildConfiguration['modules'][$wire['src']['moduleId']]['value']['name'];
         if (!isset($existingRelations[$localModelName])) {
             $existingRelations[$localModelName] = array();
         }
         $domainObject = $extension->getDomainObjectByName($localModelName);
         $relation = $domainObject->getPropertyByName($relationJsonConfiguration['relationName']);
         if (!$relation) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Relation not found: ' . $localModelName . '->' . $relationJsonConfiguration['relationName'], 'extension_builder', 2, $relationJsonConfiguration);
             throw new \Exception('Relation not found: ' . $localModelName . '->' . $relationJsonConfiguration['relationName']);
         }
         // get unique foreign key names for multiple relations to the same foreign class
         if (in_array($foreignModelName, $existingRelations[$localModelName])) {
             if (is_a($relation, '\\EBT\\ExtensionBuilder\\Domain\\Model\\DomainObject\\Relation\\ZeroToManyRelation')) {
                 $relation->setForeignKeyName(strtolower($localModelName) . count($existingRelations[$localModelName]));
             }
             if (is_a($relation, '\\EBT\\ExtensionBuilder\\Domain\\Model\\DomainObject\\Relation\\AnyToManyRelation')) {
                 $relation->setUseExtendedRelationTableName(true);
             }
         }
         $existingRelations[$localModelName][] = $foreignModelName;
         if (!empty($relationJsonConfiguration['renderType'])) {
             $relation->setRenderType($relationJsonConfiguration['renderType']);
         }
         $relation->setForeignModel($extension->getDomainObjectByName($foreignModelName));
     }
 }
 /**
  * @param string $controllerName
  * @param array $actionNames
  * @param string $label related plugin or module
  * @param \EBT\ExtensionBuilder\Domain\Model\Extension $extension
  * @param bool $firstControllerAction
  * @return void
  */
 private function validateActionConfiguration($controllerName, $actionNames, $label, $extension, $firstControllerAction = FALSE)
 {
     if ($firstControllerAction) {
         // the first Controller action config is the default Controller action
         // we show a warning if that's an action that requires a domain object as parameter
         $defaultAction = reset($actionNames);
         if (in_array($defaultAction, array('show', 'edit'))) {
             GeneralUtility::devlog('Invalid action configurations', 'extension_builder', 1, array($controllerName, $actionNames));
             $this->validationResult['warnings'][] = new ExtensionException('Potential misconfiguration in ' . $label . ':' . LF . 'Default action ' . $controllerName . '->' . $defaultAction . '  can not be called without a domain object parameter', self::ERROR_ACTION_MISCONFIGURATION);
         }
     }
     $relatedDomainObject = $extension->getDomainObjectByName($controllerName);
     if (!$relatedDomainObject) {
         $this->validationResult['warnings'][] = new ExtensionException('Potential misconfiguration in ' . $label . ':' . LF . 'Controller ' . $controllerName . ' has no related Domain Object', self::ERROR_ACTION_MISCONFIGURATION);
     } else {
         $existingActions = $relatedDomainObject->getActions();
         $existingActionNames = array();
         foreach ($existingActions as $existingAction) {
             $existingActionNames[] = $existingAction->getName();
         }
         foreach ($actionNames as $actionName) {
             if (!in_array($actionName, $existingActionNames)) {
                 $this->validationResult['warnings'][] = new ExtensionException('Potential misconfiguration in ' . $label . ':' . LF . 'Controller ' . $controllerName . ' has no action named ' . $actionName, self::ERROR_ACTION_MISCONFIGURATION);
             }
         }
     }
 }