Пример #1
0
 public function testGetClassConfigValue()
 {
     $className = 'Test\\Entity';
     $configEntityScope = new Config(new EntityConfigId('entity', $className));
     $configEntityScope->set('test', 'entity_val');
     $configAnotherScope = new Config(new EntityConfigId('another', $className));
     $configAnotherScope->set('test', 'another_val');
     $this->configManager->expects($this->any())->method('hasConfig')->with($className)->will($this->returnValue(true));
     $this->configManager->expects($this->any())->method('getConfig')->with($this->isInstanceOf('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\EntityConfigId'))->will($this->returnCallback(function (EntityConfigId $configId) use($className, $configEntityScope, $configAnotherScope) {
         self::assertEquals($className, $configId->getClassName());
         switch ($configId->getScope()) {
             case 'entity':
                 return $configEntityScope;
             case 'another':
                 return $configAnotherScope;
             default:
                 return null;
         }
     }));
     // test default scope
     $this->assertEquals('entity_val', $this->twigExtension->getClassConfigValue($className, 'test'));
     // test with specified scope
     $this->assertEquals('another_val', $this->twigExtension->getClassConfigValue($className, 'test', 'another'));
     // test undefined attribute
     $this->assertNull($this->twigExtension->getClassConfigValue($className, 'undefined'));
 }
Пример #2
0
 public function testGetClassMetadataValue()
 {
     $className = 'Test\\Entity';
     $attrName = 'routeView';
     $attrVal = 'test_route';
     $metadata = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Metadata\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $reflection = new \ReflectionClass($metadata);
     $routeViewProp = $reflection->getProperty($attrName);
     $routeViewProp->setValue($metadata, $attrVal);
     $this->configManager->expects($this->once())->method('hasConfig')->with($className)->willReturn(true);
     $this->configManager->expects($this->exactly(2))->method('getEntityMetadata')->with($className)->willReturn($metadata);
     $this->assertSame($attrVal, $this->twigExtension->getClassMetadataValue($className, $attrName));
 }