/**
  * @dataProvider provideShortcodes
  */
 public function testSerializer(SerializerInterface $serializer, ShortcodeInterface $test)
 {
     $result = $serializer->serialize($test);
     $tested = $serializer->unserialize($result);
     $this->assertSame($test->getName(), $tested->getName(), 'name: ' . $result);
     $this->assertSame($test->getParameters(), $tested->getParameters(), 'parameters: ' . $result);
     $this->assertSame($test->getContent(), $tested->getContent(), 'content: ' . $result);
     $this->assertSame($test->getBbCode(), $tested->getBbCode(), 'bbCode: ' . $result);
 }
Exemplo n.º 2
0
 /**
  * @dataProvider provideShortcodes
  */
 public function testSerializer(SerializerInterface $serializer, $text, ShortcodeInterface $shortcode)
 {
     $serialized = $serializer->serialize($shortcode);
     $this->assertSame($text, $serialized);
     $s = $serializer->unserialize($text);
     $this->assertSame($shortcode->getName(), $s->getName());
     $this->assertSame($shortcode->getParameters(), $s->getParameters());
     $this->assertSame($shortcode->getContent(), $s->getContent());
 }
 public function serialize(ShortcodeInterface $shortcode, $format)
 {
     switch ($format) {
         case 'text':
             return $this->textSerializer->serialize($shortcode);
         case 'json':
             return $this->jsonSerializer->serialize($shortcode);
         case 'yaml':
             return $this->yamlSerializer->serialize($shortcode);
         case 'xml':
             return $this->xmlSerializer->serialize($shortcode);
         default:
             throw new \InvalidArgumentException(sprintf('Invalid serialization format %s!', $format));
     }
 }
 /**
  * [text arg=val /]
  * [text arg=val]content[/text]
  * [json arg=val /]
  * [json arg=val]content[/json]
  * [xml arg=val /]
  * [xml arg=val]content[/xml]
  * [yaml arg=val /]
  * [yaml arg=val]content[/yaml]
  *
  * @param ShortcodeInterface $shortcode
  *
  * @return string
  */
 public function __invoke(ShortcodeInterface $shortcode)
 {
     return $this->serializer->serialize($shortcode);
 }