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_execute_a_request(RequestInterface $request, Page $page, PageBlock $pageBlock) { $pageUuid = Uuid::uuid4(); $pageBlockUuid = Uuid::uuid4(); $parameters = ['content' => 42, 'new_gods' => 7]; $sortOrder = 2; $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(true); $request->offsetGet('parameters')->willReturn($parameters); $request->offsetExists('sort_order')->willReturn(true); $request->offsetGet('sort_order')->willReturn($sortOrder); $request->offsetExists('status')->willReturn(false); $request->getAcceptContentType()->willReturn('text/xml'); $pageBlock->offsetSet('content', $parameters['content'])->shouldBeCalled(); $pageBlock->offsetSet('new_gods', $parameters['new_gods'])->shouldBeCalled(); $pageBlock->getType()->willReturn('type'); $pageBlock->getParameters()->willReturn($parameters); $pageBlock->setSortOrder($sortOrder)->shouldBeCalled(); $this->pageRepository->getByUuid($pageUuid)->willReturn($page); $page->getBlockByUuid($pageBlockUuid)->willReturn($pageBlock); $this->blockTypeContainer->getType('type')->willReturn(new HtmlContentBlockType()); $this->pageRepository->updateBlockForPage($pageBlock, $page)->shouldBeCalled(); $response = $this->executeRequest($request); $response['data']->shouldBe($pageBlock); }
public function validate(PageBlock $block, RequestInterface $request) { $validator = new Validator(); $validator->required('feedUrl')->url(['http', 'https']); $result = $validator->validate($block->getParameters()); if (!$result->isValid()) { throw new ValidationFailedException($result, $request); } }
public function validate(PageBlock $block, RequestInterface $request) { $validator = new Validator(); $validator->required('youtubeUrl')->regex('#^https:\\/\\/(www\\.youtube\\.com\\/watch\\?v=|youtu\\.be\\/)[a-z0-9_]+#uiD'); $result = $validator->validate($block->getParameters()); if (!$result->isValid()) { throw new ValidationFailedException($result, $request); } }
public function validate(PageBlock $block, RequestInterface $request) { $validator = new Validator(); $validator->required('vimeoUrl')->regex('#^https://vimeo\\.com/[a-z0-9_]+$#uiD'); $result = $validator->validate($block->getParameters()); if (!$result->isValid()) { throw new ValidationFailedException($result, $request); } }
public function validate(PageBlock $block, RequestInterface $request) { $validator = new Validator(); $validator->required('content'); $validator->optional('wysiwyg')->bool(); $result = $validator->validate($block->getParameters()); if (!$result->isValid()) { throw new ValidationFailedException($result, $request); } }
public function it_can_update_a_block(Page $page, PageBlock $block, \PDOStatement $statement) { $uuid = Uuid::uuid4(); $page->getUuid()->willReturn($uuid); $page->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->shouldBeCalled(); $blockUuid = Uuid::uuid4(); $blockSortOrder = 42; $blockStatus = PageStatusValue::get('concept'); $block->getUuid()->willReturn($blockUuid); $block->getPage()->willReturn($page); $block->getParameters()->willReturn([]); $block->getSortOrder()->willReturn($blockSortOrder); $block->getStatus()->willReturn($blockStatus); $block->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->shouldBeCalled(); $this->pdo->beginTransaction()->shouldBeCalled(); $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE page_blocks'))->willReturn($statement); $statement->execute(['page_block_uuid' => $blockUuid->getBytes(), 'parameters' => json_encode([]), 'sort_order' => $blockSortOrder, 'status' => $blockStatus->toString()])->shouldBeCalled(); $statement->rowCount()->willReturn(1); $this->objectRepository->update(Page::TYPE, $uuid)->shouldBeCalled(); $this->objectRepository->update(PageBlock::TYPE, $blockUuid)->shouldBeCalled(); $this->pdo->commit()->shouldBeCalled(); $this->updateBlockForPage($block, $page); }
public function updateBlockForPage(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 { $query = $this->executeSql(' UPDATE page_blocks SET parameters = :parameters, sort_order = :sort_order, status = :status WHERE page_block_uuid = :page_block_uuid ', ['page_block_uuid' => $block->getUuid()->getBytes(), 'parameters' => json_encode($block->getParameters()), 'sort_order' => $block->getSortOrder(), 'status' => $block->getStatus()->toString()]); // When at least one of the fields changes, the rowCount will be 1 and an update occurred if ($query->rowCount() === 1) { $this->objectRepository->update(Page::TYPE, $page->getUuid()); $page->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); $this->objectRepository->update(PageBlock::TYPE, $block->getUuid()); $block->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); } $this->pdo->commit(); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
public function it_can_invalidate_a_block(PageBlock $block, RequestInterface $request) { $request->getAcceptContentType()->willReturn('*/*'); $block->getParameters()->willReturn(['youtubeUrl' => 'https://vimeo.com/s0m3Ur1']); $this->shouldThrow(ValidationFailedException::class)->duringValidate($block, $request); }
public function it_can_invalidate_a_block(PageBlock $block, RequestInterface $request) { $request->getAcceptContentType()->willReturn('*/*'); $block->getParameters()->willReturn(['feedUrl' => 'not-a-url']); $this->shouldThrow(ValidationFailedException::class)->duringValidate($block, $request); }