public function testLoadMetadataForClassWithProperties() { $dataMap = new Tx_Extbase_Persistence_Mapper_DataMap('Tx_Doctrine2_Tests_Model_Post', 'posts'); $column = new Tx_Extbase_Persistence_Mapper_ColumnMap('post_headline', 'headline'); $column->setTypeOfRelation(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_NONE); $dataMap->addColumnMap($column); $this->metadataService->expects($this->once())->method('getDataMap')->will($this->returnValue($dataMap)); $metadata = $this->loadClassMetadata('Tx_Doctrine2_Tests_Model_Post'); $this->assertEquals('posts', $metadata->getTableName()); $this->assertEquals(array(), $metadata->identifier, 'No identifier, this this inherited from abstract class'); $this->assertEquals(array('post_headline' => 'headline'), $metadata->fieldNames); }
/** * This method sets the configuration for a m:n relation based on * the $TCA column configuration * * @param string $columnMap The column map * @param string $columnConfiguration The column configuration from $TCA * @return void */ protected function setManyToManyRelation(Tx_Extbase_Persistence_Mapper_ColumnMap $columnMap, $columnConfiguration) { $columnMap->setTypeOfRelation(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY); if (isset($columnConfiguration['MM'])) { $columnMap->setChildTableName($columnConfiguration['foreign_table']); $columnMap->setChildTableWhereStatement($columnConfiguration['foreign_table_where']); $columnMap->setRelationTableName($columnConfiguration['MM']); if (is_array($columnConfiguration['MM_match_fields'])) { $columnMap->setRelationTableMatchFields($columnConfiguration['MM_match_fields']); } if (is_array($columnConfiguration['MM_insert_fields'])) { $columnMap->setRelationTableInsertFields($columnConfiguration['MM_insert_fields']); } $columnMap->setRelationTableWhereStatement($columnConfiguration['MM_table_where']); if (!empty($columnConfiguration['MM_opposite_field'])) { $columnMap->setParentKeyFieldName('uid_foreign'); $columnMap->setChildKeyFieldName('uid_local'); $columnMap->setChildSortByFieldName('sorting_foreign'); } else { $columnMap->setParentKeyFieldName('uid_local'); $columnMap->setChildKeyFieldName('uid_foreign'); $columnMap->setChildSortByFieldName('sorting'); } } elseif (isset($columnConfiguration['foreign_selector'])) { $columns = $this->getColumnsDefinition($columnConfiguration['foreign_table']); $childKeyFieldName = $columnConfiguration['foreign_selector']; $columnMap->setChildTableName($columns[$childKeyFieldName]['config']['foreign_table']); $columnMap->setRelationTableName($columnConfiguration['foreign_table']); $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field']); $columnMap->setChildKeyFieldName($childKeyFieldName); $columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby']); } else { throw new Tx_Extbase_Persistence_Exception_UnsupportedRelation('The given information to build a many-to-many-relation was not sufficient. Check your TCA definitions. mm-relations with IRRE must have at least a defined "MM" or "foreign_selector".', 1268817963); } if ($this->getControlSection($columnMap->getRelationTableName()) !== NULL) { $columnMap->setRelationTablePageIdColumnName('pid'); } return $columnMap; }