MediaWiki  1.23.2
WikitextContentHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
7 
11  var $handler;
12 
13  protected function setUp() {
14  parent::setUp();
15 
17  }
18 
22  public function testSerializeContent() {
23  $content = new WikitextContent( 'hello world' );
24 
25  $this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) );
26  $this->assertEquals( 'hello world', $this->handler->serializeContent( $content, CONTENT_FORMAT_WIKITEXT ) );
27 
28  try {
29  $this->handler->serializeContent( $content, 'dummy/foo' );
30  $this->fail( "serializeContent() should have failed on unknown format" );
31  } catch ( MWException $e ) {
32  // ok, as expected
33  }
34  }
35 
39  public function testUnserializeContent() {
40  $content = $this->handler->unserializeContent( 'hello world' );
41  $this->assertEquals( 'hello world', $content->getNativeData() );
42 
43  $content = $this->handler->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT );
44  $this->assertEquals( 'hello world', $content->getNativeData() );
45 
46  try {
47  $this->handler->unserializeContent( 'hello world', 'dummy/foo' );
48  $this->fail( "unserializeContent() should have failed on unknown format" );
49  } catch ( MWException $e ) {
50  // ok, as expected
51  }
52  }
53 
57  public function testMakeEmptyContent() {
58  $content = $this->handler->makeEmptyContent();
59 
60  $this->assertTrue( $content->isEmpty() );
61  $this->assertEquals( '', $content->getNativeData() );
62  }
63 
64  public static function dataIsSupportedFormat() {
65  return array(
66  array( null, true ),
68  array( 99887766, false ),
69  );
70  }
71 
78  public function testMakeRedirectContent( $title, $expected ) {
80  $wgContLang->resetNamespaces();
81 
83 
84  if ( is_string( $title ) ) {
86  }
87  $content = $this->handler->makeRedirectContent( $title );
88  $this->assertEquals( $expected, $content->serialize() );
89  }
90 
91  public static function provideMakeRedirectContent() {
92  return array(
93  array( 'Hello', '#REDIRECT [[Hello]]' ),
94  array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' ),
95  array( 'Hello#section', '#REDIRECT [[Hello#section]]' ),
96  array( 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ),
97  array( 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ),
98  array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ),
99  array( Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ),
100  array( Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ),
101  array( Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 'google' ), '#REDIRECT [[google:Bar#fragment]]' ),
102  );
103  }
104 
109  public function testIsSupportedFormat( $format, $supported ) {
110  $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) );
111  }
112 
113  public static function dataMerge3() {
114  return array(
115  array(
116  "first paragraph
117 
118  second paragraph\n",
119 
120  "FIRST paragraph
121 
122  second paragraph\n",
123 
124  "first paragraph
125 
126  SECOND paragraph\n",
127 
128  "FIRST paragraph
129 
130  SECOND paragraph\n",
131  ),
132 
133  array( "first paragraph
134  second paragraph\n",
135 
136  "Bla bla\n",
137 
138  "Blubberdibla\n",
139 
140  false,
141  ),
142  );
143  }
144 
149  public function testMerge3( $old, $mine, $yours, $expected ) {
150  $this->checkHasDiff3();
151 
152  // test merge
153  $oldContent = new WikitextContent( $old );
154  $myContent = new WikitextContent( $mine );
155  $yourContent = new WikitextContent( $yours );
156 
157  $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent );
158 
159  $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged );
160  }
161 
162  public static function dataGetAutosummary() {
163  return array(
164  array(
165  'Hello there, world!',
166  '#REDIRECT [[Foo]]',
167  0,
168  '/^Redirected page .*Foo/'
169  ),
170 
171  array(
172  null,
173  'Hello world!',
174  EDIT_NEW,
175  '/^Created page .*Hello/'
176  ),
177 
178  array(
179  'Hello there, world!',
180  '',
181  0,
182  '/^Blanked/'
183  ),
184 
185  array(
186  'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
187  labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
188  ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
189  'Hello world!',
190  0,
191  '/^Replaced .*Hello/'
192  ),
193 
194  array(
195  'foo',
196  'bar',
197  0,
198  '/^$/'
199  ),
200  );
201  }
202 
207  public function testGetAutosummary( $old, $new, $flags, $expected ) {
208  $oldContent = is_null( $old ) ? null : new WikitextContent( $old );
209  $newContent = is_null( $new ) ? null : new WikitextContent( $new );
210 
211  $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags );
212 
213  $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
214  }
215 
219  /*
220  public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
221  */
222 
226  /*
227  public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}
228  */
229 }
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:55
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:311
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
WikitextContentHandlerTest\testUnserializeContent
testUnserializeContent()
@covers WikitextContentHandler::unserializeContent
Definition: WikitextContentHandlerTest.php:38
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
WikitextContentHandlerTest\testGetAutosummary
testGetAutosummary( $old, $new, $flags, $expected)
@dataProvider dataGetAutosummary @covers WikitextContentHandler::getAutosummary
Definition: WikitextContentHandlerTest.php:206
WikitextContentHandlerTest\dataIsSupportedFormat
static dataIsSupportedFormat()
Definition: WikitextContentHandlerTest.php:63
WikitextContentHandlerTest\testMakeEmptyContent
testMakeEmptyContent()
@covers WikitextContentHandler::makeEmptyContent
Definition: WikitextContentHandlerTest.php:56
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:283
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2113
WikitextContentHandlerTest\testMakeRedirectContent
testMakeRedirectContent( $title, $expected)
@dataProvider provideMakeRedirectContent
Definition: WikitextContentHandlerTest.php:77
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
WikitextContentHandlerTest\testSerializeContent
testSerializeContent()
@covers WikitextContentHandler::serializeContent
Definition: WikitextContentHandlerTest.php:21
MediaWikiTestCase\checkHasDiff3
checkHasDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped,...
Definition: MediaWikiTestCase.php:959
MWException
MediaWiki exception.
Definition: MWException.php:26
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
CONTENT_FORMAT_WIKITEXT
const CONTENT_FORMAT_WIKITEXT
Definition: Defines.php:297
MagicWord\clearCache
static clearCache()
Clear the self::$mObjects variable For use in parser tests.
Definition: MagicWord.php:300
WikitextContentHandlerTest\dataMerge3
static dataMerge3()
Definition: WikitextContentHandlerTest.php:112
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
WikitextContentHandlerTest\dataGetAutosummary
static dataGetAutosummary()
Definition: WikitextContentHandlerTest.php:161
$summary
$summary
Definition: importImages.php:120
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:189
WikitextContentHandlerTest\setUp
setUp()
Definition: WikitextContentHandlerTest.php:12
WikitextContentHandlerTest\$handler
ContentHandler $handler
Definition: WikitextContentHandlerTest.php:10
$e
if( $useReadline) $e
Definition: eval.php:66
WikitextContentHandlerTest\testMerge3
testMerge3( $old, $mine, $yours, $expected)
@dataProvider dataMerge3 @covers WikitextContentHandler::merge3
Definition: WikitextContentHandlerTest.php:148
WikitextContentHandlerTest\provideMakeRedirectContent
static provideMakeRedirectContent()
Definition: WikitextContentHandlerTest.php:90
WikitextContentHandlerTest\testIsSupportedFormat
testIsSupportedFormat( $format, $supported)
@dataProvider dataIsSupportedFormat @covers WikitextContentHandler::isSupportedFormat
Definition: WikitextContentHandlerTest.php:108
WikitextContentHandlerTest
@group ContentHandler
Definition: WikitextContentHandlerTest.php:6