-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/2.0.x' into 1.11.x-merge-up-into…
…-2.0.x_lo5L9oGr # Conflicts: # test/Unit/Document/Fragment/FactoryTest.php
- Loading branch information
Showing
19 changed files
with
450 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prismic\Value; | ||
|
||
use JsonSerializable; | ||
use Prismic\Json; | ||
use Stringable; | ||
|
||
use const JSON_FORCE_OBJECT; | ||
|
||
final class RouteResolverSpec implements JsonSerializable, Stringable | ||
{ | ||
/** @param array<string, string> $resolvers */ | ||
public function __construct( | ||
private string $type, | ||
private string $path, | ||
private array $resolvers, | ||
) { | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return Json::encode($this, JSON_FORCE_OBJECT); | ||
} | ||
|
||
/** @return array{type: string, path: string, resolvers: array<string, string>} */ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'path' => $this->path, | ||
'resolvers' => $this->resolvers, | ||
]; | ||
} | ||
|
||
/** @param array{type: string, path: string, resolvers: array<string, string>} $data */ | ||
public static function __set_state(array $data): self | ||
{ | ||
return new self( | ||
$data['type'], | ||
$data['path'], | ||
$data['resolvers'], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrismicTest; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prismic\DefaultLinkResolver; | ||
use Prismic\Document\Fragment\DocumentLink; | ||
use Prismic\Document\Fragment\MediaLink; | ||
use Prismic\Link; | ||
|
||
class DefaultLinkResolverTest extends TestCase | ||
{ | ||
private DefaultLinkResolver $linkResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->linkResolver = new class extends DefaultLinkResolver { | ||
protected function resolveDocumentLink(DocumentLink $link): string|null | ||
{ | ||
return '/some/url'; | ||
} | ||
}; | ||
} | ||
|
||
public function testMediaUrlsReturnTheExpectedUrl(): void | ||
{ | ||
$media = MediaLink::new('/foo', 'whatever.jpg', 1234); | ||
|
||
self::assertSame('/foo', $this->linkResolver->resolve($media)); | ||
} | ||
|
||
public function testDocLinksWillYieldStoredUrlWhenPresent(): void | ||
{ | ||
$docLink = DocumentLink::new('id', 'uid', 'foo', 'en-gb', false, [], '/special'); | ||
|
||
self::assertSame('/special', $this->linkResolver->resolve($docLink)); | ||
} | ||
|
||
public function testDocLinksWillUseCustomResolveWhenNull(): void | ||
{ | ||
$docLink = DocumentLink::new('id', 'uid', 'foo', 'en-gb', false, [], null); | ||
|
||
self::assertSame('/some/url', $this->linkResolver->resolve($docLink)); | ||
} | ||
|
||
public function testUnknownLinkTypesWillYieldNull(): void | ||
{ | ||
$link = $this->createMock(Link::class); | ||
|
||
self::assertNull($this->linkResolver->resolve($link)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.