-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCorePagePropertyProviderTest.php
More file actions
92 lines (72 loc) · 2.81 KB
/
Copy pathCorePagePropertyProviderTest.php
File metadata and controls
92 lines (72 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare( strict_types = 1 );
namespace ProfessionalWiki\NeoWiki\Tests\Persistence;
use PHPUnit\Framework\TestCase;
use ProfessionalWiki\NeoWiki\Domain\Page\PageDateTime;
use ProfessionalWiki\NeoWiki\Domain\Page\PageId;
use ProfessionalWiki\NeoWiki\Domain\Page\PagePropertyProviderContext;
use ProfessionalWiki\NeoWiki\Persistence\CorePagePropertyProvider;
/**
* @covers \ProfessionalWiki\NeoWiki\Persistence\CorePagePropertyProvider
*/
class CorePagePropertyProviderTest extends TestCase {
public function testReturnsExpectedKeys(): void {
$properties = $this->getPropertiesForContext();
$this->assertSame(
[ 'name', 'namespaceId', 'creationTime', 'lastUpdated', 'categories', 'lastEditor' ],
array_keys( $properties )
);
}
public function testNameMatchesPageTitle(): void {
$properties = $this->getPropertiesForContext( pageTitle: 'Test Page' );
$this->assertSame( 'Test Page', $properties['name'] );
}
public function testNamespaceIdMatchesContext(): void {
$properties = $this->getPropertiesForContext( namespaceId: 12 );
$this->assertSame( 12, $properties['namespaceId'] );
}
public function testCreationTimeIsPageDateTime(): void {
$properties = $this->getPropertiesForContext( creationTime: '20230726163439' );
$this->assertInstanceOf( PageDateTime::class, $properties['creationTime'] );
$this->assertSame( '20230726163439', $properties['creationTime']->timestamp );
}
public function testLastUpdatedIsPageDateTime(): void {
$properties = $this->getPropertiesForContext( modificationTime: '20240315100000' );
$this->assertInstanceOf( PageDateTime::class, $properties['lastUpdated'] );
$this->assertSame( '20240315100000', $properties['lastUpdated']->timestamp );
}
public function testCategoriesMatchContext(): void {
$properties = $this->getPropertiesForContext( categories: [ 'CatA', 'CatB' ] );
$this->assertSame( [ 'CatA', 'CatB' ], $properties['categories'] );
}
public function testLastEditorMatchesContext(): void {
$properties = $this->getPropertiesForContext( lastEditor: 'JohnDoe' );
$this->assertSame( 'JohnDoe', $properties['lastEditor'] );
}
/**
* @param string[] $categories
*/
private function getPropertiesForContext(
string $pageTitle = 'Default Title',
int $namespaceId = 0,
string $creationTime = '20230101000000',
string $modificationTime = '20230101000000',
array $categories = [],
string $lastEditor = 'DefaultEditor',
): array {
return ( new CorePagePropertyProvider() )->getProperties(
new PagePropertyProviderContext(
pageId: new PageId( 1 ),
pageTitle: $pageTitle,
namespaceId: $namespaceId,
creationTime: $creationTime,
modificationTime: $modificationTime,
categories: $categories,
lastEditor: $lastEditor,
content: 'Whatever content',
contentModel: 'wikitext',
parserProperties: [],
)
);
}
}