Update website

This commit is contained in:
Guilhem Lavaux 2024-11-19 08:02:04 +01:00
parent 4413528994
commit 1d90fbf296
6865 changed files with 1091082 additions and 0 deletions

View file

@ -0,0 +1,125 @@
<?php
declare(strict_types=1);
namespace Doctrine\Tests\RST\References;
use Doctrine\RST\References\ResolvedReference;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use function key;
use function sprintf;
class ResolvedReferenceTest extends TestCase
{
/**
* @param string[] $attributes
*
* @dataProvider attributesValid
*/
public function testCreateResolvedReference(array $attributes): void
{
$resolvedReference = new ResolvedReference('file', 'title', 'url', [['title' => 'title']], $attributes);
self::assertSame('title', $resolvedReference->getTitle());
self::assertSame('url', $resolvedReference->getUrl());
self::assertSame([['title' => 'title']], $resolvedReference->getTitles());
self::assertSame($attributes, $resolvedReference->getAttributes());
}
/** @return array<string, array{attributes: array<string, string>}> */
public function attributesValid(): array
{
return [
'attributes #1' => [
'attributes' => [],
],
'attributes #2' => [
'attributes' => ['foo' => 'bar'],
],
'attributes #3' => [
'attributes' => [
'class' => 'foo bar',
'data-id' => '123456',
],
],
'attributes #4' => [
'attributes' => [
'foo123_.' => 'bar',
'_foo123_.-foo' => 'bar',
],
],
];
}
/**
* @param string[] $attributes
*
* @dataProvider attributesInvalid
*/
public function testCreateResolvedReferenceWithAttributesInvalid(array $attributes): void
{
self::expectException(RuntimeException::class);
self::expectExceptionMessage(sprintf('Attribute with name "%s" is not allowed', key($attributes)));
new ResolvedReference('file', 'title', 'url', [], $attributes);
}
/** @return array<string, array{attributes: array<string|int, string>}> */
public function attributesInvalid(): array
{
return [
'href' => [
'attributes' => ['href' => 'foo'],
],
'illegal char #1' => [
'attributes' => ['attri"bute' => 'foo'],
],
'illegal char #2' => [
'attributes' => ['attri#bute' => 'foo'],
],
'illegal char #3' => [
'attributes' => ['attri"bute' => 'foo'],
],
'illegal char #4' => [
'attributes' => ['attri\'bute' => 'foo'],
],
'illegal char #5' => [
'attributes' => ['attri&bute' => 'foo'],
],
'starts with illegal char #1' => [
'attributes' => ['1attribute' => 'foo'],
],
'starts with illegal char #2' => [
'attributes' => ['-attribute' => 'foo'],
],
'starts with illegal char #3' => [
'attributes' => ['.attribute' => 'foo'],
],
'starts with illegal char #4' => [
'attributes' => ['#attribute' => 'foo'],
],
'starts with illegal char #5' => [
'attributes' => ['"attribute' => 'foo'],
],
'non string' => [
'attributes' => [5 => 'foo'],
],
];
}
}

View file

@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
namespace Doctrine\Tests\RST\References;
use Doctrine\RST\Environment;
use Doctrine\RST\Meta\MetaEntry;
use Doctrine\RST\Meta\Metas;
use Doctrine\RST\References\ResolvedReference;
use Doctrine\RST\References\Resolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class ResolverTest extends TestCase
{
/** @var Environment|MockObject */
private $environment;
/** @var Metas|MockObject */
private $metas;
/** @var MetaEntry|MockObject */
private $metaEntry;
/** @var Resolver */
private $resolver;
protected function setUp(): void
{
$this->environment = $this->createMock(Environment::class);
$this->metas = $this->createMock(Metas::class);
$this->environment->expects(self::any())
->method('getMetas')
->willReturn($this->metas);
$this->metaEntry = $this->createMock(MetaEntry::class);
$this->metaEntry->expects(self::any())
->method('getUrl')
->willReturn('url');
$this->metaEntry->expects(self::any())
->method('getTitle')
->willReturn('title');
$this->metaEntry->expects(self::any())
->method('getTitles')
->willReturn([]);
$this->resolver = new Resolver();
}
public function testResolveFileReference(): void
{
$this->environment->expects(self::once())
->method('canonicalUrl')
->willReturn('file');
$this->metas->expects(self::once())
->method('get')
->willReturn($this->metaEntry);
$this->environment->expects(self::once())
->method('relativeUrl')
->willReturn('/url');
self::assertEquals(
new ResolvedReference('file', 'title', '/url', [], ['attr' => 'value']),
$this->resolver->resolve($this->environment, 'url', ['attr' => 'value'])
);
}
public function testResolveAnchorReference(): void
{
$this->environment->expects(self::once())
->method('canonicalUrl')
->willReturn(null);
$this->metas->expects(self::once())
->method('findLinkMetaEntry')
->willReturn($this->metaEntry);
$this->environment->expects(self::once())
->method('relativeUrl')
->willReturn('/url');
self::assertEquals(
new ResolvedReference('', 'title', '/url#anchor', [], ['attr' => 'value']),
$this->resolver->resolve($this->environment, 'anchor', ['attr' => 'value'])
);
}
public function testUnResolvedReference1(): void
{
$this->environment->expects(self::once())
->method('canonicalUrl')
->willReturn(null);
$this->metas->expects(self::once())
->method('findLinkMetaEntry')
->willReturn(null);
self::assertNull($this->resolver->resolve($this->environment, 'invalid-reference'));
}
public function testUnResolvedReference2(): void
{
$this->environment->expects(self::once())
->method('canonicalUrl')
->willReturn('file');
$this->metas->expects(self::once())
->method('get')
->willReturn(null);
$this->metas->expects(self::once())
->method('findLinkMetaEntry')
->willReturn(null);
self::assertNull($this->resolver->resolve($this->environment, 'invalid-reference'));
}
}