/** * @covers Alchemy\Phrasea\Border\Attribute\Factory::getFileAttribute */ public function testGetFileAttributeMetaField() { $databox_field = null; foreach (self::$DI['collection']->get_databox()->get_meta_structure() as $df) { $databox_field = $df; break; } if (!$databox_field) { $this->markTestSkipped('No databox field found'); } $metafield = new MetaField($databox_field, ['value']); $attribute = Factory::getFileAttribute(self::$DI['app'], AttributeInterface::NAME_METAFIELD, $metafield->asString()); $this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Attribute\\MetaField', $attribute); }
/** * Build a file package Attribute * * @param Application $app Application context * @param string $name The name of the attribute, one of the * AttributeInterface::NAME_* constants * @param string $serialized The serialized value of the attribute * (AttributeInterface::asString result) * @return AttributeInterface The attribute * @throws \InvalidArgumentException */ public static function getFileAttribute(Application $app, $name, $serialized) { switch ($name) { case AttributeInterface::NAME_METADATA: return Metadata::loadFromString($app, $serialized); break; case AttributeInterface::NAME_STORY: return Story::loadFromString($app, $serialized); break; case AttributeInterface::NAME_METAFIELD: return MetaField::loadFromString($app, $serialized); break; case AttributeInterface::NAME_STATUS: return Status::loadFromString($app, $serialized); break; } throw new \InvalidArgumentException(sprintf('Unknown attribute %s', $name)); }
/** * @covers Alchemy\Phrasea\Border\Attribute\MetaField::loadFromString * @expectedException \InvalidArgumentException */ public function testLoadFromStringFailSerialize() { \PHPUnit_Framework_Error_Warning::$enabled = false; \PHPUnit_Framework_Error_Notice::$enabled = false; MetaField::loadFromString(self::$DI['app'], serialize(['Elephant', 'sbas_id' => self::$DI['collection']->get_sbas_id(), 'id' => 0])); }