/**
  * {@inheritdoc}
  */
 public function renderContent(Content $content, array $options)
 {
     $text = $content->getText();
     if (isset($options['separately']) && $options['separately']) {
         $this->separatelyEditableContents[$content->getId()] = $content;
         return $text;
     }
     return sprintf('<span class="ivoaz-content-editable" data-ivoaz-content-editable-id="%s">%s</span>', $content->getId(), $text);
 }
 /**
  * @dataProvider getRenderContentEditableTestData
  *
  * @param string $expectedText
  * @param string $text
  * @param string $name
  * @param array  $options
  * @param bool   $isAuthorized
  * @param string $message
  */
 public function testRenderContentEditable($expectedText, $text, $name, $options, $isAuthorized, $message)
 {
     $content = new Content();
     $content->setId(1)->setName($name)->setText($text)->setLocale($options['locale']);
     $this->manager->method('get')->with($name, $options['locale'], $text)->willReturn($content);
     $this->authorizationChecker->method('isGranted')->with('ROLE_ADMIN')->willReturn($isAuthorized);
     $this->editor->method('renderContent')->with($content, $options)->willReturn(sprintf('editable_%s', $text));
     $rendered = $this->extension->render($text, $name, $options);
     $this->assertSame($expectedText, $rendered, $message);
 }
Ejemplo n.º 3
0
 /**
  * @param \Ivoaz\Bundle\ContentEditableBundle\Model\Content $content
  */
 public function update(\Ivoaz\Bundle\ContentEditableBundle\Model\Content $content)
 {
     $content->setText($this->text);
 }
 /**
  * @return array
  */
 public function getRenderContentTestData()
 {
     $content = new Content();
     $content->setId(1)->setText('Example text')->setLocale('en');
     return [['Example text', $content, ['separately' => true], 'The text should not be modified when editable separately.'], ['<span class="ivoaz-content-editable" data-ivoaz-content-editable-id="1">Example text</span>', clone $content, [], 'The text was not wrapped correctly.']];
 }
 /**
  * @param string $name
  * @param string $text
  * @param string $locale
  *
  * @return Content
  */
 private function create($name, $text, $locale)
 {
     $content = new Content();
     $content->setName($name)->setText($text)->setLocale($locale);
     $this->om->persist($content);
     $this->om->flush($content);
     return $content;
 }
 public function testGetDetachesNewObject()
 {
     $manager = new ContentManager($this->om);
     $this->repository->method('findOneBy')->with(['name' => 'name', 'locale' => 'en'])->willReturn(null);
     $content = new Content();
     $content->setName('name')->setText('text')->setLocale('en');
     $this->om->expects($this->once())->method('detach')->with($this->callback(function ($value) use($content) {
         return $value == $content;
     }));
     $manager->get('name', 'en', 'text');
 }