Debian Codegraph @

vendor/wikimedia/parsoid/tests/phpunit/Parsoid/Config/Api/PageConfigTest.php

raw
1 <?php
2
3 namespace Test\Parsoid\Config\Api;
4
5 use Wikimedia\Parsoid\Config\Api\PageConfig;
6 use Wikimedia\Parsoid\Config\PageContent;
7 use Wikimedia\Parsoid\Mocks\MockSiteConfig;
8 use Wikimedia\Parsoid\Utils\Title;
9
10 /**
11 * @covers \Wikimedia\Parsoid\Config\Api\PageConfig
12 */
13 class PageConfigTest extends \PHPUnit\Framework\TestCase {
14
15 private static $pageConfigs = [];
16
17 protected function getPageConfig( string $id ): PageConfig {
18 if ( !self::$pageConfigs ) {
19 foreach (
20 [
21 'missing' => 'ThisPageDoesNotExist',
22 'existing' => 'Help:Sample_page',
23 ] as $name => $titleText
24 ) {
25 $helper = new TestApiHelper( $this, $name . 'page' );
26 $siteConfig = new MockSiteConfig( [] );
27 $title = Title::newFromText( $titleText, $siteConfig );
28 self::$pageConfigs[$name] = new PageConfig( $helper, $siteConfig, [ 'title' => $title ] );
29 }
30 }
31
32 return self::$pageConfigs[$id];
33 }
34
35 public function testGetTitle() {
36 $this->assertSame(
37 'ThisPageDoesNotExist',
38 $this->getPageConfig( 'missing' )->getLinkTarget()->getPrefixedText()
39 );
40 $this->assertSame(
41 'Help:Sample page',
42 $this->getPageConfig( 'existing' )->getLinkTarget()->getPrefixedText()
43 );
44 }
45
46 public function testGetNs() {
47 $this->assertSame( 0, $this->getPageConfig( 'missing' )->getNs() );
48 $this->assertSame( 12, $this->getPageConfig( 'existing' )->getNs() );
49 }
50
51 public function testGetPageId() {
52 $this->assertSame( -1, $this->getPageConfig( 'missing' )->getPageId() );
53 $this->assertSame( 53796160, $this->getPageConfig( 'existing' )->getPageId() );
54 }
55
56 public function testGetPageLanguage() {
57 $this->assertEqualsIgnoringCase(
58 'en',
59 $this->getPageConfig( 'missing' )->getPageLanguageBcp47()->toBcp47Code()
60 );
61 $this->assertEqualsIgnoringCase(
62 'en',
63 $this->getPageConfig( 'existing' )->getPageLanguageBcp47()->toBcp47Code()
64 );
65 }
66
67 public function testGetPageLanguageDir() {
68 $this->assertSame( 'ltr', $this->getPageConfig( 'missing' )->getPageLanguageDir() );
69 $this->assertSame( 'ltr', $this->getPageConfig( 'existing' )->getPageLanguageDir() );
70 }
71
72 public function testGetRevisionId() {
73 $this->assertNull( $this->getPageConfig( 'missing' )->getRevisionId() );
74 $this->assertSame( 857016953, $this->getPageConfig( 'existing' )->getRevisionId() );
75 }
76
77 public function testGetParentRevisionId() {
78 $this->assertNull( $this->getPageConfig( 'missing' )->getParentRevisionId() );
79 $this->assertSame( 817557113, $this->getPageConfig( 'existing' )->getParentRevisionId() );
80 }
81
82 public function testGetRevisionTimestamp() {
83 $this->assertNull( $this->getPageConfig( 'missing' )->getRevisionTimestamp() );
84 $this->assertSame( '20180829005516', $this->getPageConfig( 'existing' )->getRevisionTimestamp() );
85 }
86
87 public function testGetRevisionUser() {
88 $this->assertNull( $this->getPageConfig( 'missing' )->getRevisionUser() );
89 $this->assertSame( 'JCW-CleanerBot', $this->getPageConfig( 'existing' )->getRevisionUser() );
90 }
91
92 public function testGetRevisionUserId() {
93 $this->assertNull( $this->getPageConfig( 'missing' )->getRevisionUserId() );
94 $this->assertSame( 31737083, $this->getPageConfig( 'existing' )->getRevisionUserId() );
95 }
96
97 public function testGetRevisionSha1() {
98 $this->assertNull( $this->getPageConfig( 'missing' )->getRevisionSha1() );
99 $this->assertSame(
100 '27d4d91a06e8df01f33a2577e00305a81cd30bf0',
101 $this->getPageConfig( 'existing' )->getRevisionSha1()
102 );
103 }
104
105 public function testGetRevisionSize() {
106 $this->assertNull( $this->getPageConfig( 'missing' )->getRevisionSize() );
107 $this->assertSame( 1736, $this->getPageConfig( 'existing' )->getRevisionSize() );
108 }
109
110 public function testGetRevisionContent() {
111 $this->assertNull( $this->getPageConfig( 'missing' )->getRevisionContent() );
112
113 $c = $this->getPageConfig( 'existing' )->getRevisionContent();
114 $this->assertInstanceOf( PageContent::class, $c );
115 $this->assertSame( [ 'main' ], $c->getRoles() );
116 $this->assertSame( 'wikitext', $c->getModel( 'main' ) );
117 $this->assertSame( 'text/x-wiki', $c->getFormat( 'main' ) );
118 $this->assertSame(
119 "Our '''world''' is a planet where human beings have formed many societies.\n\n",
120 substr( $c->getContent( 'main' ), 0, 76 )
121 );
122 }
123
124 }