16 $user->setName(
'127.0.0.1' );
19 $this->context->setTitle( Title::newFromText(
'Test' ) );
20 $this->context->setUser( $user );
24 'wgTextModelsToParse' => [
30 'wgCapitalLinks' =>
true,
49 'TextContentTest_testGetParserOutput',
51 "hello ''world'' & [[stuff]]\n",
"hello ''world'' & [[stuff]]",
65 $expectedFields =
null
67 $title = Title::newFromText( $title );
68 $content = ContentHandler::makeContent( $text, $title, $model );
70 $po = $content->getParserOutput( $title );
72 $html = $po->getText();
73 $html = preg_replace(
'#<!--.*?-->#sm',
'',
$html );
75 $this->assertEquals( $expectedHtml, trim(
$html ) );
77 if ( $expectedFields ) {
78 foreach ( $expectedFields as $field => $exp ) {
79 $f =
'get' . ucfirst( $field );
80 $v = call_user_func( [ $po, $f ] );
82 if ( is_array( $exp ) ) {
85 $this->assertEquals( $exp, $v );
96 # 0: no signature resolution
106 # 2: newline normalization
107 "LF\n\nCRLF\r\n\r\nCR\r\rEND",
108 "LF\n\nCRLF\n\nCR\n\nEND",
123 $content = $content->preSaveTransform(
124 $this->context->getTitle(),
125 $this->context->getUser(),
129 $this->assertEquals( $expected, $content->getNativeData() );
150 $content = $content->preloadTransform( $this->context->getTitle(),
$options );
152 $this->assertEquals( $expected, $content->getNativeData() );
157 [
'#REDIRECT [[Test]]',
169 $t = $content->getRedirectTarget();
171 if ( is_null( $expected ) ) {
172 $this->assertNull(
$t,
"text should not have generated a redirect target: $text" );
174 $this->assertEquals( $expected,
$t->getPrefixedText() );
185 $this->assertEquals( !is_null( $expected ), $content->isRedirect() );
212 $v = $content->isCountable( $hasLinks, $this->context->getTitle() );
217 'isCountable() returned unexpected value ' . var_export( $v,
true )
218 .
' instead of ' . var_export( $expected,
true )
219 .
" in mode `$mode` for text \"$text\""
233 [
'[[hello world]].',
247 $this->assertEquals( $expected, $content->getTextForSummary( $maxlength ) );
254 $content = $this->
newContent(
'hello world.' );
256 $this->assertEquals(
'hello world.', $content->getTextForSearchIndex() );
263 $content = $this->
newContent(
'hello world.' );
264 $copy = $content->copy();
266 $this->assertTrue( $content->equals( $copy ),
'copy must be equal to original' );
267 $this->assertEquals(
'hello world.', $copy->getNativeData() );
274 $content = $this->
newContent(
'hello world.' );
276 $this->assertEquals( 12, $content->getSize() );
283 $content = $this->
newContent(
'hello world.' );
285 $this->assertEquals(
'hello world.', $content->getNativeData() );
292 $content = $this->
newContent(
'hello world.' );
294 $this->assertEquals(
'hello world.', $content->getWikitextForTransclusion() );
301 $content = $this->
newContent(
"hello world." );
310 $content = $this->
newContent(
"hello world." );
312 $this->assertEquals(
CONTENT_MODEL_TEXT, $content->getContentHandler()->getModelID() );
320 [
'hallo welt.',
false ],
331 $this->assertEquals( $empty, $content->isEmpty() );
349 $this->assertEquals( $equal, $a->equals( $b ) );
354 [
"TextContentTest_testGetSecondaryDataUpdates_1",
358 [
"TextContentTest_testGetSecondaryDataUpdates_2",
372 $title = Title::newFromText( $title, $ns );
374 $content = ContentHandler::makeContent( $text, $title, $model );
376 $page = WikiPage::factory( $title );
377 $page->doEditContent( $content,
'' );
379 $updates = $content->getDeletionUpdates( $page );
382 foreach ( $updates as $update ) {
383 $class = get_class( $update );
384 $updates[$class] = $update;
387 if ( !$expectedStuff ) {
388 $this->assertTrue(
true );
392 foreach ( $expectedStuff as $class => $fieldValues ) {
393 $this->assertArrayHasKey( $class, $updates,
"missing an update of type $class" );
395 $update = $updates[$class];
397 foreach ( $fieldValues as $field =>
$value ) {
398 $v = $update->$field; #
if the field doesn
't exist, just crash and burn
399 $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" );
403 $page->doDeleteArticle( '' );
406 public static function provideConvert() {
410 CONTENT_MODEL_WIKITEXT,
416 CONTENT_MODEL_WIKITEXT,
428 CONTENT_MODEL_JAVASCRIPT,
439 public function testConvert( $text, $model, $lossy, $expectedNative ) {
440 $content = $this->newContent( $text );
442 $converted = $content->convert( $model, $lossy );
444 if ( $expectedNative === false ) {
445 $this->assertFalse( $converted, "conversion to $model was expected to fail!" );
447 $this->assertInstanceOf( Content::class, $converted );
448 $this->assertEquals( $expectedNative, $converted->getNativeData() );
456 public function testNormalizeLineEndings( $input, $expected ) {
457 $this->assertEquals( $expected, TextContent::normalizeLineEndings( $input ) );
460 public static function provideNormalizeLineEndings() {
WebRequest clone which takes values from a provided array.
Content for JavaScript pages.
static destroySingleton()
Destroy the current singleton instance.
Group all the pieces relevant to the context of a request into one instance.
ContentHandler Database ^— needed, because we do need the database to test link updates.
testGetContentHandler()
TextContent::getContentHandler.
testGetTextForSearchIndex()
TextContent::getTextForSearchIndex.
testGetModel()
TextContent::getModel.
testGetNativeData()
TextContent::getNativeData.
testGetSize()
TextContent::getSize.
testGetParserOutput( $title, $model, $text, $expectedHtml, $expectedFields=null)
dataGetParserOutput TextContent::getParserOutput
testPreloadTransform( $text, $expected)
dataPreloadTransform TextContent::preloadTransform
testCopy()
TextContent::copy.
static dataGetParserOutput()
testEquals(Content $a, Content $b=null, $equal=false)
dataEquals TextContent::equals
testGetWikitextForTransclusion()
TextContent::getWikitextForTransclusion.
testIsEmpty( $text, $empty)
dataIsEmpty TextContent::isEmpty
static dataGetRedirectTarget()
testIsRedirect( $text, $expected)
dataGetRedirectTarget TextContent::isRedirect
testGetRedirectTarget( $text, $expected)
dataGetRedirectTarget TextContent::getRedirectTarget
testDeletionUpdates( $title, $model, $text, $expectedStuff)
dataGetDeletionUpdates TextContent::getDeletionUpdates
static dataGetDeletionUpdates()
testIsCountable( $text, $hasLinks, $mode, $expected)
dataIsCountable TextContent::isCountable
testGetTextForSummary( $text, $maxlength, $expected)
dataGetTextForSummary TextContent::getTextForSummary
static dataPreSaveTransform()
static dataPreloadTransform()
testPreSaveTransform( $text, $expected)
dataPreSaveTransform TextContent::preSaveTransform
static dataGetTextForSummary()
Content object implementation for representing flat text.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Content object for wiki text pages.
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 local content language as $wgContLang
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
processing should stop and the error should be shown to the user * false
const CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_JAVASCRIPT
Base interface for content objects.