|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Ibexa\Tests\Rest\Server\Output\ValueObjectVisitor; |
| 10 | + |
| 11 | +use DateTime; |
| 12 | +use DOMDocument; |
| 13 | +use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; |
| 14 | +use Ibexa\Contracts\Core\Repository\Values\Content\Location; |
| 15 | +use Ibexa\Core\Repository\Values\ContentType\ContentType; |
| 16 | +use Ibexa\Tests\Rest\Output\ValueObjectVisitorBaseTest; |
| 17 | + |
| 18 | +abstract class BaseContentValueObjectVisitorTestCase extends ValueObjectVisitorBaseTest |
| 19 | +{ |
| 20 | + abstract public function testVisitWithoutEmbeddedVersion(): DOMDocument; |
| 21 | + |
| 22 | + abstract protected function getXPathFirstElementName(): string; |
| 23 | + |
| 24 | + protected function getContentInfoStub(): ContentInfo |
| 25 | + { |
| 26 | + return new ContentInfo( |
| 27 | + [ |
| 28 | + 'id' => 22, |
| 29 | + 'name' => 'Sindelfingen', |
| 30 | + 'sectionId' => 23, |
| 31 | + 'currentVersionNo' => 5, |
| 32 | + 'published' => true, |
| 33 | + 'ownerId' => 24, |
| 34 | + 'modificationDate' => new DateTime('2012-09-05 15:27 Europe/Berlin'), |
| 35 | + 'publishedDate' => new DateTime('2012-09-05 15:27 Europe/Berlin'), |
| 36 | + 'alwaysAvailable' => true, |
| 37 | + 'status' => ContentInfo::STATUS_PUBLISHED, |
| 38 | + 'remoteId' => 'abc123', |
| 39 | + 'mainLanguageCode' => 'eng-US', |
| 40 | + 'mainLocationId' => 25, |
| 41 | + 'contentTypeId' => 26, |
| 42 | + 'contentType' => new ContentType(['id' => 26]), |
| 43 | + 'isHidden' => true, |
| 44 | + ] |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @depends testVisitWithoutEmbeddedVersion |
| 50 | + */ |
| 51 | + public function testNameCorrect(DOMDocument $dom): void |
| 52 | + { |
| 53 | + $this->assertXPath($dom, sprintf('/%s/name[text()="Sindelfingen"]', $this->getXPathFirstElementName())); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @depends testVisitWithoutEmbeddedVersion |
| 58 | + */ |
| 59 | + public function testVersionsHrefCorrect(DOMDocument $dom): void |
| 60 | + { |
| 61 | + $this->assertXPath($dom, sprintf('/%s/Versions[@href="/content/objects/22/versions"]', $this->getXPathFirstElementName())); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @depends testVisitWithoutEmbeddedVersion |
| 66 | + */ |
| 67 | + public function testVersionsMediaTypeCorrect(DOMDocument $dom): void |
| 68 | + { |
| 69 | + $this->assertXPath($dom, sprintf('/%s/Versions[@media-type="application/vnd.ibexa.api.VersionList+xml"]', $this->getXPathFirstElementName())); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @depends testVisitWithoutEmbeddedVersion |
| 74 | + */ |
| 75 | + public function testSectionHrefCorrect(DOMDocument $dom): void |
| 76 | + { |
| 77 | + $this->assertXPath($dom, sprintf('/%s/Section[@href="/content/sections/23"]', $this->getXPathFirstElementName())); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @depends testVisitWithoutEmbeddedVersion |
| 82 | + */ |
| 83 | + public function testSectionMediaTypeCorrect(DOMDocument $dom): void |
| 84 | + { |
| 85 | + $this->assertXPath($dom, sprintf('/%s/Section[@media-type="application/vnd.ibexa.api.Section+xml"]', $this->getXPathFirstElementName())); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @depends testVisitWithoutEmbeddedVersion |
| 90 | + */ |
| 91 | + public function testMainLocationHrefCorrect(DOMDocument $dom): void |
| 92 | + { |
| 93 | + $this->assertXPath($dom, sprintf('/%s/MainLocation[@href="/content/locations/1/2/23"]', $this->getXPathFirstElementName())); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @depends testVisitWithoutEmbeddedVersion |
| 98 | + */ |
| 99 | + public function testMainLocationMediaTypeCorrect(DOMDocument $dom): void |
| 100 | + { |
| 101 | + $this->assertXPath($dom, sprintf('/%s/MainLocation[@media-type="application/vnd.ibexa.api.Location+xml"]', $this->getXPathFirstElementName())); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @depends testVisitWithoutEmbeddedVersion |
| 106 | + */ |
| 107 | + public function testLocationsHrefCorrect(DOMDocument $dom): void |
| 108 | + { |
| 109 | + $this->assertXPath($dom, sprintf('/%s/Locations[@href="/content/objects/22/locations"]', $this->getXPathFirstElementName())); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * @depends testVisitWithoutEmbeddedVersion |
| 114 | + */ |
| 115 | + public function testLocationsMediaTypeCorrect(DOMDocument $dom): void |
| 116 | + { |
| 117 | + $this->assertXPath($dom, sprintf('/%s/Locations[@media-type="application/vnd.ibexa.api.LocationList+xml"]', $this->getXPathFirstElementName())); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * @depends testVisitWithoutEmbeddedVersion |
| 122 | + */ |
| 123 | + public function testOwnerHrefCorrect(DOMDocument $dom): void |
| 124 | + { |
| 125 | + $this->assertXPath($dom, sprintf('/%s/Owner[@href="/user/users/24"]', $this->getXPathFirstElementName())); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * @depends testVisitWithoutEmbeddedVersion |
| 130 | + */ |
| 131 | + public function testOwnerMediaTypeCorrect(DOMDocument $dom): void |
| 132 | + { |
| 133 | + $this->assertXPath($dom, sprintf('/%s/Owner[@media-type="application/vnd.ibexa.api.User+xml"]', $this->getXPathFirstElementName())); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @depends testVisitWithoutEmbeddedVersion |
| 138 | + */ |
| 139 | + public function testLastModificationDateCorrect(DOMDocument $dom): void |
| 140 | + { |
| 141 | + $this->assertXPath($dom, sprintf('/%s/lastModificationDate[text()="2012-09-05T15:27:00+02:00"]', $this->getXPathFirstElementName())); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @depends testVisitWithoutEmbeddedVersion |
| 146 | + */ |
| 147 | + public function testMainLanguageCodeCorrect(DOMDocument $dom): void |
| 148 | + { |
| 149 | + $this->assertXPath($dom, sprintf('/%s/mainLanguageCode[text()="eng-US"]', $this->getXPathFirstElementName())); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * @depends testVisitWithoutEmbeddedVersion |
| 154 | + */ |
| 155 | + public function testAlwaysAvailableCorrect(DOMDocument $dom): void |
| 156 | + { |
| 157 | + $this->assertXPath($dom, sprintf('/%s/alwaysAvailable[text()="true"]', $this->getXPathFirstElementName())); |
| 158 | + } |
| 159 | + |
| 160 | + protected function addContentRouteExpectations(ContentInfo $contentInfo, Location $location): void |
| 161 | + { |
| 162 | + $contentId = $contentInfo->getId(); |
| 163 | + $contentTypeId = $contentInfo->getContentType()->id; |
| 164 | + $sectionId = $contentInfo->getSectionId(); |
| 165 | + |
| 166 | + $this->addRouteExpectation( |
| 167 | + 'ibexa.rest.load_content_type', |
| 168 | + ['contentTypeId' => $contentTypeId], |
| 169 | + "/content/types/$contentTypeId" |
| 170 | + ); |
| 171 | + $this->addRouteExpectation( |
| 172 | + 'ibexa.rest.load_content_versions', |
| 173 | + ['contentId' => $contentId], |
| 174 | + "/content/objects/$contentId/versions" |
| 175 | + ); |
| 176 | + $this->addRouteExpectation( |
| 177 | + 'ibexa.rest.load_section', |
| 178 | + ['sectionId' => $sectionId], |
| 179 | + "/content/sections/$sectionId" |
| 180 | + ); |
| 181 | + $locationPath = trim($location->getPathString(), '/'); |
| 182 | + $this->addRouteExpectation( |
| 183 | + 'ibexa.rest.load_location', |
| 184 | + ['locationPath' => $locationPath], |
| 185 | + "/content/locations/$locationPath" |
| 186 | + ); |
| 187 | + $this->addRouteExpectation( |
| 188 | + 'ibexa.rest.load_locations_for_content', |
| 189 | + ['contentId' => $contentId], |
| 190 | + "/content/objects/$contentId/locations" |
| 191 | + ); |
| 192 | + } |
| 193 | +} |
0 commit comments