Пример #1
0
 public function executeRequest(RequestInterface $request) : ResponseInterface
 {
     try {
         $page = $this->pageRepository->getByUuid(Uuid::fromString($request['id']));
         $pageBlock = $this->createBlockFromRequest($request, $page);
         $this->pageRepository->addBlockToPage($pageBlock, $page);
         return new Response(self::MESSAGE, ['data' => $pageBlock, 'includes' => ['pages']], $request);
     } catch (NoResultException $exception) {
         return new NotFoundResponse([], $request);
     } catch (\Throwable $exception) {
         $this->log(LogLevel::ERROR, $exception->getMessage());
         throw new ResponseException('An error occurred during AddPageBlockHandler.', new ServerErrorResponse([], $request));
     }
 }
Пример #2
0
 public function it_can_execute_a_request(RequestInterface $request, Page $page)
 {
     $uuid = Uuid::uuid4();
     $attributes = ['type' => 'type', 'parameters' => ['content' => 1138], 'location' => 'main', 'sort_order' => 52, 'status' => PageStatusValue::CONCEPT];
     $request->offsetGet('id')->willReturn($uuid->toString());
     $request->offsetGet('attributes')->willReturn($attributes);
     $request->getAcceptContentType()->willReturn('application/json');
     $this->pageRepository->getByUuid($uuid)->willReturn($page);
     $this->blockTypeContainer->getType('type')->willReturn(new HtmlContentBlockType());
     $this->pageRepository->addBlockToPage(new Argument\Token\TypeToken(PageBlock::class), $page)->shouldBeCalled();
     $response = $this->executeRequest($request);
     $response->shouldHaveType(ResponseInterface::class);
     $response['data']->shouldHaveType(PageBlock::class);
     $response['includes']->shouldBe(['pages']);
 }