1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace ModernTimeline\Tests\Unit\SlidePresenter; |
6
|
|
|
|
7
|
|
|
use ModernTimeline\ResultFacade\PropertyValueCollection; |
8
|
|
|
use ModernTimeline\ResultFacade\Subject; |
9
|
|
|
use ModernTimeline\SlidePresenter\TemplateSlidePresenter; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use SMW\DIWikiPage; |
12
|
|
|
use SMW\Query\PrintRequest; |
13
|
|
|
use SMWDITime; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \ModernTimeline\SlidePresenter\TemplateSlidePresenter |
17
|
|
|
*/ |
18
|
|
|
class TemplateSlidePresenterTest extends TestCase { |
19
|
|
|
|
20
|
|
|
private const PAGE_NAME = 'Some Page'; |
21
|
|
|
|
22
|
|
|
public function testTemplate() { |
23
|
|
|
$this->assertSame( |
24
|
|
|
'{{TemplateName|title=Some Page|Has date=2 August 2019 16:07:42|End date=5 August 2019 17:39:23}}', |
25
|
|
|
( new TemplateSlidePresenter( 'TemplateName' ) )->getTemplateText( $this->newSinglePageWithStartAndEndDate() ) |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
private function newSinglePageWithStartAndEndDate(): Subject { |
30
|
|
|
return new Subject( |
31
|
|
|
$this->newDiWikiPage(), |
32
|
|
|
[ |
33
|
|
|
new PropertyValueCollection( |
34
|
|
|
$this->newDatePrintRequestWithLabel( 'Has date' ), |
35
|
|
|
[ |
36
|
|
|
new SMWDITime( |
37
|
|
|
SMWDITime::CM_GREGORIAN, |
38
|
|
|
2019, |
39
|
|
|
8, |
40
|
|
|
2, |
41
|
|
|
16, |
42
|
|
|
7, |
43
|
|
|
42 |
44
|
|
|
) |
45
|
|
|
] |
46
|
|
|
), |
47
|
|
|
new PropertyValueCollection( |
48
|
|
|
$this->newDatePrintRequestWithLabel( 'End date' ), |
49
|
|
|
[ |
50
|
|
|
new SMWDITime( |
51
|
|
|
SMWDITime::CM_GREGORIAN, |
52
|
|
|
2019, |
53
|
|
|
8, |
54
|
|
|
5, |
55
|
|
|
17, |
56
|
|
|
39, |
57
|
|
|
23 |
58
|
|
|
) |
59
|
|
|
] |
60
|
|
|
) |
61
|
|
|
] |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function newDiWikiPage(): DIWikiPage { |
66
|
|
|
$page = $this->createMock( DIWikiPage::class ); |
67
|
|
|
|
68
|
|
|
$page->method( 'getTitle' )->willReturn( \Title::newFromText( self::PAGE_NAME ) ); |
69
|
|
|
|
70
|
|
|
return $page; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function newDatePrintRequestWithLabel( string $label ): PrintRequest { |
74
|
|
|
$pr = $this->createMock( PrintRequest::class ); |
75
|
|
|
$pr->method( 'getLabel' )->willReturn( $label ); |
76
|
|
|
$pr->method( 'getText' )->willReturn( $label ); |
77
|
|
|
$pr->method( 'getTypeID' )->willReturn( '_dat' ); |
78
|
|
|
return $pr; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|