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'));
 }
 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 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);
 }
 /**
  * @param string $className
  * @param mixed  $values
  *
  * @return ConfigInterface
  */
 protected function getEntityConfig($className, $values)
 {
     $configId = new EntityConfigId('extend', $className);
     $config = new Config($configId);
     $config->setValues($values);
     return $config;
 }
 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 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 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 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 testConfigHas()
 {
     $config = new Config(new EntityConfigId('test', 'Entity1'), ['attr' => 'val', 'null_attr' => null]);
     self::assertBenchmark(__METHOD__, 0.05, function () use($config) {
         $config->has('attr');
         $config->has('null_attr');
         $config->has('undefined_attr');
     });
 }
 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'));
 }
 protected function prepareConfigProvider(array $configValues, $className)
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|ConfigIdInterface $configId */
     $configId = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $entityConfig = new Config($configId);
     $entityConfig->setValues($configValues);
     $this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo($className))->will($this->returnValue(true));
     $this->configProvider->expects($this->once())->method('getConfig')->with($this->equalTo($className))->will($this->returnValue($entityConfig));
 }
 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));
 }
 /**
  * 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()));
 }
 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));
 }
 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]]));
 }
 /**
  * Checks whether the name of a new field conflicts with the name of existing field.
  *
  * @param string $newFieldName
  * @param Config $existingFieldConfig
  *
  * @return bool
  */
 public function hasFieldNameConflict($newFieldName, Config $existingFieldConfig)
 {
     $existingFieldName = $existingFieldConfig->getId()->getFieldName();
     if (strtolower($newFieldName) === strtolower($existingFieldName)) {
         return true;
     }
     if ($this->normalizeFieldName($newFieldName) === $this->normalizeFieldName($existingFieldName) && !$existingFieldConfig->is('is_deleted') && !$existingFieldConfig->is('state', ExtendScope::STATE_DELETE)) {
         return true;
     }
     return false;
 }
 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();
 }
 public function testWithoutOwnerType()
 {
     $entity = new BusinessUnit();
     $className = 'Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit';
     /** @var \PHPUnit_Framework_MockObject_MockObject|ConfigIdInterface $configId */
     $configId = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $config = new Config($configId);
     $config->setValues(['another_owner_type' => 'test_type']);
     $this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo($className))->will($this->returnValue(true));
     $this->configProvider->expects($this->once())->method('getConfig')->with($this->equalTo($className))->will($this->returnValue($config));
     $this->assertNull($this->extension->getOwnerType($entity));
 }
 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 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();
 }
 /**
  * @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);
 }
 /**
  * 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'));
 }
 /**
  * Test class is NOT extend and should NOT be persisted
  */
 public function testNewNotExtendEntity()
 {
     $configModel = new EntityConfigModel('Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\TestClass2');
     $entityConfig = new Config(new EntityConfigId('Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\TestClass2', 'extend'));
     /**
      * value of NEW Config should be empty
      */
     $this->assertEquals([], $entityConfig->all());
     $this->configProvider->expects($this->any())->method('getConfig')->will($this->returnValue($entityConfig));
     $event = new EntityConfigEvent($configModel->getClassName(), $this->configManager);
     $listener = new EntityConfigListener();
     $listener->updateEntity($event);
     $this->assertEquals([], $this->configManager->getUpdateConfig());
 }
 /**
  * @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));
 }
 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));
 }
 public function preSetData()
 {
     $entityConfigId = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\EntityConfigId')->disableOriginalConstructor()->getMock();
     $user = new User();
     $user->setId(1);
     $organization = new Organization();
     $organization->setId(3);
     $userConfig = new Config($entityConfigId);
     $userConfig->setValues(["owner_type" => "USER", "owner_field_name" => "owner", "owner_column_name" => "owner_id", "organization_field_name" => "organization", "organization_column_name" => "organization_id"]);
     $buConfig = new Config($entityConfigId);
     $buConfig->setValues(["owner_type" => "BUSINESS_UNIT", "owner_field_name" => "owner", "owner_column_name" => "owner_id", "organization_field_name" => "organization", "organization_column_name" => "organization_id"]);
     $organizationConfig = new Config($entityConfigId);
     $organizationConfig->setValues(["owner_type" => "ORGANIZATION", "owner_field_name" => "owner", "owner_column_name" => "owner_id"]);
     return ['OwnershipType User with UsernamePasswordOrganizationToken' => [new UsernamePasswordOrganizationToken($user, 'admin', 'key', $organization), $userConfig, ['owner' => $user, 'organization' => $organization]], 'OwnershipType BusinessUnit with UsernamePasswordOrganizationToken' => [new UsernamePasswordOrganizationToken($user, 'admin', 'key', $organization), $buConfig, ['organization' => $organization]], 'OwnershipType Organization with UsernamePasswordOrganizationToken' => [new UsernamePasswordOrganizationToken($user, 'admin', 'key', $organization), $organizationConfig, ['owner' => $organization]], 'OwnershipType User with UsernamePasswordToken' => [new UsernamePasswordToken($user, 'admin', 'key'), $userConfig, ['owner' => $user]], 'OwnershipType BusinessUnit with UsernamePasswordToken' => [new UsernamePasswordToken($user, 'admin', 'key'), $buConfig, []], 'OwnershipType Organization with UsernamePasswordToken' => [new UsernamePasswordToken($user, 'admin', 'key'), $organizationConfig, []]];
 }
 /**
  * @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;
 }