Example #1
0
 /**
  * Test that the method attributeTypeMatchesFlags() works correctly.
  *
  * @return void
  */
 public function testGetTypeNames()
 {
     $factory = new AttributeFactory();
     $this->assertSame(array(), $factory->getTypeNames(IAttributeFactory::FLAG_ALL), 'FLAG_ALL');
     $this->assertSame(array(), $factory->getTypeNames(IAttributeFactory::FLAG_INCLUDE_TRANSLATED), 'FLAG_INCLUDE_TRANSLATED');
     $this->assertSame(array(), $factory->getTypeNames(IAttributeFactory::FLAG_INCLUDE_SIMPLE), 'FLAG_INCLUDE_SIMPLE');
     $this->assertSame(array(), $factory->getTypeNames(IAttributeFactory::FLAG_INCLUDE_COMPLEX), 'FLAG_INCLUDE_COMPLEX');
     $this->assertSame(array(), $factory->getTypeNames(IAttributeFactory::FLAG_ALL_UNTRANSLATED), 'FLAG_ALL_UNTRANSLATED');
     $factory->addTypeFactory($this->mockAttributeFactory('test_translated', true, false, false));
     $factory->addTypeFactory($this->mockAttributeFactory('test_simple', false, true, false));
     $factory->addTypeFactory($this->mockAttributeFactory('test_complex', false, false, true));
     $factory->addTypeFactory($this->mockAttributeFactory('test_simplecomplex', false, true, true));
     $factory->addTypeFactory($this->mockAttributeFactory('test_translatedsimple', true, true, false));
     $factory->addTypeFactory($this->mockAttributeFactory('test_translatedcomplex', true, false, true));
     $factory->addTypeFactory($this->mockAttributeFactory('test_translatedsimplecomplex', true, true, true));
     $this->assertSame(array('test_translated', 'test_simple', 'test_complex', 'test_simplecomplex', 'test_translatedsimple', 'test_translatedcomplex', 'test_translatedsimplecomplex'), $factory->getTypeNames(IAttributeFactory::FLAG_ALL), 'FLAG_ALL');
     $this->assertSame(array('test_translated', 'test_translatedsimple', 'test_translatedcomplex', 'test_translatedsimplecomplex'), $factory->getTypeNames(IAttributeFactory::FLAG_INCLUDE_TRANSLATED), 'FLAG_INCLUDE_TRANSLATED');
     $this->assertSame(array('test_simple', 'test_simplecomplex', 'test_translatedsimple', 'test_translatedsimplecomplex'), $factory->getTypeNames(IAttributeFactory::FLAG_INCLUDE_SIMPLE), 'FLAG_INCLUDE_SIMPLE');
     $this->assertSame(array('test_complex', 'test_simplecomplex', 'test_translatedcomplex', 'test_translatedsimplecomplex'), $factory->getTypeNames(IAttributeFactory::FLAG_INCLUDE_COMPLEX), 'FLAG_INCLUDE_COMPLEX');
     $this->assertSame(array('test_simple', 'test_complex', 'test_simplecomplex', 'test_translatedsimple', 'test_translatedcomplex', 'test_translatedsimplecomplex'), $factory->getTypeNames(IAttributeFactory::FLAG_ALL_UNTRANSLATED), 'FLAG_ALL_UNTRANSLATED');
 }
 /**
  * Test the addFactoriesToFactory method.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function testGetTypeIconsFromFactory()
 {
     $reflection = new \ReflectionClass('MetaModels\\Attribute\\LegacyAttributeTypeFactory');
     $typeClassProp = $reflection->getProperty('typeClass');
     $typeIconProp = $reflection->getProperty('typeIcon');
     $typeClassProp->setAccessible(true);
     $typeIconProp->setAccessible(true);
     foreach ($this->testFactories as $typeName => $instance) {
         $GLOBALS['METAMODELS']['attributes'][$typeName]['class'] = $typeClassProp->getValue($instance);
         $GLOBALS['METAMODELS']['attributes'][$typeName]['image'] = $typeIconProp->getValue($instance);
     }
     $factory = new AttributeFactory();
     $factory->setServiceContainer($this->mockServiceContainer());
     $this->assertEquals(array_keys($this->testFactories), $factory->getTypeNames());
     foreach ($this->testFactories as $typeName => $instance) {
         $this->assertEquals($typeIconProp->getValue($instance), $factory->getIconForType($typeName));
     }
     unset($GLOBALS['METAMODELS']);
 }