/**
  * @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.');
 }
 /**
  * Helper function to find the parents class recordType
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  * @return string
  */
 public function render(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject)
 {
     $classSettings = $this->configurationManager->getExtbaseClassConfiguration($domainObject->getParentClass());
     if (isset($classSettings['recordType'])) {
         $parentRecordType = $classSettings['recordType'];
     } else {
         $parentRecordType = str_replace('Domain_Model_', '', $domainObject->getParentClass());
         if (!isset($TCA[$domainObject->getDatabaseTableName()]['types'][$parentRecordType])) {
             $parentRecordType = 1;
         }
     }
     $this->templateVariableContainer->add('parentRecordType', $parentRecordType);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove('parentRecordType');
     return $content;
 }
 public function getForeignModelName()
 {
     if (is_object($this->foreignModel)) {
         return $this->foreignModel->getName();
     }
     $parts = explode('_Domain_Model_', $this->foreignClassName);
     return $parts[1];
 }
 /**
  * Add a domain object to the extension. Creates the reverse link as well.
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  */
 public function addDomainObject(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject)
 {
     $domainObject->setExtension($this);
     if (in_array($domainObject->getName(), array_keys($this->domainObjects))) {
         throw new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Duplicate domain object name "' . $domainObject->getName() . '".', Tx_ExtensionBuilder_Domain_Validator_ExtensionValidator::ERROR_DOMAINOBJECT_DUPLICATE);
     }
     if ($domainObject->getNeedsUploadFolder()) {
         $this->needsUploadFolder = TRUE;
     }
     $this->domainObjects[$domainObject->getName()] = $domainObject;
 }
 /**
  * Returns the current TCA for a domain objects table if the extension is installed
  * TODO: check for previous table name if an extension is renamed
  *
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  *
  * @return array
  */
 protected static function getTcaForDomainObject($domainObject, $extension)
 {
     $tableName = $domainObject->getDatabaseTableName();
     t3lib_div::loadTca($tableName);
     if (isset($GLOBALS['TCA'][$tableName])) {
         return $GLOBALS['TCA'][$tableName];
     } else {
         return NULL;
     }
 }
 private function validateDomainObjectActions(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject)
 {
     $actionNames = array();
     $actions = $domainObject->getActions();
     foreach ($actions as $action) {
         if (in_array($action->getName(), $actionNames)) {
             $this->validationResult['errors'][] = new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Duplicate action name "' . $action->getName() . '" of ' . $domainObject->getName() . '. Action names have to be unique for each model', self::ERROR_ACTIONNAME_DUPLICATE);
         }
         /**
          * Character test
          * Allowed characters are: a-z (lowercase), A-Z (uppercase) and 0-9
          */
         if (!preg_match("/^[a-zA-Z0-9]*\$/", $action->getName())) {
             $this->validationResult['errors'][] = new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Illegal action name "' . $action->getName() . '" of ' . $domainObject->getName() . '. Please use lowerCamelCase, no spaces or underscores.', self::ERROR_ACTIONNAME_ILLEGAL_CHARACTER);
         }
         $actionNames[] = $action->getName();
     }
     $this->validateDependentActions($actionNames, 'Domain object ' . $domainObject->getName());
     $firstAction = reset($actionNames);
     if ($firstAction == 'show' || $firstAction == 'edit' || $firstAction == 'delete') {
         $this->validationResult['warnings'][] = new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Potential misconfiguration in Domain object ' . $domainObject->getName() . ':<br />First action could not be default action since "' . $firstAction . '" action needs a parameter', self::ERROR_MISCONFIGURATION);
     }
 }
 /**
  * @test
  */
 public function conversionExtractsWholeExtensionMetadataWithRelations()
 {
     $input = array('modules' => array(0 => array('value' => array('name' => 'Blog', 'objectsettings' => array('description' => 'A blog object', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array(0 => array('propertyName' => 'name', 'propertyType' => 'String'), 1 => array('propertyName' => 'description', 'propertyType' => 'String'))), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'posts', 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => 1))))), 1 => array('value' => array('name' => 'Post', 'objectsettings' => array('description' => 'A blog post', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array()), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'comments', 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => 1))))), 2 => array('value' => array('name' => 'Comment', 'objectsettings' => array('description' => '', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array()), 'relationGroup' => array('relations' => array())))), 'properties' => array('description' => 'Some description', 'extensionKey' => $this->extensionKey, 'name' => 'My ext name', 'emConf' => array('state' => 'beta')), 'wires' => array(0 => array('tgt' => array('moduleId' => 1, 'terminal' => 'SOURCES'), 'src' => array('moduleId' => 0, 'terminal' => 'relationWire_0')), 1 => array('tgt' => array('moduleId' => 2, 'terminal' => 'SOURCES'), 'src' => array('moduleId' => 1, 'terminal' => 'relationWire_0'))));
     $extension = new Tx_ExtensionBuilder_Domain_Model_Extension();
     $extension->setName('My ext name');
     $extension->setState(Tx_ExtensionBuilder_Domain_Model_Extension::STATE_BETA);
     $extension->setExtensionKey($this->extensionKey);
     $extension->setDescription('Some description');
     $extension->setExtensionDir('');
     $blog = new Tx_ExtensionBuilder_Domain_Model_DomainObject();
     $blog->setName('Blog');
     $blog->setDescription('A blog object');
     $blog->setEntity(TRUE);
     $blog->setAggregateRoot(FALSE);
     $property = new Tx_ExtensionBuilder_Domain_Model_DomainObject_StringProperty('name');
     $blog->addProperty($property);
     $property = new Tx_ExtensionBuilder_Domain_Model_DomainObject_StringProperty('description');
     $blog->addProperty($property);
     $extension->addDomainObject($blog);
     $post = new Tx_ExtensionBuilder_Domain_Model_DomainObject();
     $post->setName('Post');
     $post->setDescription('A blog post');
     $post->setEntity(TRUE);
     $post->setAggregateRoot(FALSE);
     $extension->addDomainObject($post);
     $comment = new Tx_ExtensionBuilder_Domain_Model_DomainObject();
     $comment->setName('Comment');
     $comment->setDescription('');
     $comment->setEntity(TRUE);
     $comment->setAggregateRoot(FALSE);
     $extension->addDomainObject($comment);
     $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation('posts');
     $relation->setForeignModel($post);
     $relation->setExcludeField(1);
     $blog->addProperty($relation);
     $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation('comments');
     $relation->setForeignModel($comment);
     $relation->setExcludeField(1);
     $post->addProperty($relation);
     $actualExtension = $this->extensionSchemaBuilder->build($input);
     $this->assertEquals($extension->getDomainObjects(), $actualExtension->getDomainObjects(), 'The extensions differ');
 }
 /**
  * Not used right now
  * TODO: Needs better implementation
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  * @return void
  */
 public function sortMethods($domainObject)
 {
     $objectProperties = $domainObject->getProperties();
     $sortedProperties = array();
     $propertyRelatedMethods = array();
     $customMethods = array();
     // sort all properties and methods according to domainObject sort order
     foreach ($objectProperties as $objectProperty) {
         if ($this->classObject->propertyExists($objectProperty->getName())) {
             $sortedProperties[$objectProperty->getName()] = $this->classObject->getProperty($objectProperty->getName());
             $methodPrefixes = array('get', 'set', 'add', 'remove', 'is');
             foreach ($methodPrefixes as $methodPrefix) {
                 $methodName = $this->getMethodName($objectProperty, $methodPrefix);
                 if ($this->classObject->methodExists($methodName)) {
                     $propertyRelatedMethods[$methodName] = $this->classObject->getMethod($methodName);
                 }
             }
         }
     }
     // add the properties that were not in the domainObject
     $classProperties = $this->classObject->getProperties();
     $sortedPropertyNames = array_keys($sortedProperties);
     foreach ($classProperties as $classProperty) {
         if (!in_array($classProperty->getName(), $sortedProperties)) {
             $sortedProperties[$classProperty->getName()] = $classProperty;
         }
     }
     // add custom methods that were manually added to the class
     $classMethods = $this->classObject->getMethods();
     $propertyRelatedMethodNames = array_keys($propertyRelatedMethods);
     foreach ($classMethods as $classMethod) {
         if (!in_array($classMethod->getName(), $propertyRelatedMethodNames)) {
             $customMethods[$classMethod->getName()] = $classMethod;
         }
     }
     $sortedMethods = array_merge($customMethods, $propertyRelatedMethods);
     //t3lib_div::devlog('Methods after sorting', 'extension_builder', 0, array_keys($sortedMethods));
     $this->classObject->setProperties($sortedProperties);
     $this->classObject->setMethods($sortedMethods);
 }