public function it_can_transform_page_to_array() { $attributes = $this->getAttributes($this->block); $attributes['type']->shouldBe($this->block->getType()); $attributes['parameters']->shouldBe($this->block->getParameters()); $attributes['location']->shouldBe($this->block->getLocation()); $attributes['sort_order']->shouldBe($this->block->getSortOrder()); $attributes['status']->shouldBe($this->block->getStatus()->toString()); $attributes['meta']->shouldBe(['created' => $this->block->metaDataGetCreatedTimestamp()->format('c'), 'updated' => $this->block->metaDataGetUpdatedTimestamp()->format('c')]); }
public function it_can_add_a_block_to_a_page(Page $page, PageBlock $block, \PDOStatement $statement) { $uuid = Uuid::uuid4(); $page->getUuid()->willReturn($uuid); $page->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled(); $blockUuid = Uuid::uuid4(); $blockType = 'type'; $blockLocation = 'main'; $blockSortOrder = 42; $blockStatus = PageStatusValue::get('concept'); $block->getUuid()->willReturn($blockUuid); $block->getPage()->willReturn($page); $block->getType()->willReturn($blockType); $block->getParameters()->willReturn([]); $block->getLocation()->willReturn($blockLocation); $block->getSortOrder()->willReturn($blockSortOrder); $block->getStatus()->willReturn($blockStatus); $block->metaDataSetInsertTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled(); $this->pdo->beginTransaction()->shouldBeCalled(); $this->objectRepository->create(PageBlock::TYPE, $blockUuid)->shouldBeCalled(); $this->pdo->prepare(new Argument\Token\StringContainsToken('INSERT INTO page_blocks'))->willReturn($statement); $statement->execute(['page_block_uuid' => $blockUuid->getBytes(), 'page_uuid' => $uuid->getBytes(), 'type' => $blockType, 'parameters' => json_encode([]), 'location' => $blockLocation, 'sort_order' => $blockSortOrder, 'status' => $blockStatus->toString()])->shouldBeCalled(); $this->objectRepository->update(Page::TYPE, $uuid)->shouldBeCalled(); $this->pdo->commit()->shouldBeCalled(); $this->addBlockToPage($block, $page); }
public function addBlockToPage(PageBlock $block, Page $page) { if (!$page->getUuid()->equals($block->getPage()->getUuid())) { throw new \OutOfBoundsException('PageBlock must belong to page to be added to it.'); } $this->pdo->beginTransaction(); try { $this->objectRepository->create(PageBlock::TYPE, $block->getUuid()); $this->executeSql(' INSERT INTO page_blocks (page_block_uuid, page_uuid, type, parameters, location, sort_order, status) VALUES (:page_block_uuid, :page_uuid, :type, :parameters, :location, :sort_order, :status) ', ['page_block_uuid' => $block->getUuid()->getBytes(), 'page_uuid' => $block->getPage()->getUuid()->getBytes(), 'type' => $block->getType(), 'parameters' => json_encode($block->getParameters()), 'location' => $block->getLocation(), 'sort_order' => $block->getSortOrder(), 'status' => $block->getStatus()->toString()]); $this->objectRepository->update(Page::TYPE, $page->getUuid()); $page->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); $this->pdo->commit(); $block->metaDataSetInsertTimestamp(new \DateTimeImmutable()); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
public function it_can_execute_a_request_part_deux(RequestInterface $request, Page $page, PageBlock $pageBlock) { $pageUuid = Uuid::uuid4(); $pageBlockUuid = Uuid::uuid4(); $newStatus = PageStatusValue::get(PageStatusValue::DELETED); $request->offsetExists('page_uuid')->willReturn(true); $request->offsetGet('page_uuid')->willReturn($pageUuid->toString()); $request->offsetExists('uuid')->willReturn(true); $request->offsetGet('uuid')->willReturn($pageBlockUuid->toString()); $request->offsetExists('parameters')->willReturn(false); $request->offsetExists('sort_order')->willReturn(false); $request->offsetExists('status')->willReturn(true); $request->offsetGet('status')->willReturn($newStatus->toString()); $request->getAcceptContentType()->willReturn('text/xml'); $pageBlock->getType()->willReturn('type'); $pageBlock->setStatus($newStatus)->shouldBeCalled(); $this->pageRepository->getByUuid($pageUuid)->willReturn($page); $page->getBlockByUuid($pageBlockUuid)->willReturn($pageBlock); $pageBlock->getParameters()->willReturn(['content' => 'test']); $this->blockTypeContainer->getType('type')->willReturn(new HtmlContentBlockType()); $this->pageRepository->updateBlockForPage($pageBlock, $page)->shouldBeCalled(); $response = $this->executeRequest($request); $response['data']->shouldBe($pageBlock); }