public function testGetEntities()
 {
     $entityConfig = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMock();
     $entityConfig->expects($this->at(0))->method('get')->with('label')->will($this->returnValue('SomeLabel'));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with('SomeClass')->will($this->returnValue(true));
     $this->entityConfigProvider->expects($this->once())->method('getConfig')->with('SomeClass')->will($this->returnValue($entityConfig));
     $securityConfigId = new EntityConfigId('security', 'SomeClass');
     $securityConfig = new Config($securityConfigId);
     $securityConfig->set('type', Provider::ACL_SECURITY_TYPE);
     $securityConfig->set('permissions', 'All');
     $securityConfig->set('group_name', 'SomeGroup');
     $securityConfigs = array($securityConfig);
     $this->securityConfigProvider->expects($this->any())->method('getConfigs')->will($this->returnValue($securityConfigs));
     $this->cache->expects($this->at(0))->method('fetch')->with(Provider::ACL_SECURITY_TYPE)->will($this->returnValue(false));
     $this->cache->expects($this->at(2))->method('fetch')->with(Provider::ACL_SECURITY_TYPE)->will($this->returnValue(array('SomeClass' => $this->entity)));
     $this->cache->expects($this->once())->method('save')->with(Provider::ACL_SECURITY_TYPE, array('SomeClass' => $this->entity));
     $provider = new Provider($this->securityConfigProvider, $this->entityConfigProvider, $this->extendConfigProvider, $this->cache);
     // call without cache
     $result = $provider->getEntities();
     $this->assertCount(1, $result);
     $this->assertContainsOnlyInstancesOf('Oro\\Bundle\\SecurityBundle\\Metadata\\EntitySecurityMetadata', $result);
     $this->assertEquals(serialize($result), serialize(array($this->entity)));
     // call with local cache
     $result = $provider->getEntities();
     $this->assertCount(1, $result);
     $this->assertContainsOnlyInstancesOf('Oro\\Bundle\\SecurityBundle\\Metadata\\EntitySecurityMetadata', $result);
     $this->assertEquals(serialize($result), serialize(array($this->entity)));
     // call with cache
     $provider = new Provider($this->securityConfigProvider, $this->entityConfigProvider, $this->extendConfigProvider, $this->cache);
     $result = $provider->getEntities();
     $this->assertCount(1, $result);
     $this->assertContains($this->entity, $result);
 }
 public function testGetMetadataSetsOrganizationFieldName()
 {
     $configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $provider = new OwnershipMetadataProvider(array('organization' => 'AcmeBundle\\Entity\\Organization', 'business_unit' => 'AcmeBundle\\Entity\\BusinessUnit', 'user' => 'AcmeBundle\\Entity\\User'), $configProvider, null);
     $config = new Config(new EntityConfigId('ownership', 'SomeClass'));
     $config->set('owner_type', 'ORGANIZATION');
     $config->set('owner_field_name', 'test_field');
     $config->set('owner_column_name', 'test_column');
     $configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo('SomeClass'))->will($this->returnValue(true));
     $configProvider->expects($this->once())->method('getConfig')->with($this->equalTo('SomeClass'))->will($this->returnValue($config));
     $this->assertEquals(new OwnershipMetadata('ORGANIZATION', 'test_field', 'test_column', 'test_field', 'test_column'), $provider->getMetadata('SomeClass'));
 }
 public function testFlush()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $model = new EntityConfigModel(self::ENTITY_CLASS);
     $entityConfigId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $entityConfig = new Config($entityConfigId);
     $entityConfig->set('icon', 'test_icon');
     $entityConfig->set('label', 'test_label');
     $entityPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['icon' => [], 'label' => ['options' => ['indexed' => true]]]]], $container);
     $this->entityConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($entityPropertyConfig));
     $testConfigId = new EntityConfigId('test', self::ENTITY_CLASS);
     $testConfig = new Config($testConfigId);
     $testConfig->set('attr1', 'test_attr1');
     $testPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['attr1' => []]]], $container);
     $this->testConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($testPropertyConfig));
     $this->modelManager->expects($this->once())->method('getEntityModel')->with($entityConfigId->getClassName())->will($this->returnValue($model));
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->modelManager->expects($this->any())->method('getEntityManager')->will($this->returnValue($em));
     $this->setFlushExpectations($em, [$model]);
     $this->eventDispatcher->expects($this->at(0))->method('dispatch')->with(Events::PRE_PERSIST_CONFIG, new PersistConfigEvent($entityConfig, $this->configManager));
     $this->eventDispatcher->expects($this->at(1))->method('dispatch')->with(Events::PRE_PERSIST_CONFIG, new PersistConfigEvent($testConfig, $this->configManager));
     $this->configManager->persist($entityConfig);
     $this->configManager->persist($testConfig);
     $this->configManager->flush();
     $this->assertEquals(['icon' => 'test_icon', 'label' => 'test_label'], $model->toArray('entity'));
     $this->assertEquals(['attr1' => 'test_attr1'], $model->toArray('test'));
     $this->assertCount(3, $model->getIndexedValues());
     $this->assertEquals('entity_config', $model->getIndexedValues()[0]->getScope());
     $this->assertEquals('module_name', $model->getIndexedValues()[0]->getCode());
     $this->assertEquals('entity_config', $model->getIndexedValues()[1]->getScope());
     $this->assertEquals('entity_name', $model->getIndexedValues()[1]->getCode());
     $this->assertEquals('entity', $model->getIndexedValues()[2]->getScope());
     $this->assertEquals('label', $model->getIndexedValues()[2]->getCode());
 }
 public function testResolve()
 {
     $route = new Route('/{activity}/route', [], [], ['group' => ActivityAssociationRouteOptionsResolver::ROUTE_GROUP]);
     $this->routeCollection->add('first_route', new Route('/first_route'));
     $this->routeCollection->add('override_before', new Route('/events/route'));
     $this->routeCollection->add('some_route', new Route('/some_route'));
     $this->routeCollection->add('tested_route', $route);
     $this->routeCollection->add('override_after', new Route('/emails/route'));
     $this->routeCollection->add('last_route', new Route('/last_route'));
     $config1 = new Config(new EntityConfigId('grouping', 'Test\\Email'));
     $config1->set('groups', ['activity']);
     $config2 = new Config(new EntityConfigId('grouping', 'Test\\Call'));
     $config2->set('groups', ['test', 'activity']);
     $config3 = new Config(new EntityConfigId('grouping', 'Test\\Task'));
     $config3->set('groups', ['activity']);
     $config4 = new Config(new EntityConfigId('grouping', 'Test\\Message'));
     $config5 = new Config(new EntityConfigId('grouping', 'Test\\Event'));
     $config5->set('groups', ['activity']);
     $this->groupingConfigProvider->expects($this->once())->method('getConfigs')->with(null, false)->willReturn([$config1, $config2, $config3, $config4, $config5]);
     $this->entityAliasResolver->expects($this->exactly(4))->method('getPluralAlias')->willReturnMap([['Test\\Email', 'emails'], ['Test\\Call', 'calls'], ['Test\\Task', 'tasks'], ['Test\\Event', 'events']]);
     $this->routeOptionsResolver->resolve($route, $this->routeCollectionAccessor);
     $this->assertEquals(['activity' => '\\w+'], $route->getRequirements());
     $this->routeCollection->sortByPriority();
     $this->assertEquals(['first_route', 'some_route', 'override_after', 'tested_route_auto_7', 'tested_route_auto_8', 'override_before', 'tested_route', 'last_route'], array_keys($this->routeCollection->all()));
     $this->assertEquals('\\w+', $this->routeCollection->get('tested_route')->getRequirement('activity'));
     $this->assertEquals('calls', $this->routeCollection->get('tested_route_auto_7')->getDefault('activity'));
     $this->assertEquals('tasks', $this->routeCollection->get('tested_route_auto_8')->getDefault('activity'));
 }
 public function testResolve()
 {
     $route = new Route('/{activity}/route', [], [], ['group' => 'activity_association']);
     $this->routeCollection->add('first_route', new Route('/first_route'));
     $this->routeCollection->add('override1', new Route('/notes/route'));
     $this->routeCollection->add('some_route', new Route('/some_route'));
     $this->routeCollection->add('tested_route', $route);
     $this->routeCollection->add('override2', new Route('/emails/route'));
     $this->routeCollection->add('last_route', new Route('/last_route'));
     $config1 = new Config(new EntityConfigId('grouping', 'Test\\Email'));
     $config1->set('groups', ['activity']);
     $config2 = new Config(new EntityConfigId('grouping', 'Test\\Call'));
     $config2->set('groups', ['test', 'activity']);
     $config3 = new Config(new EntityConfigId('grouping', 'Test\\Message'));
     $config4 = new Config(new EntityConfigId('grouping', 'Test\\Note'));
     $config4->set('groups', ['activity']);
     $this->groupingConfigProvider->expects($this->once())->method('getConfigs')->with(null, false)->willReturn([$config1, $config2, $config3, $config4]);
     $this->entityAliasResolver->expects($this->exactly(3))->method('getPluralAlias')->willReturnMap([['Test\\Email', 'emails'], ['Test\\Call', 'calls'], ['Test\\Note', 'notes']]);
     $this->routeOptionsResolver->resolve($route, $this->routeCollectionAccessor);
     $this->assertEquals(['activity' => 'emails|calls|notes'], $route->getRequirements());
     $this->routeCollection->sortByPriority();
     $this->assertEquals(['first_route', 'some_route', 'override2', 'tested_route_auto_7', 'override1', 'tested_route', 'last_route'], array_keys($this->routeCollection->all()));
     $this->assertEquals('emails|calls|notes', $this->routeCollection->get('tested_route')->getRequirement('activity'));
     $this->assertEquals('calls', $this->routeCollection->get('tested_route_auto_7')->getDefault('activity'));
 }
 /**
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function getExtendConfigMock()
 {
     $extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $config1 = new Config(new EntityConfigId('extend', self::ENTITY_NAMESPACE . '\\TestEntity1'));
     $config2 = new Config(new EntityConfigId('extend', self::ENTITY_NAMESPACE . '\\TestEntity2'));
     $config3 = new Config(new EntityConfigId('extend', self::ENTITY_NAMESPACE . '\\TestEntity3'));
     $newCustomEntityConfig = new Config(new EntityConfigId('extend', ExtendHelper::ENTITY_NAMESPACE . '\\TestEntity4'));
     $newCustomEntityConfig->set('state', ExtendScope::STATE_NEW);
     $toBeDeletedCustomEntityConfig = new Config(new EntityConfigId('extend', ExtendHelper::ENTITY_NAMESPACE . '\\TestEntity5'));
     $toBeDeletedCustomEntityConfig->set('state', ExtendScope::STATE_DELETE);
     $deletedCustomEntityConfig = new Config(new EntityConfigId('extend', ExtendHelper::ENTITY_NAMESPACE . '\\TestEntity6'));
     $deletedCustomEntityConfig->set('state', ExtendScope::STATE_ACTIVE);
     $deletedCustomEntityConfig->set('is_deleted', true);
     $entityConfigs = [$config1, $config2, $config3, $newCustomEntityConfig, $toBeDeletedCustomEntityConfig, $deletedCustomEntityConfig];
     $extendConfigProvider->expects($this->once())->method('getConfigs')->will($this->returnValue($entityConfigs));
     return $extendConfigProvider;
 }
 public function testIsEntityAuditable()
 {
     $config = new Config(new EntityConfigId('dataaudit', self::TEST_ENTITY_REFERENCE));
     $config->set('auditable', true);
     $this->configProvider->expects($this->once())->method('hasConfig')->with(self::TEST_ENTITY_REFERENCE)->will($this->returnValue(true));
     $this->configProvider->expects($this->once())->method('getConfig')->with(self::TEST_ENTITY_REFERENCE)->will($this->returnValue($config));
     $this->assertTrue($this->filter->isEntityAuditable(new LoggableClass(), false));
 }
 public function testSupportsForNotActivityEntity()
 {
     $config = new Config(new EntityConfigId('grouping', 'Test\\Entity'));
     $config->set('groups', ['another_group']);
     $this->groupingConfigProvider->expects($this->once())->method('hasConfig')->with('Test\\Entity')->will($this->returnValue(true));
     $this->groupingConfigProvider->expects($this->once())->method('getConfig')->with('Test\\Entity')->will($this->returnValue($config));
     $this->assertFalse($this->extension->supports(['class' => 'Test\\Entity']));
 }
 public function testPrePersistEntityConfigWithNoneOwnership()
 {
     $config = new Config(new EntityConfigId('ownership', 'Test\\Entity1'));
     $config->set('owner_type', 'NONE');
     $expectedConfig = new Config(new EntityConfigId('ownership', 'Test\\Entity1'));
     $this->configManager->expects($this->once())->method('persist')->with($expectedConfig);
     $this->configManager->expects($this->once())->method('calculateConfigChangeSet')->with($expectedConfig);
     $this->subscriber->prePersistEntityConfig(new PersistConfigEvent($config, $this->configManager));
 }
 public function testIsNoteAssociationEnabled()
 {
     $config = new Config(new EntityConfigId('note', static::TEST_ENTITY_REFERENCE));
     $config->set('enabled', true);
     $this->noteConfigProvider->expects($this->once())->method('hasConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue(true));
     $this->noteConfigProvider->expects($this->once())->method('getConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue($config));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(Note::ENTITY_NAME, ExtendHelper::buildAssociationName(static::TEST_ENTITY_REFERENCE))->will($this->returnValue(true));
     $this->assertTrue($this->filter->isNoteAssociationEnabled(new TestEntity(1)));
 }
 public function testIsAttachmentAssociationEnabled()
 {
     $config = new Config(new EntityConfigId('attachment', 'stdClass'));
     $config->set('enabled', true);
     $this->attachmentConfigProvider->expects($this->once())->method('hasConfig')->with('stdClass')->will($this->returnValue(true));
     $this->attachmentConfigProvider->expects($this->once())->method('getConfig')->with('stdClass')->will($this->returnValue($config));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(AttachmentScope::ATTACHMENT, ExtendHelper::buildAssociationName('stdClass'))->will($this->returnValue(true));
     $this->assertTrue($this->filter->isAttachmentAssociationEnabled(new \stdClass()));
 }
 public function testGetMetadataWithoutCache()
 {
     $config = new Config(new EntityConfigId('ownership', 'SomeClass'));
     $config->set('frontend_owner_type', 'USER')->set('frontend_owner_field_name', 'test_field')->set('frontend_owner_column_name', 'test_column');
     $this->configProvider->expects($this->once())->method('hasConfig')->with('SomeClass')->willReturn(true);
     $this->configProvider->expects($this->once())->method('getConfig')->with('SomeClass')->willReturn($config);
     $this->cache = null;
     $this->assertEquals(new FrontendOwnershipMetadata('USER', 'test_field', 'test_column'), $this->provider->getMetadata('SomeClass'));
 }
 public function testIsNoteAssociationEnabledForEnabledButNotAccessibleAssociationButWithAccessibleFalse()
 {
     $entityClass = 'Test\\Entity';
     $config = new Config(new EntityConfigId('note', $entityClass));
     $config->set('enabled', true);
     $this->configManager->expects($this->once())->method('hasConfig')->with($entityClass)->willReturn(true);
     $this->configManager->expects($this->once())->method('getEntityConfig')->with('note', $entityClass)->willReturn($config);
     $this->configManager->expects($this->never())->method('getFieldConfig');
     $this->assertTrue($this->noteAssociationHelper->isNoteAssociationEnabled($entityClass, false));
 }
 /**
  * Test new index created and old deleted when field renamed
  */
 public function testRenameField()
 {
     $entityConfig = new Config(new EntityConfigId('extend', self::ENTITY_CLASS_NAME));
     $entityConfig->set('index', ['testField' => ['testField']]);
     $this->configProvider->expects($this->once())->method('getConfig')->with(self::ENTITY_CLASS_NAME)->will($this->returnValue($entityConfig));
     $event = new RenameFieldEvent(self::ENTITY_CLASS_NAME, 'testField', 'newName', $this->configManager);
     $listener = new EntityConfigListener();
     $listener->renameField($event);
     $this->assertEquals(['newName' => ['testField']], $entityConfig->get('index'));
 }
 public function testIsApplicable()
 {
     $config = new Config(new EntityConfigId('comment', static::TEST_ENTITY_REFERENCE));
     $config->set('enabled', true);
     $this->securityFacade->expects($this->once())->method('isGranted')->with('oro_comment_view')->willReturn(true);
     $this->commentConfigProvider->expects($this->once())->method('hasConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue(true));
     $this->commentConfigProvider->expects($this->once())->method('getConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue($config));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(Comment::ENTITY_NAME, ExtendHelper::buildAssociationName(static::TEST_ENTITY_REFERENCE))->will($this->returnValue(true));
     $this->assertTrue($this->filter->isApplicable(new TestEntity()));
 }
 protected function initialize($className)
 {
     $metadata = $this->getClassMetadata(['enumField', 'multiEnumField', 'nonConfigurableField']);
     $enumFieldConfig = new Config(new FieldConfigId('extend', $className, 'enumField', 'enum'));
     $enumFieldConfig->set('target_field', 'targetField');
     $multiEnumFieldConfig = new Config(new FieldConfigId('extend', $className, 'multiEnumField', 'multiEnum'));
     $this->em->expects($this->once())->method('getClassMetadata')->with($className)->will($this->returnValue($metadata));
     $this->extendConfigProvider->expects($this->exactly(3))->method('hasConfig')->will($this->returnValueMap([[$className, 'enumField', true], [$className, 'multiEnumField', true], [$className, 'nonConfigurableField', false]]));
     $this->extendConfigProvider->expects($this->exactly(2))->method('getConfig')->will($this->returnValueMap([[$className, 'enumField', $enumFieldConfig], [$className, 'multiEnumField', $multiEnumFieldConfig]]));
 }
Beispiel #17
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetEntities()
 {
     $entityClassName1 = 'Acme\\Entity\\Test1';
     $entityClassName2 = 'Acme\\Entity\\Test2';
     $entityClassName3 = 'Acme\\Entity\\Test3';
     $entityClassName4 = 'Acme\\Entity\\Test4';
     $entityClassName5 = 'Acme\\Entity\\Test5';
     $entityConfig1 = $this->getEntityConfig($entityClassName1, ['label' => 'C', 'plural_label' => 'B', 'icon' => 'icon-test1']);
     $entityConfig2 = $this->getEntityConfig($entityClassName2, ['label' => 'B', 'plural_label' => 'A', 'icon' => 'icon-test2']);
     $entityConfig3 = $this->getEntityConfig($entityClassName3, ['label' => 'A', 'plural_label' => 'C', 'icon' => 'icon-test3']);
     $entityConfig4 = $this->getEntityConfig($entityClassName4, ['label' => 'A', 'plural_label' => 'C', 'icon' => 'icon-test3']);
     $entityConfig5 = $this->getEntityConfig($entityClassName5, ['label' => 'A', 'plural_label' => 'C', 'icon' => 'icon-test3']);
     $map = [$entityClassName1 => $entityConfig1, $entityClassName2 => $entityConfig2, $entityClassName3 => $entityConfig3, $entityClassName4 => $entityConfig4, $entityClassName5 => $entityConfig5];
     $this->extendConfigProvider->expects($this->any())->method('getConfigById')->will($this->returnCallback(function (EntityConfigId $configId) use($map) {
         $className = $configId->getClassName();
         /** @var ConfigInterface $config */
         $config = $map[$className];
         $config->set('state', ExtendScope::STATE_ACTIVE);
         return $config;
     }));
     $this->entityConfigProvider->expects($this->any())->method('getConfig')->will($this->returnValueMap([[$entityClassName1, $entityConfig1], [$entityClassName2, $entityConfig2], [$entityClassName3, $entityConfig3], [$entityClassName4, $entityConfig4], [$entityClassName5, $entityConfig5]]));
     $this->entityConfigProvider->expects($this->any())->method('getConfigs')->will($this->returnValue([$entityConfig1, $entityConfig2, $entityConfig3]));
     $this->extendConfigProvider->expects($this->any())->method('getConfig')->will($this->returnCallback(function ($param) {
         $this->extendConfig->set('state', ExtendScope::STATE_ACTIVE);
         if ($param == 'Acme\\Entity\\Test4') {
             $this->extendConfig->set('state', ExtendScope::STATE_NEW);
         }
         if ($param == 'Acme\\Entity\\Test4') {
             $this->extendConfig->set('state', ExtendScope::STATE_DELETE);
         }
         return $this->extendConfig;
     }));
     $this->extendConfigProvider->expects($this->any())->method('getConfig')->will($this->returnValue($this->extendConfig));
     // sort by plural label
     $result = $this->provider->getEntities();
     $expected = [['name' => $entityClassName2, 'label' => 'B', 'plural_label' => 'A', 'icon' => 'icon-test2'], ['name' => $entityClassName1, 'label' => 'C', 'plural_label' => 'B', 'icon' => 'icon-test1'], ['name' => $entityClassName3, 'label' => 'A', 'plural_label' => 'C', 'icon' => 'icon-test3']];
     $this->assertEquals($expected, $result);
     // sort by label
     $result = $this->provider->getEntities(false);
     $expected = [['name' => $entityClassName3, 'label' => 'A', 'plural_label' => 'C', 'icon' => 'icon-test3'], ['name' => $entityClassName2, 'label' => 'B', 'plural_label' => 'A', 'icon' => 'icon-test2'], ['name' => $entityClassName1, 'label' => 'C', 'plural_label' => 'B', 'icon' => 'icon-test1']];
     $this->assertEquals($expected, $result);
 }
 public function testValueConfig()
 {
     $values = array('firstKey' => 'firstValue', 'secondKey' => 'secondValue', 'fourthKey' => new \stdClass());
     $this->config->setValues($values);
     $this->assertEquals($values, $this->config->all());
     $this->assertEquals(array('firstKey' => 'firstValue'), $this->config->all(function ($value) {
         return $value == 'firstValue';
     }));
     $this->assertEquals('firstValue', $this->config->get('firstKey'));
     $this->assertEquals('secondValue', $this->config->get('secondKey'));
     $this->assertEquals(true, $this->config->is('secondKey'));
     $this->assertEquals(true, $this->config->has('secondKey'));
     $this->assertEquals(false, $this->config->has('thirdKey'));
     $this->assertEquals(null, $this->config->get('thirdKey'));
     $this->assertEquals($this->config, unserialize(serialize($this->config)));
     $this->config->set('secondKey', 'secondValue2');
     $this->assertEquals('secondValue2', $this->config->get('secondKey'));
     $this->setExpectedException('Oro\\Bundle\\EntityConfigBundle\\Exception\\RuntimeException');
     $this->config->get('thirdKey', true);
 }
 protected function prepareReverseRelationsConfig()
 {
     $selfEntityConfig = new Config(new EntityConfigId('extend', 'Oro\\Bundle\\UserBundle\\Entity\\User'));
     $selfTargetFieldId = new FieldConfigId('extend', 'Extend\\Entity\\testEntity1', 'rel_m_t_o', 'manyToOne');
     $selfEntityRelation = ['manyToOne|Extend\\Entity\\testEntity1|Oro\\Bundle\\UserBundle\\Entity\\User|rel_m_t_o' => ['assign' => false, 'field_id' => false, 'owner' => false, 'target_entity' => 'Extend\\Entity\\testEntity1', 'target_field_id' => $selfTargetFieldId], 'oneToMany|Extend\\Entity\\testEntity1|Oro\\Bundle\\UserBundle\\Entity\\User|rel_o_t_m' => ['assign' => true, 'field_id' => new FieldConfigId('extend', 'Extend\\Entity\\testEntity1', 'rel_o_t_m', 'oneToMany'), 'owner' => true, 'target_entity' => 'Extend\\Entity\\testEntity1', 'target_field_id' => false]];
     $selfEntityConfig->set('relation', $selfEntityRelation);
     $targetEntityConfig = new Config(new EntityConfigId('extend', 'Extend\\Entity\\testEntity1'));
     $targetEntityRelation = ['manyToOne|Extend\\Entity\\testEntity1|Oro\\Bundle\\UserBundle\\Entity\\User|rel_m_t_o' => ['assign' => true, 'field_id' => new FieldConfigId('extend', 'Extend\\Entity\\testEntity1', 'rel_m_t_o', 'manyToOne'), 'owner' => true, 'target_entity' => 'Oro\\Bundle\\UserBundle\\Entity\\User', 'target_field_id' => false]];
     $targetEntityConfig->set('relation', $targetEntityRelation);
     return ['selfEntityConfig' => $selfEntityConfig, 'targetFieldId' => $selfTargetFieldId, 'targetEntityConfig' => $targetEntityConfig];
 }
 public function testPreUpdate()
 {
     $configId = new EntityConfigId('extend', 'Acme\\TestBundle\\Entity\\TestEntity');
     $config = new Config($configId);
     $config->set('upgradeable', true);
     $provider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $provider->expects($this->once())->method('getConfigs')->willReturn([$config]);
     $this->listProvider->expects($this->any())->method('getTargetEntityClasses')->willReturn(['Acme\\TestBundle\\Entity\\TestEntity']);
     $this->configManager->expects($this->any())->method('getProvider')->willReturn($provider);
     $this->associationBuilder->expects($this->once())->method('createManyToManyAssociation')->with('Oro\\Bundle\\ActivityListBundle\\Entity\\ActivityList', 'Acme\\TestBundle\\Entity\\TestEntity', 'activityList');
     $this->extension->preUpdate();
 }
 /**
  * Test new index created and old deleted when field renamed
  */
 public function testRenameField()
 {
     $entityConfig = new Config(new EntityConfigId('extend', self::ENTITY_CLASS_NAME));
     $entityConfig->set('index', ['testField' => ['testField']]);
     $configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $configProvider->expects($this->once())->method('getConfig')->with(self::ENTITY_CLASS_NAME)->will($this->returnValue($entityConfig));
     $configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $configManager->expects($this->once())->method('getProvider')->with('extend')->will($this->returnValue($configProvider));
     $extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $event = new RenameFieldEvent(self::ENTITY_CLASS_NAME, 'testField', 'newName', $configManager);
     $configSubscriber = new ConfigSubscriber($extendConfigProvider);
     $configSubscriber->renameField($event);
     $this->assertEquals(['newName' => ['testField']], $entityConfig->get('index'));
 }
 public function testGetEmailFromRelatedObject()
 {
     $object = new TestCustomEntity();
     $object->setUser(new TestUser('*****@*****.**'));
     $object->setEmailHolder(new TestEmailHolder('*****@*****.**'));
     $object->setOther(new SomeEntity());
     $config = new Config(new EntityConfigId('extend', get_class($object)));
     $config->set('relation', [['owner' => true, 'field_id' => new FieldConfigId('extend', get_class($object), 'user', 'manyToOne'), 'target_entity' => 'Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestUser'], ['owner' => true, 'field_id' => new FieldConfigId('extend', get_class($object), 'emailHolder', 'manyToOne'), 'target_entity' => 'Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestEmailHolder'], ['owner' => true, 'field_id' => new FieldConfigId('extend', get_class($object), 'other', 'manyToOne'), 'target_entity' => 'Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\SomeEntity']]);
     $this->extendConfigProvider->expects($this->once())->method('hasConfig')->with(get_class($object))->will($this->returnValue(true));
     $this->extendConfigProvider->expects($this->once())->method('getConfig')->with(get_class($object))->will($this->returnValue($config));
     $this->helper->addTargetEntity('Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestUser');
     $this->helper->addTargetEntity('Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestEmailHolder', -10);
     $this->assertEquals('*****@*****.**', $this->helper->getEmail($object));
 }
 /**
  * @dataProvider dictionaryDataProvider
  */
 public function testGetEntityAliasForDictionary($entityClass, $expectedAlias)
 {
     $enumConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $enumConfig = new Config(new EntityConfigId('enum', $entityClass));
     $groupingConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $groupingConfig = new Config(new EntityConfigId('grouping', $entityClass));
     $groupingConfig->set('groups', [GroupingScope::GROUP_DICTIONARY]);
     $this->configManager->expects($this->once())->method('hasConfig')->with($entityClass)->willReturn(true);
     $this->configManager->expects($this->exactly(2))->method('getProvider')->willReturnMap([['enum', $enumConfigProvider], ['grouping', $groupingConfigProvider]]);
     $enumConfigProvider->expects($this->once())->method('getConfig')->with($entityClass)->willReturn($enumConfig);
     $groupingConfigProvider->expects($this->once())->method('getConfig')->with($entityClass)->willReturn($groupingConfig);
     $result = $this->entityAliasProvider->getEntityAlias($entityClass);
     $this->assertEntityAlias($expectedAlias, $result);
 }
 /**
  * @param string $className
  * @param null   $configs
  */
 protected function prepareMocks($className, $configs)
 {
     $this->identifyProvider->expects($this->once())->method('getEventTargetEntities')->will($this->returnValue([$className]));
     $extendConfig = new Config(new EntityConfigId('extend', $className));
     if (!empty($configs)) {
         foreach ($configs as $name => $value) {
             $extendConfig->set($name, $value);
         }
     }
     $extendProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $extendProvider->expects($this->once())->method('getConfigs')->will($this->returnValue([$extendConfig]));
     $extendProvider->expects($this->any())->method('hasConfig')->with('Oro\\Bundle\\TrackingBundle\\Entity\\TrackingVisitEvent')->will($this->returnValue(true));
     $this->configManager->expects($this->any())->method('getProvider')->with('extend')->will($this->returnValue($extendProvider));
 }
 protected function setUp()
 {
     $reader = new AnnotationReader();
     $metadataDriver = new AnnotationDriver($reader, self::ENTITY_NAMESPACE);
     $em = $this->getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($metadataDriver);
     $extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $config1 = new Config(new EntityConfigId('extend', self::ENTITY_NAMESPACE . '\\TestEntity1'));
     $config2 = new Config(new EntityConfigId('extend', self::ENTITY_NAMESPACE . '\\TestEntity2'));
     $config3 = new Config(new EntityConfigId('extend', self::ENTITY_NAMESPACE . '\\TestEntity3'));
     $newCustomEntityConfig = new Config(new EntityConfigId('extend', ExtendHelper::ENTITY_NAMESPACE . '\\TestEntity4'));
     $newCustomEntityConfig->set('state', ExtendScope::STATE_NEW);
     $toBeDeletedCustomEntityConfig = new Config(new EntityConfigId('extend', ExtendHelper::ENTITY_NAMESPACE . '\\TestEntity5'));
     $toBeDeletedCustomEntityConfig->set('state', ExtendScope::STATE_DELETE);
     $deletedCustomEntityConfig = new Config(new EntityConfigId('extend', ExtendHelper::ENTITY_NAMESPACE . '\\TestEntity6'));
     $deletedCustomEntityConfig->set('state', ExtendScope::STATE_ACTIVE);
     $deletedCustomEntityConfig->set('is_deleted', true);
     $entityConfigs = [$config1, $config2, $config3, $newCustomEntityConfig, $toBeDeletedCustomEntityConfig, $deletedCustomEntityConfig];
     $extendConfigProvider->expects($this->once())->method('getConfigs')->will($this->returnValue($entityConfigs));
     $doctrine = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $doctrine->expects($this->any())->method('getManagerForClass')->will($this->returnValue($em));
     $this->provider = new EntityHierarchyProvider($extendConfigProvider, $doctrine);
 }
 public function testPreUpdateForManyToOne()
 {
     $extension = $this->getExtensionMock(['getAssociationScope', 'getAssociationAttributeName', 'getAssociationKind', 'getAssociationType']);
     $extension->expects($this->once())->method('getAssociationScope')->will($this->returnValue(self::ASSOCIATION_SCOPE));
     $extension->expects($this->exactly(3))->method('getAssociationAttributeName')->will($this->returnValue(self::ATTR_NAME));
     $extension->expects($this->once())->method('getAssociationKind')->will($this->returnValue('test'));
     $extension->expects($this->once())->method('getAssociationType')->will($this->returnValue('manyToOne'));
     $config1 = new Config(new EntityConfigId(self::ASSOCIATION_SCOPE, 'Test\\Entity1'));
     $config1->set(self::ATTR_NAME, ['Test\\SourceEntity']);
     $config2 = new Config(new EntityConfigId(self::ASSOCIATION_SCOPE, 'Test\\Entity2'));
     $this->setTargetEntityConfigsExpectations([$config1, $config2]);
     $this->associationBuilder->expects($this->once())->method('createManyToOneAssociation')->with('Test\\SourceEntity', 'Test\\Entity1', 'test');
     $extension->preUpdate();
 }
 public function testGetOwningSideEntities()
 {
     $config1 = new Config(new EntityConfigId('grouping', 'Test\\Entity1'));
     $config1->set('groups', ['some_group', 'another_group']);
     $config2 = new Config(new EntityConfigId('grouping', 'Test\\Entity2'));
     $config2->set('groups', ['another_group']);
     $config3 = new Config(new EntityConfigId('grouping', 'Test\\Entity3'));
     $configs = [$config1, $config2, $config3];
     $configProvider = $this->getConfigProviderMock();
     $this->configManager->expects($this->exactly(2))->method('getProvider')->with('grouping')->will($this->returnValue($configProvider));
     $configProvider->expects($this->exactly(2))->method('getConfigs')->will($this->returnValue($configs));
     $this->assertEquals(['Test\\Entity1'], $this->typeHelper->getOwningSideEntities('some_group'));
     // one more call to check caching
     $this->assertEquals(['Test\\Entity1'], $this->typeHelper->getOwningSideEntities('some_group'));
     // call with another group to check a caching has no collisions
     $this->assertEquals(['Test\\Entity1', 'Test\\Entity2'], $this->typeHelper->getOwningSideEntities('another_group'));
 }
 /**
  * @dataProvider validateDataProvider
  */
 public function testValidate($enumName, $entityClassName, $fieldName, $violation)
 {
     $config1 = new Config(new EntityConfigId('extend', 'Test\\Entity1'));
     $config1->set('is_extend', true);
     $config1->set('state', ExtendScope::STATE_NEW);
     $config2 = new Config(new EntityConfigId('extend', 'Test\\Entity2'));
     $config2->set('is_extend', true);
     $config2->set('state', ExtendScope::STATE_UPDATE);
     $config3 = new Config(new EntityConfigId('extend', 'Test\\Entity3'));
     $config3->set('is_extend', true);
     $config3->set('state', ExtendScope::STATE_DELETE);
     $config4 = new Config(new EntityConfigId('extend', 'Test\\Entity4'));
     $config4->set('is_extend', true);
     $config4->set('state', ExtendScope::STATE_ACTIVE);
     $config5 = new Config(new EntityConfigId('extend', 'Test\\Entity5'));
     $config5->set('state', ExtendScope::STATE_NEW);
     $configs = [$config1, $config2, $config3, $config4, $config5];
     $fieldConfig11 = new Config(new FieldConfigId('extend', 'Test\\Entity1', 'field1', 'enum'));
     $fieldConfig11->set('state', ExtendScope::STATE_NEW);
     $enumFieldConfigs11 = new Config(new FieldConfigId('enum', 'Test\\Entity1', 'field1', 'enum'));
     $enumFieldConfigs11->set('enum_name', 'Enum 1');
     $fieldConfigs1 = [$fieldConfig11];
     $fieldConfig21 = new Config(new FieldConfigId('extend', 'Test\\Entity2', 'field1', 'multiEnum'));
     $fieldConfig21->set('state', ExtendScope::STATE_NEW);
     $enumFieldConfigs21 = new Config(new FieldConfigId('enum', 'Test\\Entity2', 'field1', 'multiEnum'));
     $enumFieldConfigs21->set('enum_name', 'Enum 2');
     $fieldConfigs2 = [$fieldConfig21];
     $enumValueConfig = new Config(new EntityConfigId('extend', 'Test\\EnumValue'));
     $enumValueConfig->set('inherit', ExtendHelper::BASE_ENUM_VALUE_CLASS);
     $enumValueEnumConfig = new Config(new EntityConfigId('enum', 'Test\\EnumValue'));
     $enumValueEnumConfig->set('code', 'existing_enum');
     $enumConfigProvider = $this->getConfigProviderMock();
     $extendConfigProvider = $this->getConfigProviderMock();
     $this->configManager->expects($this->exactly(2))->method('getProvider')->will($this->returnValueMap([['extend', $extendConfigProvider], ['enum', $enumConfigProvider]]));
     $extendConfigProvider->expects($this->any())->method('getConfigs')->will($this->returnValueMap([[null, false, $configs], [null, true, array_merge([$enumValueConfig], $configs)], ['Test\\Entity1', false, $fieldConfigs1], ['Test\\Entity2', false, $fieldConfigs2]]));
     $enumConfigProvider->expects($this->any())->method('getConfig')->will($this->returnValueMap([['Test\\EnumValue', null, $enumValueEnumConfig], ['Test\\Entity1', 'field1', $enumFieldConfigs11], ['Test\\Entity2', 'field1', $enumFieldConfigs21]]));
     $constraint = new UniqueEnumName(['entityClassName' => $entityClassName, 'fieldName' => $fieldName]);
     if ($violation) {
         $this->context->expects($this->once())->method('addViolation')->with($constraint->message);
     } else {
         $this->context->expects($this->never())->method('addViolation');
     }
     $this->validator->validate($enumName, $constraint);
 }
 /**
  * @param string                                     $formName
  * @param AbstractType                               $formType
  * @param array                                      $options
  * @param \PHPUnit_Framework_MockObject_MockObject[] $configProviders
  * @param mixed                                      $newVal
  * @param mixed                                      $oldVal
  * @param string                                     $state
  * @param bool                                       $isSetStateExpected
  *
  * @return mixed The form data
  */
 protected function doTestSubmit($formName, AbstractType $formType, array $options, array $configProviders, $newVal, $oldVal, $state, $isSetStateExpected)
 {
     $config = new Config(new EntityConfigId('test', 'Test\\Entity'));
     $config->set($formName, $oldVal);
     $propertyConfig = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\PropertyConfigContainer')->disableOriginalConstructor()->getMock();
     $propertyConfig->expects($this->once())->method('isSchemaUpdateRequired')->with($formName, $config->getId())->will($this->returnValue(true));
     $this->testConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($propertyConfig));
     $extendConfigId = new EntityConfigId('extend', 'Test\\Entity');
     $extendConfig = new Config($extendConfigId);
     $extendConfig->set('state', $state);
     $extendConfigProvider = $this->getConfigProviderMock();
     $extendConfigProvider->expects($this->any())->method('getConfig')->with('Test\\Entity')->will($this->returnValue($extendConfig));
     $this->configManager->expects($this->any())->method('getConfig')->with($config->getId())->will($this->returnValue($config));
     $this->setConfigProvidersForSubmitTest($configProviders);
     $configProviders['extend'] = $extendConfigProvider;
     $configProvidersMap = [];
     foreach ($configProviders as $configProviderScope => $configProvider) {
         $configProvidersMap[] = [$configProviderScope, $configProvider];
     }
     $this->configManager->expects($this->any())->method('getProvider')->will($this->returnValueMap($configProvidersMap));
     $expectedExtendConfig = new Config($extendConfigId);
     if ($isSetStateExpected) {
         $expectedExtendConfig->set('state', ExtendScope::STATE_UPDATE);
         $this->configManager->expects($this->once())->method('persist')->with($expectedExtendConfig);
     } else {
         $expectedExtendConfig->set('state', $state);
         $this->configManager->expects($this->never())->method('persist');
     }
     // flush should be never called
     foreach ($configProviders as $configProvider) {
         $configProvider->expects($this->never())->method('flush');
     }
     $this->configManager->expects($this->never())->method('flush');
     $form = $this->factory->createNamed($formName, $formType, $oldVal, $options);
     $form->submit($newVal);
     $this->assertTrue($form->isSynchronized(), 'Expected that a form is synchronized');
     $this->assertEquals($expectedExtendConfig, $extendConfig);
     return $form->getData();
 }
 public function testValidateSandboxErrors()
 {
     $trans = new EmailTemplateTranslation();
     $trans->setField('subject')->setLocale('fr')->setContent(self::TEST_TRANS_SUBJECT);
     $this->template->getTranslations()->add($trans);
     $subjectTokenStream = $this->getMockBuilder('\\Twig_TokenStream')->disableOriginalConstructor()->getMock();
     $contentTokenStream = $this->getMockBuilder('\\Twig_TokenStream')->disableOriginalConstructor()->getMock();
     $transSubjectTokenStream = $this->getMockBuilder('\\Twig_TokenStream')->disableOriginalConstructor()->getMock();
     $tokenizeMap = [[self::TEST_SUBJECT, null, $subjectTokenStream], [self::TEST_CONTENT, null, $contentTokenStream], [self::TEST_TRANS_SUBJECT, null, $transSubjectTokenStream]];
     $this->twig->expects($this->exactly(count($tokenizeMap)))->method('tokenize')->will($this->returnValueMap($tokenizeMap));
     $this->twig->expects($this->exactly(count($tokenizeMap)))->method('parse')->will($this->throwException(new \Twig_Error_Syntax('message')));
     $this->entityConfigProvider->expects($this->exactly(3))->method('hasConfig')->will($this->returnValueMap([[get_class($this->template), 'subject', true], [get_class($this->template), 'content', false]]));
     $subjectConfig = new Config(new FieldConfigId('entity', get_class($this->template), 'subject', 'string'));
     $subjectConfig->set('label', 'subject.label');
     $this->entityConfigProvider->expects($this->exactly(2))->method('getConfig')->with(get_class($this->template), 'subject')->will($this->returnValue($subjectConfig));
     $this->localeSettings->expects($this->exactly(3))->method('getLanguage')->will($this->returnValue('en'));
     $this->localeSettings->expects($this->exactly(3))->method('getLocalesByCodes')->will($this->returnValueMap([[['en'], 'en', ['en' => 'English']], [['fr'], 'en', ['fr' => 'French']]]));
     $this->context->expects($this->at(0))->method('addViolation')->with($this->constraint->message, ['{{ field }}' => 'subject.label', '{{ locale }}' => 'English', '{{ error }}' => 'message']);
     $this->context->expects($this->at(1))->method('addViolation')->with($this->constraint->message, ['{{ field }}' => 'content', '{{ locale }}' => 'English', '{{ error }}' => 'message']);
     $this->context->expects($this->at(2))->method('addViolation')->with($this->constraint->message, ['{{ field }}' => 'subject.label', '{{ locale }}' => 'French', '{{ error }}' => 'message']);
     $validator = $this->getValidator(self::ENTITY_CLASS);
     $validator->validate($this->template, $this->constraint);
 }