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