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('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('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('content'); $validator->optional('wysiwyg')->bool(); $result = $validator->validate($block->getParameters()); if (!$result->isValid()) { throw new ValidationFailedException($result, $request); } }
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_will_error_when_trying_to_delete_a_block_from_wrong_page(Page $page1, Page $page2, PageBlock $block) { $uuid1 = Uuid::uuid4(); $page1->getUuid()->willReturn($uuid1); $uuid2 = Uuid::uuid4(); $page2->getUuid()->willReturn($uuid2); $block->getPage()->willReturn($page2); $this->shouldThrow(\OutOfBoundsException::class)->duringDeleteBlockFromPage($block, $page1); }
public function deleteBlockFromPage(PageBlock $block, Page $page) { if (!$page->getUuid()->equals($block->getPage()->getUuid())) { throw new \OutOfBoundsException('PageBlock must belong to page to be added to it.'); } // The database constraint should cascade the delete to the page $this->objectRepository->delete(PageBlock::TYPE, $block->getUuid()); $page->removeBlock($block); $this->objectRepository->update(Page::TYPE, $page->getUuid()); $page->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); $block->setStatus(PageStatusValue::get(PageStatusValue::DELETED)); }
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_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); }
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); }
public function it_errors_when_a_specific_block_does_not_exist(PageBlock $block1, PageBlock $block2, PageBlock $block3) { $uuid1 = Uuid::uuid4(); $block1->getUuid()->willReturn($uuid1); $block1->getSortOrder()->willReturn(1); $uuid2 = Uuid::uuid4(); $block2->getUuid()->willReturn($uuid2); $block2->getSortOrder()->willReturn(2); $uuid3 = Uuid::uuid4(); $block3->getUuid()->willReturn($uuid3); $block3->getSortOrder()->willReturn(3); $this->setBlocks([$block1, $block2, $block3])->shouldReturn($this); $this->shouldThrow(NoResultException::class)->duringGetBlockByUuid(Uuid::uuid4()); }
public function removeBlock(PageBlock $block) : Page { foreach ($this->getBlocks() as $idx => $relBlock) { if ($relBlock->getUuid()->equals($block->getUuid())) { unset($this->relatedBlocks[$idx]); $this->relatedBlocks = array_merge($this->relatedBlocks); return $this; } } throw new NoResultException('Block not found in Page\'s blocks: ' . $block->getUuid()->toString()); }
private function setBlockStatus(PageBlock $block, RequestInterface $request) { if (isset($request['status'])) { $block->setStatus(PageStatusValue::get($request['status'])); } }