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 update(Page $page)
 {
     $this->pdo->beginTransaction();
     try {
         $query = $this->executeSql('
             UPDATE pages
                SET title = :title,
                    slug = :slug,
                    short_title = :short_title,
                    sort_order = :sort_order,
                    status = :status
              WHERE page_uuid = :page_uuid
         ', ['page_uuid' => $page->getUuid()->getBytes(), 'title' => $page->getTitle(), 'slug' => $page->getSlug(), 'short_title' => $page->getShortTitle(), 'sort_order' => $page->getSortOrder(), 'status' => $page->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->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
Example #3
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);
 }
Example #4
0
 public function it_will_roll_back_on_error_during_update(Page $page)
 {
     $uuid = Uuid::uuid4();
     $title = 'The Torment of Tantalus';
     $slug = '1x10_the_torment_of_tantalus';
     $shortTitle = '1x10';
     $sortOrder = 110;
     $status = PageStatusValue::get('published');
     $page->getUuid()->willReturn($uuid);
     $page->getTitle()->willReturn($title);
     $page->getSlug()->willReturn($slug);
     $page->getShortTitle()->willReturn($shortTitle);
     $page->getSortOrder()->willReturn($sortOrder);
     $page->getStatus()->willReturn($status);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE pages'))->willThrow(new \RuntimeException());
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow(\RuntimeException::class)->duringUpdate($page);
 }