Changed quoting function for oracleDB.
[mediawiki.git] / tests / phpunit / includes / content / WikitextContentHandlerTest.php
blob45d814068ff06af8544aeaa89613ce6512f75f3f
1 <?php
3 /**
4 * @group ContentHandler
5 */
6 class WikitextContentHandlerTest extends MediaWikiLangTestCase {
8 /**
9 * @var ContentHandler
11 var $handler;
13 public function setUp() {
14 parent::setUp();
16 $this->handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
19 public function testSerializeContent() {
20 $content = new WikitextContent( 'hello world' );
22 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) );
23 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content, CONTENT_FORMAT_WIKITEXT ) );
25 try {
26 $this->handler->serializeContent( $content, 'dummy/foo' );
27 $this->fail( "serializeContent() should have failed on unknown format" );
28 } catch ( MWException $e ) {
29 // ok, as expected
33 public function testUnserializeContent() {
34 $content = $this->handler->unserializeContent( 'hello world' );
35 $this->assertEquals( 'hello world', $content->getNativeData() );
37 $content = $this->handler->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT );
38 $this->assertEquals( 'hello world', $content->getNativeData() );
40 try {
41 $this->handler->unserializeContent( 'hello world', 'dummy/foo' );
42 $this->fail( "unserializeContent() should have failed on unknown format" );
43 } catch ( MWException $e ) {
44 // ok, as expected
48 public function testMakeEmptyContent() {
49 $content = $this->handler->makeEmptyContent();
51 $this->assertTrue( $content->isEmpty() );
52 $this->assertEquals( '', $content->getNativeData() );
55 public static function dataIsSupportedFormat() {
56 return array(
57 array( null, true ),
58 array( CONTENT_FORMAT_WIKITEXT, true ),
59 array( 99887766, false ),
63 /**
64 * @dataProvider dataIsSupportedFormat
66 public function testIsSupportedFormat( $format, $supported ) {
67 $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) );
70 public static function dataMerge3() {
71 return array(
72 array(
73 "first paragraph
75 second paragraph\n",
77 "FIRST paragraph
79 second paragraph\n",
81 "first paragraph
83 SECOND paragraph\n",
85 "FIRST paragraph
87 SECOND paragraph\n",
90 array( "first paragraph
91 second paragraph\n",
93 "Bla bla\n",
95 "Blubberdibla\n",
97 false,
103 * @dataProvider dataMerge3
105 public function testMerge3( $old, $mine, $yours, $expected ) {
106 $this->checkHasDiff3();
108 // test merge
109 $oldContent = new WikitextContent( $old );
110 $myContent = new WikitextContent( $mine );
111 $yourContent = new WikitextContent( $yours );
113 $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent );
115 $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged );
118 public static function dataGetAutosummary() {
119 return array(
120 array(
121 'Hello there, world!',
122 '#REDIRECT [[Foo]]',
124 '/^Redirected page .*Foo/'
127 array(
128 null,
129 'Hello world!',
130 EDIT_NEW,
131 '/^Created page .*Hello/'
134 array(
135 'Hello there, world!',
138 '/^Blanked/'
141 array(
142 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
143 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
144 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
145 'Hello world!',
147 '/^Replaced .*Hello/'
150 array(
151 'foo',
152 'bar',
154 '/^$/'
160 * @dataProvider dataGetAutosummary
162 public function testGetAutosummary( $old, $new, $flags, $expected ) {
163 $oldContent = is_null( $old ) ? null : new WikitextContent( $old );
164 $newContent = is_null( $new ) ? null : new WikitextContent( $new );
166 $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags );
168 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
172 * @todo Text case requires database, should be done by a test class in the Database group
175 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
179 * @todo Text case requires database, should be done by a test class in the Database group
182 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}