Debian Codegraph @

vendor/wikimedia/parsoid/src/Mocks/MockPageConfig.php

raw
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Wikimedia\Parsoid\Mocks;
5
6 use Wikimedia\Bcp47Code\Bcp47Code;
7 use Wikimedia\Parsoid\Config\PageConfig;
8 use Wikimedia\Parsoid\Config\PageContent;
9 use Wikimedia\Parsoid\Config\SiteConfig;
10 use Wikimedia\Parsoid\Core\LinkTarget;
11 use Wikimedia\Parsoid\Utils\Title;
12 use Wikimedia\Parsoid\Utils\Utils;
13
14 class MockPageConfig extends PageConfig {
15 private SiteConfig $siteConfig;
16
17 /** @var ?PageContent */
18 private $content;
19
20 /** @var int */
21 private $pageid;
22
23 private Title $title;
24
25 private Bcp47Code $pagelanguage;
26
27 /** @var ?string */
28 private $pagelanguageDir;
29
30 /**
31 * Construct a mock environment object for use in tests
32 * @param SiteConfig $siteConfig
33 * @param array $opts
34 * @param ?PageContent $content
35 */
36 public function __construct( SiteConfig $siteConfig, array $opts, ?PageContent $content ) {
37 $this->siteConfig = $siteConfig;
38 $this->content = $content;
39 $this->title = Title::newFromText( $opts['title'] ?? 'TestPage', $siteConfig, $opts['pagens'] ?? null );
40 $this->pageid = $opts['pageid'] ?? -1;
41 $this->pagelanguage = Utils::mwCodeToBcp47( $opts['pageLanguage'] ?? 'en' );
42 $this->pagelanguageDir = $opts['pageLanguageDir'] ?? null;
43 }
44
45 /** @inheritDoc */
46 public function getContentModel(): string {
47 return 'wikitext';
48 }
49
50 /** @inheritDoc */
51 public function getLinkTarget(): LinkTarget {
52 return $this->title;
53 }
54
55 /** @inheritDoc */
56 public function getPageId(): int {
57 return $this->pageid;
58 }
59
60 /** @inheritDoc */
61 public function getPageLanguageBcp47(): Bcp47Code {
62 return $this->pagelanguage;
63 }
64
65 /** @inheritDoc */
66 public function getPageLanguageDir(): string {
67 return $this->pagelanguageDir ?? 'rtl';
68 }
69
70 /** @inheritDoc */
71 public function getRevisionId(): ?int {
72 return 1;
73 }
74
75 /** @inheritDoc */
76 public function getParentRevisionId(): ?int {
77 return null;
78 }
79
80 /** @inheritDoc */
81 public function getRevisionTimestamp(): ?string {
82 return null;
83 }
84
85 /** @inheritDoc */
86 public function getRevisionUser(): ?string {
87 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
88 throw new \BadMethodCallException( 'Not implemented' );
89 }
90
91 /** @inheritDoc */
92 public function getRevisionUserId(): ?int {
93 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
94 throw new \BadMethodCallException( 'Not implemented' );
95 }
96
97 /** @inheritDoc */
98 public function getRevisionSha1(): ?string {
99 return null;
100 }
101
102 /** @inheritDoc */
103 public function getRevisionSize(): ?int {
104 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
105 throw new \BadMethodCallException( 'Not implemented' );
106 }
107
108 /** @inheritDoc */
109 public function getRevisionContent(): ?PageContent {
110 return $this->content;
111 }
112
113 }