コード例 #1
0
 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')]);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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;
     }
 }