Example #1
0
 public function it_can_transform_page_to_array()
 {
     $attributes = $this->getAttributes($this->page);
     $attributes['title']->shouldBe($this->page->getTitle());
     $attributes['slug']->shouldBe($this->page->getSlug());
     $attributes['short_title']->shouldBe($this->page->getShortTitle());
     $attributes['parent_uuid']->shouldBe($this->page->getParentUuid()->toString());
     $attributes['sort_order']->shouldBe($this->page->getSortOrder());
     $attributes['status']->shouldBe($this->page->getStatus()->toString());
     $attributes['meta']->shouldBe(['created' => $this->page->metaDataGetCreatedTimestamp()->format('c'), 'updated' => $this->page->metaDataGetUpdatedTimestamp()->format('c')]);
 }
Example #2
0
 public function create(Page $page)
 {
     $this->pdo->beginTransaction();
     try {
         $this->objectRepository->create(Page::TYPE, $page->getUuid());
         $this->executeSql('
             INSERT INTO pages (page_uuid, title, slug, short_title, parent_uuid, sort_order, status)
                  VALUES (:page_uuid, :title, :slug, :short_title, :parent_uuid, :sort_order, :status)
         ', ['page_uuid' => $page->getUuid()->getBytes(), 'title' => $page->getTitle(), 'slug' => $page->getSlug(), 'short_title' => $page->getShortTitle(), 'parent_uuid' => $page->getParentUuid() ? $page->getParentUuid()->getBytes() : null, 'sort_order' => $page->getSortOrder(), 'status' => $page->getStatus()->toString()]);
         $this->pdo->commit();
         $page->metaDataSetInsertTimestamp(new \DateTimeImmutable());
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
Example #3
0
 public function it_can_create_a_page(Page $page, \PDOStatement $statement)
 {
     $uuid = Uuid::uuid4();
     $title = 'Cold Lazarus';
     $slug = '1x08_cold_lazarus';
     $shortTitle = '1x08';
     $parentUuid = Uuid::uuid4();
     $sortOrder = 108;
     $status = PageStatusValue::get('published');
     $page->getUuid()->willReturn($uuid);
     $page->getTitle()->willReturn($title);
     $page->getSlug()->willReturn($slug);
     $page->getShortTitle()->willReturn($shortTitle);
     $page->getParentUuid()->willReturn($parentUuid);
     $page->getSortOrder()->willReturn($sortOrder);
     $page->getStatus()->willReturn($status);
     $page->metaDataSetInsertTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->willReturn($page);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->objectRepository->create(Page::TYPE, $uuid)->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('INSERT INTO pages'))->willReturn($statement);
     $statement->execute(['page_uuid' => $uuid->getBytes(), 'title' => $title, 'slug' => $slug, 'short_title' => $shortTitle, 'parent_uuid' => $parentUuid->getBytes(), 'sort_order' => $sortOrder, 'status' => $status->toString()])->shouldBeCalled();
     $this->pdo->commit()->shouldBeCalled();
     $this->create($page);
 }
Example #4
0
 public function it_errors_when_parent_doesnt_match_page(RequestInterface $request, Page $page1)
 {
     $parentUuid = Uuid::uuid4();
     $page1Uuid = Uuid::uuid4();
     $page1->getUuid()->willReturn($page1Uuid);
     $page1->getParentUuid()->willReturn(Uuid::uuid4());
     $page1->getSortOrder()->willReturn(1);
     $this->pageRepository->getByUuid($page1Uuid)->willReturn($page1);
     $orderedPageUuids = [['page_uuid' => $page1Uuid->toString()]];
     $request->getAcceptContentType()->willReturn('*/*');
     $request->offsetGet('ordered_pages')->willReturn($orderedPageUuids);
     $request->offsetGet('parent_uuid')->willReturn($parentUuid->toString());
     $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request);
 }