protected function setUp() { $this->entityConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock(); $this->entityConfigProvider->expects($this->any())->method('getScope')->will($this->returnValue('entity')); $this->testConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock(); $this->testConfigProvider->expects($this->any())->method('getScope')->will($this->returnValue('test')); $this->configProviderBag = new ConfigProviderBag(); $this->configProviderBag->addProvider($this->entityConfigProvider); $this->configProviderBag->addProvider($this->testConfigProvider); $this->container = $this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->container->expects($this->any())->method('has')->will($this->returnCallback(function ($id) { switch ($id) { case 'ConfigProviderBag': return true; default: return false; } })); $configProviderBag = $this->configProviderBag; $this->container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use(&$configProviderBag) { switch ($id) { case 'ConfigProviderBag': return $configProviderBag; default: return null; } })); $this->metadataFactory = $this->getMockBuilder('Metadata\\MetadataFactory')->disableOriginalConstructor()->getMock(); $this->eventDispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock(); $this->modelManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigModelManager')->disableOriginalConstructor()->getMock(); $this->auditManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Audit\\AuditManager')->disableOriginalConstructor()->getMock(); $this->configCache = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigCache')->disableOriginalConstructor()->getMock(); $this->configManager = new ConfigManager($this->metadataFactory, $this->eventDispatcher, new ServiceLink($this->container, 'ConfigProviderBag'), $this->modelManager, $this->auditManager); $this->configManager->setCache($this->configCache); }
public function testUpdateConfigFieldModelWithForceForCustomField() { $configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int'); $metadata = $this->getEntityMetadata(self::ENTITY_CLASS); $idFieldMetadata = $this->getFieldMetadata(self::ENTITY_CLASS, 'id', ['translatable1' => 'labelVal1', 'other1' => 'otherVal1', 'translatable2' => 'labelVal2', 'other2' => 'otherVal2']); $metadata->addPropertyMetadata($idFieldMetadata); $this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata); $propertyConfigContainer = $this->getPropertyConfigContainerMock(); $propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_FIELD, 'int')->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']); $propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_FIELD)->willReturn(['translatable1', 'translatable2', 'translatable10', 'auto_generated']); $this->configProvider->expects($this->any())->method('getPropertyConfig')->willReturn($propertyConfigContainer); $config = $this->getConfig($configId, ['translatable2' => 'labelVal2_old', 'other2' => 'otherVal2_old']); $this->configProvider->expects($this->once())->method('getConfig')->with(self::ENTITY_CLASS)->willReturn($config); $extendConfig = $this->getConfig(new FieldConfigId('extend', self::ENTITY_CLASS, 'id')); $extendConfig->set('owner', ExtendScope::OWNER_CUSTOM); $extendConfigProvider = $this->getConfigProviderMock(); $extendConfigProvider->expects($this->any())->method('getScope')->willReturn('extend'); $this->configProviderBag->addProvider($extendConfigProvider); $extendConfigProvider->expects($this->once())->method('hasConfig')->with(self::ENTITY_CLASS, 'id')->willReturn(true); $extendConfigProvider->expects($this->exactly(2))->method('getConfig')->with(self::ENTITY_CLASS, 'id')->willReturn($extendConfig); $extendPropertyConfigContainer = $this->getPropertyConfigContainerMock(); $extendPropertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_FIELD)->willReturn(['owner' => ExtendScope::OWNER_SYSTEM]); $extendPropertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_FIELD)->willReturn([]); $extendConfigProvider->expects($this->any())->method('getPropertyConfig')->willReturn($extendPropertyConfigContainer); $extendConfigProvider->expects($this->never())->method('persist'); $expectedConfig = $this->getConfig($configId, ['translatable2' => 'labelVal2_old', 'other2' => 'otherVal2_old', 'translatable10' => 'labelVal10', 'other10' => 'otherVal10', 'translatable1' => 'labelVal1', 'other1' => 'otherVal1', 'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated']); $actualConfig = null; $this->configProvider->expects($this->once())->method('persist')->willReturnCallback(function ($c) use(&$actualConfig) { $actualConfig = $c; }); $this->configManager->updateConfigFieldModel(self::ENTITY_CLASS, 'id', true); $this->assertEquals($expectedConfig, $actualConfig); }
public function testBag() { $provider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock(); $provider->expects($this->any())->method('getScope')->will($this->returnValue('testScope')); $providerBag = new ConfigProviderBag(); $providerBag->addProvider($provider); $this->assertEquals(new ArrayCollection(array('testScope' => $provider)), $providerBag->getProviders()); $this->assertEquals($provider, $providerBag->getProvider('testScope')); $this->assertTrue($providerBag->hasProvider('testScope')); $this->assertFalse($providerBag->hasProvider('wrongTestScope')); }