コード例 #1
0
 public function testChoiceNormalizer()
 {
     // source data
     $workflowAwareClass = 'WorkflowAwareClass';
     $extendedClass = 'ExtendedClass';
     $notExtendedClass = 'NotExtendedClass';
     $notConfigurableClass = 'NotConfigurableClass';
     // asserts
     $this->entityConnector->expects($this->any())->method('isWorkflowAware')->will($this->returnCallback(function ($class) use($workflowAwareClass) {
         return $class === $workflowAwareClass;
     }));
     $extendedEntityConfig = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $extendedEntityConfig->expects($this->any())->method('is')->with('is_extend')->will($this->returnValue(true));
     $notExtendedEntityConfig = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $notExtendedEntityConfig->expects($this->any())->method('is')->with('is_extend')->will($this->returnValue(false));
     $extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $hasConfigMap = array(array($workflowAwareClass, null, false), array($extendedClass, null, true), array($notExtendedClass, null, true), array($notConfigurableClass, null, false));
     $extendConfigProvider->expects($this->any())->method('hasConfig')->with($this->isType('string'), null)->will($this->returnValueMap($hasConfigMap));
     $getConfigMap = array(array($extendedClass, null, $extendedEntityConfig), array($notExtendedClass, null, $notExtendedEntityConfig));
     $extendConfigProvider->expects($this->any())->method('getConfig')->with($this->isType('string'), null)->will($this->returnValueMap($getConfigMap));
     $this->configManager->expects($this->once())->method('getProvider')->with('extend')->will($this->returnValue($extendConfigProvider));
     // test
     $inputChoices = array($workflowAwareClass => Inflector::tableize($workflowAwareClass), $extendedClass => Inflector::tableize($extendedClass), $notExtendedClass => Inflector::tableize($notExtendedClass), $notConfigurableClass => Inflector::tableize($notConfigurableClass));
     $expectedChoices = array($workflowAwareClass => Inflector::tableize($workflowAwareClass), $extendedClass => Inflector::tableize($extendedClass));
     $resolver = new OptionsResolver();
     $resolver->setDefaults(array('choices' => $inputChoices));
     $this->formType->setDefaultOptions($resolver);
     $result = $resolver->resolve(array());
     $this->assertEquals($expectedChoices, $result['choices']);
 }
コード例 #2
0
 public function testChoiceNormalizer()
 {
     // source data
     $workflowAwareClass = 'WorkflowAwareClass';
     $extendedClass = 'ExtendedClass';
     $notExtendedClass = 'NotExtendedClass';
     $notConfigurableClass = 'NotConfigurableClass';
     $workflowAwareItem = new ChoiceListItem($workflowAwareClass);
     $extendedItem = new ChoiceListItem($extendedClass);
     $notExtendedItem = new ChoiceListItem($notExtendedClass);
     $notConfigurableItem = new ChoiceListItem($notConfigurableClass);
     // asserts
     $this->entityConnector->expects($this->any())->method('isWorkflowAware')->will($this->returnCallback(function ($class) use($workflowAwareClass) {
         return $class === $workflowAwareClass;
     }));
     $extendedEntityConfig = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $extendedEntityConfig->expects($this->any())->method('is')->with('is_extend')->will($this->returnValue(true));
     $notExtendedEntityConfig = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $notExtendedEntityConfig->expects($this->any())->method('is')->with('is_extend')->will($this->returnValue(false));
     $extendConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $hasConfigMap = array(array($workflowAwareClass, null, false), array($extendedClass, null, true), array($notExtendedClass, null, true), array($notConfigurableClass, null, false));
     $extendConfigProvider->expects($this->any())->method('hasConfig')->with($this->isType('string'), null)->will($this->returnValueMap($hasConfigMap));
     $getConfigMap = array(array($extendedClass, null, $extendedEntityConfig), array($notExtendedClass, null, $notExtendedEntityConfig));
     $extendConfigProvider->expects($this->any())->method('getConfig')->with($this->isType('string'), null)->will($this->returnValueMap($getConfigMap));
     $this->configManager->expects($this->once())->method('getProvider')->with('extend')->will($this->returnValue($extendConfigProvider));
     // test
     $inputClasses = array($workflowAwareClass => $workflowAwareItem, $extendedClass => $extendedItem, $notExtendedClass => $notExtendedItem, $notConfigurableClass => $notConfigurableItem);
     $expectedClasses = array($workflowAwareClass => $workflowAwareItem, $extendedClass => $extendedItem);
     $resolver = $this->getMock('Symfony\\Component\\OptionsResolver\\OptionsResolverInterface');
     $resolver->expects($this->once())->method('setNormalizers')->will($this->returnCallback(function (array $normalizers) use($inputClasses, $expectedClasses) {
         $this->assertCount(1, $normalizers);
         $this->assertArrayHasKey('choices', $normalizers);
         $this->assertTrue(is_callable($normalizers['choices']), 'Choices normalizer is not callable');
         $this->assertEquals($expectedClasses, call_user_func($normalizers['choices'], new Options(), $inputClasses));
     }));
     $this->formType->setDefaultOptions($resolver);
 }