public function testOneToManyWhenUnidirectionalRelationToBeCreated() { $selfRelations = ['oneToMany|Test\\SourceEntity|Test\\TargetEntity|rel_otm' => ['field_id' => $this->getFieldId('Test\\SourceEntity', 'rel_otm', 'oneToMany'), 'owner' => false, 'target_entity' => 'Test\\TargetEntity', 'target_field_id' => $this->getFieldId('Test\\TargetEntity', 'sourceentity_rel_otm', 'manyToOne')]]; $targetRelations = ['oneToMany|Test\\SourceEntity|Test\\TargetEntity|rel_otm' => ['field_id' => $this->getFieldId('Test\\TargetEntity', 'sourceentity_rel_otm', 'manyToOne'), 'owner' => true, 'target_entity' => 'Test\\SourceEntity', 'target_field_id' => $this->getFieldId('Test\\SourceEntity', 'rel_otm', 'oneToMany')]]; $selfConfig = $this->addEntityConfig(['is_extend' => true, 'state' => ExtendScope::STATE_ACTIVE], 'Test\\SourceEntity'); $this->addConfigNewField(['target_entity' => 'Test\\TargetEntity', 'relation_key' => 'oneToMany|Test\\SourceEntity|Test\\TargetEntity|rel_otm'], 'oneToMany', 'Test\\SourceEntity', 'rel_otm'); $targetConfig = $this->addEntityConfig(['is_extend' => true, 'state' => ExtendScope::STATE_ACTIVE], 'Test\\TargetEntity'); $this->extension->preUpdate(); $this->assertEquals($selfRelations, $selfConfig->get('relation')); $this->assertEquals($targetRelations, $targetConfig->get('relation')); }
/** * Test create new field (relation type [*:*]) */ public function testCreateTargetRelationManyToMany() { $config = new Config(new EntityConfigId('extend', 'TestClass')); $config->set('is_extend', true); $fieldsConfigs = [$this->getConfigNewField(['target_entity' => 'Oro\\Bundle\\UserBundle\\Entity\\User', 'target_title' => ['username'], 'target_grid' => ['username'], 'target_detailed' => ['username'], 'relation_key' => 'manyToMany|TestClass|Oro\\Bundle\\UserBundle\\Entity\\User|testFieldName'], 'manyToMany')]; $relation = ['manyToMany|TestClass|Oro\\Bundle\\UserBundle\\Entity\\User|testFieldName' => ['assign' => true, 'owner' => true, 'target_entity' => 'Oro\\Bundle\\UserBundle\\Entity\\User', 'field_id' => new FieldConfigId('extend', 'TestClass', 'testFieldName', 'manyToMany')]]; $selfConfig = $this->getEntityConfig(['state' => ExtendScope::STATE_ACTIVE, 'relation' => []]); $targetConfig = $this->getEntityConfig(['state' => ExtendScope::STATE_ACTIVE, 'relation' => $relation], 'extend', 'Oro\\Bundle\\UserBundle\\Entity\\User'); $this->extendConfigProvider->expects($this->any())->method('getConfigs')->will($this->returnValueMap([[null, false, [$config]], ['TestClass', false, $fieldsConfigs]])); $this->extendConfigProvider->expects($this->any())->method('getConfig')->will($this->returnValueMap([['TestClass', null, $selfConfig], ['Oro\\Bundle\\UserBundle\\Entity\\User', null, $targetConfig]])); $this->extension->preUpdate(); // setup expected relation array $relationKey = 'manyToMany|TestClass|Oro\\Bundle\\UserBundle\\Entity\\User|testFieldName'; $relation[$relationKey]['target_field_id'] = $relation[$relationKey]['field_id']; $this->assertEquals($relation, $targetConfig->get('relation')); $this->assertEquals($relation, $targetConfig->get('relation')); }