2012-10-10 10:42:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group ContentHandler
|
|
|
|
|
* @group Database
|
|
|
|
|
* ^--- needed, because we do need the database to test link updates
|
|
|
|
|
*/
|
2012-11-11 07:08:45 +00:00
|
|
|
class TextContentTest extends MediaWikiLangTestCase {
|
2012-10-20 01:51:15 +00:00
|
|
|
protected $context;
|
2012-10-10 10:42:42 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
protected function setUp() {
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
// Anon user
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->setName( '127.0.0.1' );
|
|
|
|
|
|
2012-10-16 10:38:20 +00:00
|
|
|
$this->context = new RequestContext( new FauxRequest() );
|
|
|
|
|
$this->context->setTitle( Title::newFromText( 'Test' ) );
|
|
|
|
|
$this->context->setUser( $user );
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgUser' => $user,
|
|
|
|
|
'wgTextModelsToParse' => array(
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT,
|
2012-11-07 22:08:56 +00:00
|
|
|
),
|
2013-02-12 14:43:43 +00:00
|
|
|
'wgUseTidy' => false,
|
2014-07-07 23:21:09 +00:00
|
|
|
'wgCapitalLinks' => true,
|
2014-10-15 15:09:30 +00:00
|
|
|
'wgHooks' => array(), // bypass hook ContentGetParserOutput that force custom rendering
|
2012-10-20 01:51:15 +00:00
|
|
|
) );
|
2015-08-31 04:42:55 +00:00
|
|
|
|
|
|
|
|
MWTidy::destroySingleton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tearDown() {
|
|
|
|
|
MWTidy::destroySingleton();
|
|
|
|
|
parent::tearDown();
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function newContent( $text ) {
|
|
|
|
|
return new TextContent( $text );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetParserOutput() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
2012-10-18 13:21:34 +00:00
|
|
|
array(
|
2012-10-20 01:51:15 +00:00
|
|
|
'TextContentTest_testGetParserOutput',
|
2012-10-18 13:21:34 +00:00
|
|
|
CONTENT_MODEL_TEXT,
|
|
|
|
|
"hello ''world'' & [[stuff]]\n", "hello ''world'' & [[stuff]]",
|
2012-10-20 01:51:15 +00:00
|
|
|
array(
|
|
|
|
|
'Links' => array()
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
// TODO: more...?
|
2012-10-10 10:42:42 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetParserOutput
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::getParserOutput
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
2014-04-24 16:06:21 +00:00
|
|
|
public function testGetParserOutput( $title, $model, $text, $expectedHtml,
|
|
|
|
|
$expectedFields = null
|
|
|
|
|
) {
|
2012-10-10 10:42:42 +00:00
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$content = ContentHandler::makeContent( $text, $title, $model );
|
|
|
|
|
|
|
|
|
|
$po = $content->getParserOutput( $title );
|
|
|
|
|
|
|
|
|
|
$html = $po->getText();
|
|
|
|
|
$html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedHtml, trim( $html ) );
|
2012-10-18 13:21:34 +00:00
|
|
|
|
|
|
|
|
if ( $expectedFields ) {
|
|
|
|
|
foreach ( $expectedFields as $field => $exp ) {
|
|
|
|
|
$f = 'get' . ucfirst( $field );
|
|
|
|
|
$v = call_user_func( array( $po, $f ) );
|
|
|
|
|
|
|
|
|
|
if ( is_array( $exp ) ) {
|
|
|
|
|
$this->assertArrayEquals( $exp, $v );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals( $exp, $v );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
// TODO: assert more properties
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataPreSaveTransform() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
2012-10-20 01:51:15 +00:00
|
|
|
array(
|
|
|
|
|
#0: no signature resolution
|
|
|
|
|
'hello this is ~~~',
|
|
|
|
|
'hello this is ~~~',
|
2012-10-18 18:14:46 +00:00
|
|
|
),
|
2012-10-20 01:51:15 +00:00
|
|
|
array(
|
|
|
|
|
#1: rtrim
|
2012-10-18 18:14:46 +00:00
|
|
|
" Foo \n ",
|
2012-10-20 01:51:15 +00:00
|
|
|
' Foo',
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataPreSaveTransform
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::preSaveTransform
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testPreSaveTransform( $text, $expected ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
|
|
|
$options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
|
|
|
|
|
|
|
|
|
|
$content = $this->newContent( $text );
|
2014-04-24 16:06:21 +00:00
|
|
|
$content = $content->preSaveTransform(
|
|
|
|
|
$this->context->getTitle(),
|
|
|
|
|
$this->context->getUser(),
|
|
|
|
|
$options
|
|
|
|
|
);
|
2012-10-10 10:42:42 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataPreloadTransform() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
2012-10-20 01:51:15 +00:00
|
|
|
array(
|
|
|
|
|
'hello this is ~~~',
|
|
|
|
|
'hello this is ~~~',
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataPreloadTransform
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::preloadTransform
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testPreloadTransform( $text, $expected ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
$options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
|
|
|
|
|
|
|
|
|
|
$content = $this->newContent( $text );
|
|
|
|
|
$content = $content->preloadTransform( $this->context->getTitle(), $options );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetRedirectTarget() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
|
|
|
|
array( '#REDIRECT [[Test]]',
|
|
|
|
|
null,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetRedirectTarget
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::getRedirectTarget
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetRedirectTarget( $text, $expected ) {
|
|
|
|
|
$content = $this->newContent( $text );
|
2013-02-14 13:10:38 +00:00
|
|
|
$t = $content->getRedirectTarget();
|
2012-10-10 10:42:42 +00:00
|
|
|
|
|
|
|
|
if ( is_null( $expected ) ) {
|
|
|
|
|
$this->assertNull( $t, "text should not have generated a redirect target: $text" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals( $expected, $t->getPrefixedText() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetRedirectTarget
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::isRedirect
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
2012-10-20 01:51:15 +00:00
|
|
|
public function testIsRedirect( $text, $expected ) {
|
2012-10-10 10:42:42 +00:00
|
|
|
$content = $this->newContent( $text );
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
$this->assertEquals( !is_null( $expected ), $content->isRedirect() );
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-15 01:12:35 +00:00
|
|
|
* @todo Test needs database! Should be done by a test class in the Database group.
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
public function getRedirectChain() {
|
|
|
|
|
$text = $this->getNativeData();
|
|
|
|
|
return Title::newFromRedirectArray( $text );
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-15 01:12:35 +00:00
|
|
|
* @todo Test needs database! Should be done by a test class in the Database group.
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
public function getUltimateRedirectTarget() {
|
|
|
|
|
$text = $this->getNativeData();
|
|
|
|
|
return Title::newFromRedirectRecurse( $text );
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataIsCountable() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
|
|
|
|
array( '',
|
2013-02-14 13:10:38 +00:00
|
|
|
null,
|
|
|
|
|
'any',
|
|
|
|
|
true
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
array( 'Foo',
|
2013-02-14 13:10:38 +00:00
|
|
|
null,
|
|
|
|
|
'any',
|
|
|
|
|
true
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
array( 'Foo',
|
2013-02-14 13:10:38 +00:00
|
|
|
null,
|
|
|
|
|
'comma',
|
|
|
|
|
false
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
array( 'Foo, bar',
|
2013-02-14 13:10:38 +00:00
|
|
|
null,
|
|
|
|
|
'comma',
|
|
|
|
|
false
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataIsCountable
|
|
|
|
|
* @group Database
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::isCountable
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsCountable( $text, $hasLinks, $mode, $expected ) {
|
2013-03-21 19:35:44 +00:00
|
|
|
$this->setMwGlobals( 'wgArticleCountMethod', $mode );
|
2012-10-10 10:42:42 +00:00
|
|
|
|
|
|
|
|
$content = $this->newContent( $text );
|
|
|
|
|
|
|
|
|
|
$v = $content->isCountable( $hasLinks, $this->context->getTitle() );
|
|
|
|
|
|
2014-04-24 16:06:21 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected,
|
|
|
|
|
$v,
|
|
|
|
|
'isCountable() returned unexpected value ' . var_export( $v, true )
|
|
|
|
|
. ' instead of ' . var_export( $expected, true )
|
|
|
|
|
. " in mode `$mode` for text \"$text\""
|
|
|
|
|
);
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetTextForSummary() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
|
|
|
|
array( "hello\nworld.",
|
2013-02-14 13:10:38 +00:00
|
|
|
16,
|
|
|
|
|
'hello world.',
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
array( 'hello world.',
|
2013-02-14 13:10:38 +00:00
|
|
|
8,
|
|
|
|
|
'hello...',
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
array( '[[hello world]].',
|
2013-02-14 13:10:38 +00:00
|
|
|
8,
|
|
|
|
|
'[[hel...',
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetTextForSummary
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::getTextForSummary
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetTextForSummary( $text, $maxlength, $expected ) {
|
|
|
|
|
$content = $this->newContent( $text );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $content->getTextForSummary( $maxlength ) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TextContent::getTextForSearchIndex
|
|
|
|
|
*/
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testGetTextForSearchIndex() {
|
2012-10-20 01:51:15 +00:00
|
|
|
$content = $this->newContent( 'hello world.' );
|
2012-10-10 10:42:42 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
$this->assertEquals( 'hello world.', $content->getTextForSearchIndex() );
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TextContent::copy
|
|
|
|
|
*/
|
2012-10-10 10:42:42 +00:00
|
|
|
public function testCopy() {
|
2012-10-20 01:51:15 +00:00
|
|
|
$content = $this->newContent( 'hello world.' );
|
2012-10-10 10:42:42 +00:00
|
|
|
$copy = $content->copy();
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
$this->assertTrue( $content->equals( $copy ), 'copy must be equal to original' );
|
|
|
|
|
$this->assertEquals( 'hello world.', $copy->getNativeData() );
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TextContent::getSize
|
|
|
|
|
*/
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testGetSize() {
|
2012-10-20 01:51:15 +00:00
|
|
|
$content = $this->newContent( 'hello world.' );
|
2012-10-10 10:42:42 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( 12, $content->getSize() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TextContent::getNativeData
|
|
|
|
|
*/
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testGetNativeData() {
|
2012-10-20 01:51:15 +00:00
|
|
|
$content = $this->newContent( 'hello world.' );
|
2012-10-10 10:42:42 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
$this->assertEquals( 'hello world.', $content->getNativeData() );
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TextContent::getWikitextForTransclusion
|
|
|
|
|
*/
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testGetWikitextForTransclusion() {
|
2012-10-20 01:51:15 +00:00
|
|
|
$content = $this->newContent( 'hello world.' );
|
2012-10-10 10:42:42 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
$this->assertEquals( 'hello world.', $content->getWikitextForTransclusion() );
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TextContent::getModel
|
|
|
|
|
*/
|
2012-10-10 10:42:42 +00:00
|
|
|
public function testGetModel() {
|
|
|
|
|
$content = $this->newContent( "hello world." );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( CONTENT_MODEL_TEXT, $content->getModel() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TextContent::getContentHandler
|
|
|
|
|
*/
|
2012-10-10 10:42:42 +00:00
|
|
|
public function testGetContentHandler() {
|
|
|
|
|
$content = $this->newContent( "hello world." );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( CONTENT_MODEL_TEXT, $content->getContentHandler()->getModelID() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public static function dataIsEmpty() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
|
|
|
|
array( '', true ),
|
|
|
|
|
array( ' ', false ),
|
|
|
|
|
array( '0', false ),
|
|
|
|
|
array( 'hallo welt.', false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataIsEmpty
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::isEmpty
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsEmpty( $text, $empty ) {
|
|
|
|
|
$content = $this->newContent( $text );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $empty, $content->isEmpty() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public static function dataEquals() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
|
|
|
|
array( new TextContent( "hallo" ), null, false ),
|
|
|
|
|
array( new TextContent( "hallo" ), new TextContent( "hallo" ), true ),
|
2012-12-06 22:11:16 +00:00
|
|
|
array( new TextContent( "hallo" ), new JavaScriptContent( "hallo" ), false ),
|
2012-10-10 10:42:42 +00:00
|
|
|
array( new TextContent( "hallo" ), new WikitextContent( "hallo" ), false ),
|
|
|
|
|
array( new TextContent( "hallo" ), new TextContent( "HALLO" ), false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataEquals
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::equals
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testEquals( Content $a, Content $b = null, $equal = false ) {
|
|
|
|
|
$this->assertEquals( $equal, $a->equals( $b ) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetDeletionUpdates() {
|
2012-10-10 10:42:42 +00:00
|
|
|
return array(
|
2013-02-14 13:10:38 +00:00
|
|
|
array( "TextContentTest_testGetSecondaryDataUpdates_1",
|
2012-10-10 10:42:42 +00:00
|
|
|
CONTENT_MODEL_TEXT, "hello ''world''\n",
|
2013-02-14 13:10:38 +00:00
|
|
|
array()
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
2013-02-14 13:10:38 +00:00
|
|
|
array( "TextContentTest_testGetSecondaryDataUpdates_2",
|
2012-10-10 10:42:42 +00:00
|
|
|
CONTENT_MODEL_TEXT, "hello [[world test 21344]]\n",
|
2013-02-14 13:10:38 +00:00
|
|
|
array()
|
2012-10-10 10:42:42 +00:00
|
|
|
),
|
2012-10-20 01:51:15 +00:00
|
|
|
// TODO: more...?
|
2012-10-10 10:42:42 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetDeletionUpdates
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::getDeletionUpdates
|
2012-10-10 10:42:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testDeletionUpdates( $title, $model, $text, $expectedStuff ) {
|
2013-01-23 17:14:35 +00:00
|
|
|
$ns = $this->getDefaultWikitextNS();
|
|
|
|
|
$title = Title::newFromText( $title, $ns );
|
2012-10-10 10:42:42 +00:00
|
|
|
|
|
|
|
|
$content = ContentHandler::makeContent( $text, $title, $model );
|
|
|
|
|
|
2013-01-23 17:14:35 +00:00
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$page->doEditContent( $content, '' );
|
|
|
|
|
|
|
|
|
|
$updates = $content->getDeletionUpdates( $page );
|
2012-10-10 10:42:42 +00:00
|
|
|
|
|
|
|
|
// make updates accessible by class name
|
|
|
|
|
foreach ( $updates as $update ) {
|
|
|
|
|
$class = get_class( $update );
|
2013-02-14 13:10:38 +00:00
|
|
|
$updates[$class] = $update;
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$expectedStuff ) {
|
|
|
|
|
$this->assertTrue( true ); // make phpunit happy
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $expectedStuff as $class => $fieldValues ) {
|
|
|
|
|
$this->assertArrayHasKey( $class, $updates, "missing an update of type $class" );
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
$update = $updates[$class];
|
2012-10-10 10:42:42 +00:00
|
|
|
|
|
|
|
|
foreach ( $fieldValues as $field => $value ) {
|
|
|
|
|
$v = $update->$field; #if the field doesn't exist, just crash and burn
|
|
|
|
|
$this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-23 17:14:35 +00:00
|
|
|
|
|
|
|
|
$page->doDeleteArticle( '' );
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-05 15:53:48 +00:00
|
|
|
public static function provideConvert() {
|
|
|
|
|
return array(
|
|
|
|
|
array( // #0
|
|
|
|
|
'Hallo Welt',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'lossless',
|
|
|
|
|
'Hallo Welt'
|
|
|
|
|
),
|
|
|
|
|
array( // #1
|
|
|
|
|
'Hallo Welt',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'lossless',
|
|
|
|
|
'Hallo Welt'
|
|
|
|
|
),
|
|
|
|
|
array( // #1
|
|
|
|
|
'Hallo Welt',
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
'lossless',
|
|
|
|
|
'Hallo Welt'
|
|
|
|
|
),
|
|
|
|
|
array( // #1
|
|
|
|
|
'Hallo Welt',
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT,
|
|
|
|
|
'lossless',
|
|
|
|
|
'Hallo Welt'
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideConvert
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers TextContent::convert
|
2012-11-05 15:53:48 +00:00
|
|
|
*/
|
|
|
|
|
public function testConvert( $text, $model, $lossy, $expectedNative ) {
|
|
|
|
|
$content = $this->newContent( $text );
|
|
|
|
|
|
|
|
|
|
$converted = $content->convert( $model, $lossy );
|
|
|
|
|
|
|
|
|
|
if ( $expectedNative === false ) {
|
|
|
|
|
$this->assertFalse( $converted, "conversion to $model was expected to fail!" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertInstanceOf( 'Content', $converted );
|
|
|
|
|
$this->assertEquals( $expectedNative, $converted->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-10 10:42:42 +00:00
|
|
|
}
|