/**
  * @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);
 }
 /**
  * {@inheritdoc}
  */
 public function render($default, $name = null, array $options = [])
 {
     if (null === $name) {
         $name = $default;
     }
     $locale = isset($options['locale']) ? $options['locale'] : null;
     $content = $this->manager->get($name, $locale, $default);
     if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
         return $content->getText();
     }
     return $this->editor->renderContent($content, $options);
 }
 /**
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function batchUpdateAction(Request $request)
 {
     if (!$this->isAuthorized()) {
         return new JsonResponse(null, JsonResponse::HTTP_FORBIDDEN);
     }
     $form = $this->formFactory->create(BatchType::class);
     $form->submit($this->getDataFromJsonRequest($request));
     if (!$form->isValid()) {
         $errors = $this->getErrors($form);
         return $this->createErrorResponse($errors);
     }
     $errors = [];
     $contents = [];
     foreach ($form->getData()->contents as $data) {
         $content = $this->manager->find($data->id);
         if (null === $content) {
             $errors[] = $this->createContentNotFoundError($data->id);
             continue;
         }
         $data->update($content);
         $contents[] = $content;
     }
     if (0 !== count($errors)) {
         return $this->createErrorResponse($errors);
     }
     foreach ($contents as $content) {
         $this->manager->update($content);
     }
     return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
 }
 public function testBatchUpdateActionUpdatesContent()
 {
     $this->setAuthorized(true);
     $content1 = new Content();
     $content2 = new Content();
     $this->manager->method('find')->will($this->returnValueMap([[1, $content1], [2, $content2]]));
     $this->form->method('isValid')->willReturn(true);
     $this->form->method('getData')->willReturn($this->getBatch());
     $this->manager->expects($this->exactly(2))->method('update')->withConsecutive([$content1], [$content2]);
     $response = $this->controller->batchUpdateAction(new Request());
     $expectedResponse = new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
     $this->assertEquals($expectedResponse, $response);
 }