+++ /dev/null
-<?php
-/**
- * Test class for ArrayUtils class
- *
- * @group Database
- */
-
-class ArrayUtilsTest extends MediaWikiTestCase {
- private $search;
-
- /**
- * @covers ArrayUtils::findLowerBound
- * @dataProvider provideFindLowerBound
- */
- function testFindLowerBound(
- $valueCallback, $valueCount, $comparisonCallback, $target, $expected
- ) {
- $this->assertSame(
- ArrayUtils::findLowerBound(
- $valueCallback, $valueCount, $comparisonCallback, $target
- ), $expected
- );
- }
-
- function provideFindLowerBound() {
- $self = $this;
- $indexValueCallback = function ( $size ) use ( $self ) {
- return function ( $val ) use ( $self, $size ) {
- $self->assertTrue( $val >= 0 );
- $self->assertTrue( $val < $size );
- return $val;
- };
- };
- $comparisonCallback = function ( $a, $b ) {
- return $a - $b;
- };
-
- return array(
- array(
- $indexValueCallback( 0 ),
- 0,
- $comparisonCallback,
- 1,
- false,
- ),
- array(
- $indexValueCallback( 1 ),
- 1,
- $comparisonCallback,
- -1,
- false,
- ),
- array(
- $indexValueCallback( 1 ),
- 1,
- $comparisonCallback,
- 0,
- 0,
- ),
- array(
- $indexValueCallback( 1 ),
- 1,
- $comparisonCallback,
- 1,
- 0,
- ),
- array(
- $indexValueCallback( 2 ),
- 2,
- $comparisonCallback,
- -1,
- false,
- ),
- array(
- $indexValueCallback( 2 ),
- 2,
- $comparisonCallback,
- 0,
- 0,
- ),
- array(
- $indexValueCallback( 2 ),
- 2,
- $comparisonCallback,
- 0.5,
- 0,
- ),
- array(
- $indexValueCallback( 2 ),
- 2,
- $comparisonCallback,
- 1,
- 1,
- ),
- array(
- $indexValueCallback( 2 ),
- 2,
- $comparisonCallback,
- 1.5,
- 1,
- ),
- array(
- $indexValueCallback( 3 ),
- 3,
- $comparisonCallback,
- 1,
- 1,
- ),
- array(
- $indexValueCallback( 3 ),
- 3,
- $comparisonCallback,
- 1.5,
- 1,
- ),
- array(
- $indexValueCallback( 3 ),
- 3,
- $comparisonCallback,
- 2,
- 2,
- ),
- array(
- $indexValueCallback( 3 ),
- 3,
- $comparisonCallback,
- 3,
- 2,
- ),
- );
- }
-
- /**
- * @covers ArrayUtils::arrayDiffAssocRecursive
- * @dataProvider provideArrayDiffAssocRecursive
- */
- function testArrayDiffAssocRecursive( $expected ) {
- $args = func_get_args();
- array_shift( $args );
- $this->assertEquals( call_user_func_array(
- 'ArrayUtils::arrayDiffAssocRecursive', $args
- ), $expected );
- }
-
- function provideArrayDiffAssocRecursive() {
- return array(
- array(
- array(),
- array(),
- array(),
- ),
- array(
- array(),
- array(),
- array(),
- array(),
- ),
- array(
- array( 1 ),
- array( 1 ),
- array(),
- ),
- array(
- array( 1 ),
- array( 1 ),
- array(),
- array(),
- ),
- array(
- array(),
- array(),
- array( 1 ),
- ),
- array(
- array(),
- array(),
- array( 1 ),
- array( 2 ),
- ),
- array(
- array( '' => 1 ),
- array( '' => 1 ),
- array(),
- ),
- array(
- array(),
- array(),
- array( '' => 1 ),
- ),
- array(
- array( 1 ),
- array( 1 ),
- array( 2 ),
- ),
- array(
- array(),
- array( 1 ),
- array( 2 ),
- array( 1 ),
- ),
- array(
- array(),
- array( 1 ),
- array( 1, 2 ),
- ),
- array(
- array( 1 => 1 ),
- array( 1 => 1 ),
- array( 1 ),
- ),
- array(
- array(),
- array( 1 => 1 ),
- array( 1 ),
- array( 1 => 1),
- ),
- array(
- array(),
- array( 1 => 1 ),
- array( 1, 1, 1 ),
- ),
- array(
- array(),
- array( array() ),
- array(),
- ),
- array(
- array(),
- array( array( array() ) ),
- array(),
- ),
- array(
- array( 1, array( 1 ) ),
- array( 1, array( 1 ) ),
- array(),
- ),
- array(
- array( 1 ),
- array( 1, array( 1 ) ),
- array( 2, array( 1 ) ),
- ),
- array(
- array(),
- array( 1, array( 1 ) ),
- array( 2, array( 1 ) ),
- array( 1, array( 2 ) ),
- ),
- array(
- array( 1 ),
- array( 1, array() ),
- array( 2 ),
- ),
- array(
- array(),
- array( 1, array() ),
- array( 2 ),
- array( 1 ),
- ),
- array(
- array( 1, array( 1 => 2 ) ),
- array( 1, array( 1, 2 ) ),
- array( 2, array( 1 ) ),
- ),
- array(
- array( 1 ),
- array( 1, array( 1, 2 ) ),
- array( 2, array( 1 ) ),
- array( 2, array( 1 => 2 ) ),
- ),
- array(
- array( 1 => array( 1, 2 ) ),
- array( 1, array( 1, 2 ) ),
- array( 1, array( 2 ) ),
- ),
- array(
- array( 1 => array( array( 2, 3 ), 2 ) ),
- array( 1, array( array( 2, 3 ), 2 ) ),
- array( 1, array( 2 ) ),
- ),
- array(
- array( 1 => array( array( 2 ), 2 ) ),
- array( 1, array( array( 2, 3 ), 2 ) ),
- array( 1, array( array( 1 => 3 ) ) ),
- ),
- array(
- array( 1 => array( 1 => 2 ) ),
- array( 1, array( array( 2, 3 ), 2 ) ),
- array( 1, array( array( 1 => 3, 0 => 2 ) ) ),
- ),
- array(
- array( 1 => array( 1 => 2 ) ),
- array( 1, array( array( 2, 3 ), 2 ) ),
- array( 1, array( array( 1 => 3 ) ) ),
- array( 1 => array( array( 2 ) ) ),
- ),
- array(
- array(),
- array( 1, array( array( 2, 3 ), 2 ) ),
- array( 1 => array( 1 => 2, 0 => array( 1 => 3, 0 => 2 ) ), 0 => 1 ),
- ),
- array(
- array(),
- array( 1, array( array( 2, 3 ), 2 ) ),
- array( 1 => array( 1 => 2 ) ),
- array( 1 => array( array( 1 => 3 ) ) ),
- array( 1 => array( array( 2 ) ) ),
- array( 1 ),
- ),
- );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @group Database
- */
-class ArticleTablesTest extends MediaWikiLangTestCase {
- /**
- * Make sure that bug 14404 doesn't strike again. We don't want
- * templatelinks based on the user language when {{int:}} is used, only the
- * content language.
- *
- * @covers Title::getTemplateLinksFrom
- * @covers Title::getLinksFrom
- */
- public function testTemplatelinksUsesContentLanguage() {
- $title = Title::newFromText( 'Bug 14404' );
- $page = WikiPage::factory( $title );
- $user = new User();
- $user->mRights = array( 'createpage', 'edit', 'purge' );
- $this->setMwGlobals( 'wgLanguageCode', 'es' );
- $this->setMwGlobals( 'wgContLang', Language::factory( 'es' ) );
- $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) );
-
- $page->doEditContent(
- new WikitextContent( '{{:{{int:history}}}}' ),
- 'Test code for bug 14404',
- 0,
- false,
- $user
- );
- $templates1 = $title->getTemplateLinksFrom();
-
- $this->setMwGlobals( 'wgLang', Language::factory( 'de' ) );
- $page = WikiPage::factory( $title ); // In order to force the re-rendering of the same wikitext
-
- // We need an edit, a purge is not enough to regenerate the tables
- $page->doEditContent(
- new WikitextContent( '{{:{{int:history}}}}' ),
- 'Test code for bug 14404',
- EDIT_UPDATE,
- false,
- $user
- );
- $templates2 = $title->getTemplateLinksFrom();
-
- /**
- * @var Title[] $templates1
- * @var Title[] $templates2
- */
- $this->assertEquals( $templates1, $templates2 );
- $this->assertEquals( $templates1[0]->getFullText(), 'Historial' );
- }
-}
+++ /dev/null
-<?php
-
-class ArticleTest extends MediaWikiTestCase {
-
- /**
- * @var Title
- */
- private $title;
- /**
- * @var Article
- */
- private $article;
-
- /** creates a title object and its article object */
- protected function setUp() {
- parent::setUp();
- $this->title = Title::makeTitle( NS_MAIN, 'SomePage' );
- $this->article = new Article( $this->title );
- }
-
- /** cleanup title object and its article object */
- protected function tearDown() {
- parent::tearDown();
- $this->title = null;
- $this->article = null;
- }
-
- /**
- * @covers Article::__get
- */
- public function testImplementsGetMagic() {
- $this->assertEquals( false, $this->article->mLatest, "Article __get magic" );
- }
-
- /**
- * @depends testImplementsGetMagic
- * @covers Article::__set
- */
- public function testImplementsSetMagic() {
- $this->article->mLatest = 2;
- $this->assertEquals( 2, $this->article->mLatest, "Article __set magic" );
- }
-
- /**
- * @depends testImplementsSetMagic
- * @covers Article::__call
- */
- public function testImplementsCallMagic() {
- $this->article->mLatest = 33;
- $this->article->mDataLoaded = true;
- $this->assertEquals( 33, $this->article->getLatest(), "Article __call magic" );
- }
-
- /**
- * @covers Article::__get
- * @covers Article::__set
- */
- public function testGetOrSetOnNewProperty() {
- $this->article->ext_someNewProperty = 12;
- $this->assertEquals( 12, $this->article->ext_someNewProperty,
- "Article get/set magic on new field" );
-
- $this->article->ext_someNewProperty = -8;
- $this->assertEquals( -8, $this->article->ext_someNewProperty,
- "Article get/set magic on update to new field" );
- }
-
- /**
- * Checks for the existence of the backwards compatibility static functions
- * (forwarders to WikiPage class)
- *
- * @covers Article::selectFields
- * @covers Article::onArticleCreate
- * @covers Article::onArticleDelete
- * @covers Article::onArticleEdit
- * @covers Article::getAutosummary
- */
- public function testStaticFunctions() {
- $this->hideDeprecated( 'Article::selectFields' );
- $this->hideDeprecated( 'Article::getAutosummary' );
- $this->hideDeprecated( 'WikiPage::getAutosummary' );
- $this->hideDeprecated( 'CategoryPage::getAutosummary' ); // Inherited from Article
-
- $this->assertEquals( WikiPage::selectFields(), Article::selectFields(),
- "Article static functions" );
- $this->assertEquals( true, is_callable( "Article::onArticleCreate" ),
- "Article static functions" );
- $this->assertEquals( true, is_callable( "Article::onArticleDelete" ),
- "Article static functions" );
- $this->assertEquals( true, is_callable( "ImagePage::onArticleEdit" ),
- "Article static functions" );
- $this->assertTrue( is_string( CategoryPage::getAutosummary( '', '', 0 ) ),
- "Article static functions" );
- }
-}
+++ /dev/null
-<?php
-/**
- * External Store tests
- */
-
-class ExternalStoreTest extends MediaWikiTestCase {
-
- /**
- * @covers ExternalStore::fetchFromURL
- */
- public function testExternalFetchFromURL() {
- $this->setMwGlobals( 'wgExternalStores', false );
-
- $this->assertFalse(
- ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
- 'Deny if wgExternalStores is not set to a non-empty array'
- );
-
- $this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) );
-
- $this->assertEquals(
- ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
- 'Hello',
- 'Allow FOO://cluster1/200'
- );
- $this->assertEquals(
- ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
- 'Hello',
- 'Allow FOO://cluster1/300/0'
- );
- # Assertions for r68900
- $this->assertFalse(
- ExternalStore::fetchFromURL( 'ftp.example.org' ),
- 'Deny domain ftp.example.org'
- );
- $this->assertFalse(
- ExternalStore::fetchFromURL( '/example.txt' ),
- 'Deny path /example.txt'
- );
- $this->assertFalse(
- ExternalStore::fetchFromURL( 'http://' ),
- 'Deny protocol http://'
- );
- }
-}
-
-class ExternalStoreFOO {
-
- protected $data = array(
- 'cluster1' => array(
- '200' => 'Hello',
- '300' => array(
- 'Hello', 'World',
- ),
- ),
- );
-
- /**
- * Fetch data from given URL
- * @param string $url An url of the form FOO://cluster/id or FOO://cluster/id/itemid.
- * @return mixed
- */
- function fetchFromURL( $url ) {
- // Based on ExternalStoreDB
- $path = explode( '/', $url );
- $cluster = $path[2];
- $id = $path[3];
- if ( isset( $path[4] ) ) {
- $itemID = $path[4];
- } else {
- $itemID = false;
- }
-
- if ( !isset( $this->data[$cluster][$id] ) ) {
- return null;
- }
-
- if ( $itemID !== false
- && is_array( $this->data[$cluster][$id] )
- && isset( $this->data[$cluster][$id][$itemID] )
- ) {
- return $this->data[$cluster][$id][$itemID];
- }
-
- return $this->data[$cluster][$id];
- }
-}
+++ /dev/null
-<?php
-/**
- * For doing Image Page tests that rely on 404 thumb handling
- */
-class ImagePage404Test extends MediaWikiMediaTestCase {
-
- protected function getRepoOptions() {
- return parent::getRepoOptions() + array( 'transformVia404' => true );
- }
-
- function setUp() {
- $this->setMwGlobals( 'wgImageLimits', array(
- array( 320, 240 ),
- array( 640, 480 ),
- array( 800, 600 ),
- array( 1024, 768 ),
- array( 1280, 1024 )
- ) );
- parent::setUp();
- }
-
- function getImagePage( $filename ) {
- $title = Title::makeTitleSafe( NS_FILE, $filename );
- $file = $this->dataFile( $filename );
- $iPage = new ImagePage( $title );
- $iPage->setFile( $file );
- return $iPage;
- }
-
- /**
- * @dataProvider providerGetThumbSizes
- * @param string $filename
- * @param int $expectedNumberThumbs How many thumbnails to show
- */
- function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
- $iPage = $this->getImagePage( $filename );
- $reflection = new ReflectionClass( $iPage );
- $reflMethod = $reflection->getMethod( 'getThumbSizes' );
- $reflMethod->setAccessible( true );
-
- $actual = $reflMethod->invoke( $iPage, 545, 700 );
- $this->assertEquals( count( $actual ), $expectedNumberThumbs );
- }
-
- function providerGetThumbSizes() {
- return array(
- array( 'animated.gif', 6 ),
- array( 'Toll_Texas_1.svg', 6 ),
- array( '80x60-Greyscale.xcf', 6 ),
- array( 'jpeg-comment-binary.jpg', 6 ),
- );
- }
-}
+++ /dev/null
-<?php
-class ImagePageTest extends MediaWikiMediaTestCase {
-
- function setUp() {
- $this->setMwGlobals( 'wgImageLimits', array(
- array( 320, 240 ),
- array( 640, 480 ),
- array( 800, 600 ),
- array( 1024, 768 ),
- array( 1280, 1024 )
- ) );
- parent::setUp();
- }
-
- function getImagePage( $filename ) {
- $title = Title::makeTitleSafe( NS_FILE, $filename );
- $file = $this->dataFile( $filename );
- $iPage = new ImagePage( $title );
- $iPage->setFile( $file );
- return $iPage;
- }
-
- /**
- * @dataProvider providerGetDisplayWidthHeight
- * @param array $dim Array [maxWidth, maxHeight, width, height]
- * @param array $expected Array [width, height] The width and height we expect to display at
- */
- function testGetDisplayWidthHeight( $dim, $expected ) {
- $iPage = $this->getImagePage( 'animated.gif' );
- $reflection = new ReflectionClass( $iPage );
- $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
- $reflMethod->setAccessible( true );
-
- $actual = $reflMethod->invoke( $iPage, $dim[0], $dim[1], $dim[2], $dim[3] );
- $this->assertEquals( $actual, $expected );
- }
-
- function providerGetDisplayWidthHeight() {
- return array(
- array(
- array( 1024.0, 768.0, 600.0, 600.0 ),
- array( 600.0, 600.0 )
- ),
- array(
- array( 1024.0, 768.0, 1600.0, 600.0 ),
- array( 1024.0, 384.0 )
- ),
- array(
- array( 1024.0, 768.0, 1024.0, 768.0 ),
- array( 1024.0, 768.0 )
- ),
- array(
- array( 1024.0, 768.0, 800.0, 1000.0 ),
- array( 614.0, 768.0 )
- ),
- array(
- array( 1024.0, 768.0, 0, 1000 ),
- array( 0, 0 )
- ),
- array(
- array( 1024.0, 768.0, 2000, 0 ),
- array( 0, 0 )
- ),
- );
- }
-
- /**
- * @dataProvider providerGetThumbSizes
- * @param string $filename
- * @param int $expectedNumberThumbs How many thumbnails to show
- */
- function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
- $iPage = $this->getImagePage( $filename );
- $reflection = new ReflectionClass( $iPage );
- $reflMethod = $reflection->getMethod( 'getThumbSizes' );
- $reflMethod->setAccessible( true );
-
- $actual = $reflMethod->invoke( $iPage, 545, 700 );
- $this->assertEquals( count( $actual ), $expectedNumberThumbs );
- }
-
- function providerGetThumbSizes() {
- return array(
- array( 'animated.gif', 2 ),
- array( 'Toll_Texas_1.svg', 1 ),
- array( '80x60-Greyscale.xcf', 1 ),
- array( 'jpeg-comment-binary.jpg', 2 ),
- );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @group Database
- * ^--- make sure temporary tables are used.
- */
-class LinksUpdateTest extends MediaWikiTestCase {
-
- function __construct( $name = null, array $data = array(), $dataName = '' ) {
- parent::__construct( $name, $data, $dataName );
-
- $this->tablesUsed = array_merge( $this->tablesUsed,
- array(
- 'interwiki',
- 'page_props',
- 'pagelinks',
- 'categorylinks',
- 'langlinks',
- 'externallinks',
- 'imagelinks',
- 'templatelinks',
- 'iwlinks'
- )
- );
- }
-
- protected function setUp() {
- parent::setUp();
- $dbw = wfGetDB( DB_MASTER );
- $dbw->replace(
- 'interwiki',
- array( 'iw_prefix' ),
- array(
- 'iw_prefix' => 'linksupdatetest',
- 'iw_url' => 'http://testing.com/wiki/$1',
- 'iw_api' => 'http://testing.com/w/api.php',
- 'iw_local' => 0,
- 'iw_trans' => 0,
- 'iw_wikiid' => 'linksupdatetest',
- )
- );
- }
-
- protected function makeTitleAndParserOutput( $name, $id ) {
- $t = Title::newFromText( $name );
- $t->mArticleID = $id; # XXX: this is fugly
-
- $po = new ParserOutput();
- $po->setTitleText( $t->getPrefixedText() );
-
- return array( $t, $po );
- }
-
- /**
- * @covers ParserOutput::addLink
- */
- public function testUpdate_pagelinks() {
- /** @var ParserOutput $po */
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $po->addLink( Title::newFromText( "Foo" ) );
- $po->addLink( Title::newFromText( "Special:Foo" ) ); // special namespace should be ignored
- $po->addLink( Title::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored
- $po->addLink( Title::newFromText( "#Foo" ) ); // hash link should be ignored
-
- $update = $this->assertLinksUpdate(
- $t,
- $po,
- 'pagelinks',
- 'pl_namespace,
- pl_title',
- 'pl_from = 111',
- array( array( NS_MAIN, 'Foo' ) )
- );
- $this->assertArrayEquals( array(
- Title::makeTitle( NS_MAIN, 'Foo' ), // newFromText doesn't yield the same internal state....
- ), $update->getAddedLinks() );
-
- $po = new ParserOutput();
- $po->setTitleText( $t->getPrefixedText() );
-
- $po->addLink( Title::newFromText( "Bar" ) );
- $po->addLink( Title::newFromText( "Talk:Bar" ) );
-
- $update = $this->assertLinksUpdate(
- $t,
- $po,
- 'pagelinks',
- 'pl_namespace,
- pl_title',
- 'pl_from = 111',
- array(
- array( NS_MAIN, 'Bar' ),
- array( NS_TALK, 'Bar' ),
- )
- );
- $this->assertArrayEquals( array(
- Title::makeTitle( NS_MAIN, 'Bar' ),
- Title::makeTitle( NS_TALK, 'Bar' ),
- ), $update->getAddedLinks() );
- $this->assertArrayEquals( array(
- Title::makeTitle( NS_MAIN, 'Foo' ),
- ), $update->getRemovedLinks() );
- }
-
- /**
- * @covers ParserOutput::addExternalLink
- */
- public function testUpdate_externallinks() {
- /** @var ParserOutput $po */
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $po->addExternalLink( "http://testing.com/wiki/Foo" );
-
- $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
- array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
- ) );
- }
-
- /**
- * @covers ParserOutput::addCategory
- */
- public function testUpdate_categorylinks() {
- /** @var ParserOutput $po */
- $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
-
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $po->addCategory( "Foo", "FOO" );
-
- $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
- array( 'Foo', "FOO\nTESTING" ),
- ) );
- }
-
- /**
- * @covers ParserOutput::addInterwikiLink
- */
- public function testUpdate_iwlinks() {
- /** @var ParserOutput $po */
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' );
- $po->addInterwikiLink( $target );
-
- $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
- array( 'linksupdatetest', 'Foo' ),
- ) );
- }
-
- /**
- * @covers ParserOutput::addTemplate
- */
- public function testUpdate_templatelinks() {
- /** @var ParserOutput $po */
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 );
-
- $this->assertLinksUpdate(
- $t,
- $po,
- 'templatelinks',
- 'tl_namespace,
- tl_title',
- 'tl_from = 111',
- array( array( NS_TEMPLATE, 'Foo' ) )
- );
- }
-
- /**
- * @covers ParserOutput::addImage
- */
- public function testUpdate_imagelinks() {
- /** @var ParserOutput $po */
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $po->addImage( "Foo.png" );
-
- $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
- array( 'Foo.png' ),
- ) );
- }
-
- /**
- * @covers ParserOutput::addLanguageLink
- */
- public function testUpdate_langlinks() {
- $this->setMwGlobals( array(
- 'wgCapitalLinks' => true,
- ) );
-
- /** @var ParserOutput $po */
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() );
-
- $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
- array( 'En', 'Foo' ),
- ) );
- }
-
- /**
- * @covers ParserOutput::setProperty
- */
- public function testUpdate_page_props() {
- global $wgPagePropsHaveSortkey;
-
- /** @var ParserOutput $po */
- list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
-
- $fields = array( 'pp_propname', 'pp_value' );
- $expected = array();
-
- $po->setProperty( "bool", true );
- $expected[] = array( "bool", true );
-
- $po->setProperty( "float", 4.0 + 1.0 / 4.0 );
- $expected[] = array( "float", 4.0 + 1.0 / 4.0 );
-
- $po->setProperty( "int", -7 );
- $expected[] = array( "int", -7 );
-
- $po->setProperty( "string", "33 bar" );
- $expected[] = array( "string", "33 bar" );
-
- // compute expected sortkey values
- if ( $wgPagePropsHaveSortkey ) {
- $fields[] = 'pp_sortkey';
-
- foreach ( $expected as &$row ) {
- $value = $row[1];
-
- if ( is_int( $value ) || is_float( $value ) || is_bool( $value ) ) {
- $row[] = floatval( $value );
- } else {
- $row[] = null;
- }
- }
- }
-
- $this->assertLinksUpdate( $t, $po, 'page_props', $fields, 'pp_page = 111', $expected );
- }
-
- public function testUpdate_page_props_without_sortkey() {
- $this->setMwGlobals( 'wgPagePropsHaveSortkey', false );
-
- $this->testUpdate_page_props();
- }
-
- // @todo test recursive, too!
-
- protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput,
- $table, $fields, $condition, array $expectedRows
- ) {
- $update = new LinksUpdate( $title, $parserOutput );
-
- //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
- $update->beginTransaction();
- $update->doUpdate();
- $update->commitTransaction();
-
- $this->assertSelect( $table, $fields, $condition, $expectedRows );
- return $update;
- }
-}
+++ /dev/null
-<?php
-
-/**
- * These tests should work regardless of $wgCapitalLinks
- * @group Database
- * @todo Split tests into providers and test methods
- */
-
-class LocalFileTest extends MediaWikiTestCase {
-
- protected function setUp() {
- parent::setUp();
-
- $this->setMwGlobals( 'wgCapitalLinks', true );
-
- $info = array(
- 'name' => 'test',
- 'directory' => '/testdir',
- 'url' => '/testurl',
- 'hashLevels' => 2,
- 'transformVia404' => false,
- 'backend' => new FSFileBackend( array(
- 'name' => 'local-backend',
- 'wikiId' => wfWikiId(),
- 'containerPaths' => array(
- 'cont1' => "/testdir/local-backend/tempimages/cont1",
- 'cont2' => "/testdir/local-backend/tempimages/cont2"
- )
- ) )
- );
- $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
- $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
- $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
- $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
- $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
- $this->file_lc = $this->repo_lc->newFile( 'test!' );
- }
-
- /**
- * @covers File::getHashPath
- */
- public function testGetHashPath() {
- $this->assertEquals( '', $this->file_hl0->getHashPath() );
- $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
- $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
- }
-
- /**
- * @covers File::getRel
- */
- public function testGetRel() {
- $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
- $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
- $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
- }
-
- /**
- * @covers File::getUrlRel
- */
- public function testGetUrlRel() {
- $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
- $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
- $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
- }
-
- /**
- * @covers File::getArchivePath
- */
- public function testGetArchivePath() {
- $this->assertEquals(
- 'mwstore://local-backend/test-public/archive',
- $this->file_hl0->getArchivePath()
- );
- $this->assertEquals(
- 'mwstore://local-backend/test-public/archive/a/a2',
- $this->file_hl2->getArchivePath()
- );
- $this->assertEquals(
- 'mwstore://local-backend/test-public/archive/!',
- $this->file_hl0->getArchivePath( '!' )
- );
- $this->assertEquals(
- 'mwstore://local-backend/test-public/archive/a/a2/!',
- $this->file_hl2->getArchivePath( '!' )
- );
- }
-
- /**
- * @covers File::getThumbPath
- */
- public function testGetThumbPath() {
- $this->assertEquals(
- 'mwstore://local-backend/test-thumb/Test!',
- $this->file_hl0->getThumbPath()
- );
- $this->assertEquals(
- 'mwstore://local-backend/test-thumb/a/a2/Test!',
- $this->file_hl2->getThumbPath()
- );
- $this->assertEquals(
- 'mwstore://local-backend/test-thumb/Test!/x',
- $this->file_hl0->getThumbPath( 'x' )
- );
- $this->assertEquals(
- 'mwstore://local-backend/test-thumb/a/a2/Test!/x',
- $this->file_hl2->getThumbPath( 'x' )
- );
- }
-
- /**
- * @covers File::getArchiveUrl
- */
- public function testGetArchiveUrl() {
- $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
- $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
- $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
- $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
- }
-
- /**
- * @covers File::getThumbUrl
- */
- public function testGetThumbUrl() {
- $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
- $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
- $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
- $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
- }
-
- /**
- * @covers File::getArchiveVirtualUrl
- */
- public function testGetArchiveVirtualUrl() {
- $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
- $this->assertEquals(
- 'mwrepo://test/public/archive/a/a2',
- $this->file_hl2->getArchiveVirtualUrl()
- );
- $this->assertEquals(
- 'mwrepo://test/public/archive/%21',
- $this->file_hl0->getArchiveVirtualUrl( '!' )
- );
- $this->assertEquals(
- 'mwrepo://test/public/archive/a/a2/%21',
- $this->file_hl2->getArchiveVirtualUrl( '!' )
- );
- }
-
- /**
- * @covers File::getThumbVirtualUrl
- */
- public function testGetThumbVirtualUrl() {
- $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
- $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
- $this->assertEquals(
- 'mwrepo://test/thumb/Test%21/%21',
- $this->file_hl0->getThumbVirtualUrl( '!' )
- );
- $this->assertEquals(
- 'mwrepo://test/thumb/a/a2/Test%21/%21',
- $this->file_hl2->getThumbVirtualUrl( '!' )
- );
- }
-
- /**
- * @covers File::getUrl
- */
- public function testGetUrl() {
- $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
- $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
- }
-
- /**
- * @covers ::wfLocalFile
- */
- public function testWfLocalFile() {
- $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
- $this->assertThat(
- $file,
- $this->isInstanceOf( 'LocalFile' ),
- 'wfLocalFile() returns LocalFile for valid Titles'
- );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @covers MWFunction
- */
-class MWFunctionTest extends MediaWikiTestCase {
- public function testNewObjFunction() {
- $arg1 = 'Foo';
- $arg2 = 'Bar';
- $arg3 = array( 'Baz' );
- $arg4 = new ExampleObject;
-
- $args = array( $arg1, $arg2, $arg3, $arg4 );
-
- $newObject = new MWBlankClass( $arg1, $arg2, $arg3, $arg4 );
- $this->hideDeprecated( 'MWFunction::newObj' );
- $this->assertEquals(
- MWFunction::newObj( 'MWBlankClass', $args )->args,
- $newObject->args
- );
- }
-}
-
-class MWBlankClass {
-
- public $args = array();
-
- function __construct( $arg1, $arg2, $arg3, $arg4 ) {
- $this->args = array( $arg1, $arg2, $arg3, $arg4 );
- }
-}
-
-class ExampleObject {
-}
+++ /dev/null
-<?php
-/**
- * Testing framework for the Password infrastructure
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-class PasswordTest extends MediaWikiTestCase {
- /**
- * @covers InvalidPassword::equals
- */
- public function testInvalidUnequalInvalid() {
- $invalid1 = User::getPasswordFactory()->newFromCiphertext( null );
- $invalid2 = User::getPasswordFactory()->newFromCiphertext( null );
-
- $this->assertFalse( $invalid1->equals( $invalid2 ) );
- }
-
- public function testInvalidPlaintext() {
- $invalid = User::getPasswordFactory()->newFromPlaintext( null );
-
- $this->assertInstanceOf( 'InvalidPassword', $invalid );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @group Database
- * @group RequestContext
- */
-class RequestContextTest extends MediaWikiTestCase {
-
- /**
- * Test the relationship between title and wikipage in RequestContext
- * @covers RequestContext::getWikiPage
- * @covers RequestContext::getTitle
- */
- public function testWikiPageTitle() {
- $context = new RequestContext();
-
- $curTitle = Title::newFromText( "A" );
- $context->setTitle( $curTitle );
- $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ),
- "When a title is first set WikiPage should be created on-demand for that title." );
-
- $curTitle = Title::newFromText( "B" );
- $context->setWikiPage( WikiPage::factory( $curTitle ) );
- $this->assertTrue( $curTitle->equals( $context->getTitle() ),
- "Title must be updated when a new WikiPage is provided." );
-
- $curTitle = Title::newFromText( "C" );
- $context->setTitle( $curTitle );
- $this->assertTrue(
- $curTitle->equals( $context->getWikiPage()->getTitle() ),
- "When a title is updated the WikiPage should be purged "
- . "and recreated on-demand with the new title."
- );
- }
-
- /**
- * @covers RequestContext::importScopedSession
- */
- public function testImportScopedSession() {
- $context = RequestContext::getMain();
-
- $oInfo = $context->exportSession();
- $this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." );
- $this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." );
-
- $user = User::newFromName( 'UnitTestContextUser' );
- $user->addToDatabase();
-
- $sinfo = array(
- 'sessionId' => 'd612ee607c87e749ef14da4983a702cd',
- 'userId' => $user->getId(),
- 'ip' => '192.0.2.0',
- 'headers' => array(
- 'USER-AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0'
- )
- );
- // importScopedSession() sets these variables
- $this->setMwGlobals( array(
- 'wgUser' => new User,
- 'wgRequest' => new FauxRequest,
- ) );
- $sc = RequestContext::importScopedSession( $sinfo ); // load new context
-
- $info = $context->exportSession();
- $this->assertEquals( $sinfo['ip'], $info['ip'], "Correct IP address." );
- $this->assertEquals( $sinfo['headers'], $info['headers'], "Correct headers." );
- $this->assertEquals( $sinfo['sessionId'], $info['sessionId'], "Correct session ID." );
- $this->assertEquals( $sinfo['userId'], $info['userId'], "Correct user ID." );
- $this->assertEquals(
- $sinfo['ip'],
- $context->getRequest()->getIP(),
- "Correct context IP address."
- );
- $this->assertEquals(
- $sinfo['headers'],
- $context->getRequest()->getAllHeaders(),
- "Correct context headers."
- );
- $this->assertEquals( $sinfo['sessionId'], session_id(), "Correct context session ID." );
- $this->assertEquals( true, $context->getUser()->isLoggedIn(), "Correct context user." );
- $this->assertEquals( $sinfo['userId'], $context->getUser()->getId(), "Correct context user ID." );
- $this->assertEquals(
- 'UnitTestContextUser',
- $context->getUser()->getName(),
- "Correct context user name."
- );
-
- unset( $sc ); // restore previous context
-
- $info = $context->exportSession();
- $this->assertEquals( $oInfo['ip'], $info['ip'], "Correct restored IP address." );
- $this->assertEquals( $oInfo['headers'], $info['headers'], "Correct restored headers." );
- $this->assertEquals( $oInfo['sessionId'], $info['sessionId'], "Correct restored session ID." );
- $this->assertEquals( $oInfo['userId'], $info['userId'], "Correct restored user ID." );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @covers SpecialPage
- *
- * @group Database
- *
- * @licence GNU GPL v2+
- * @author Katie Filbert < aude.wiki@gmail.com >
- */
-class SpecialPageTest extends MediaWikiTestCase {
-
- protected function setUp() {
- parent::setUp();
-
- $this->setMwGlobals( array(
- 'wgScript' => '/index.php',
- 'wgContLang' => Language::factory( 'en' )
- ) );
- }
-
- /**
- * @dataProvider getTitleForProvider
- */
- public function testGetTitleFor( $expectedName, $name ) {
- $title = SpecialPage::getTitleFor( $name );
- $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
- $this->assertEquals( $expected, $title );
- }
-
- public function getTitleForProvider() {
- return array(
- array( 'UserLogin', 'Userlogin' )
- );
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error_Notice
- */
- public function testInvalidGetTitleFor() {
- $title = SpecialPage::getTitleFor( 'cat' );
- $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
- $this->assertEquals( $expected, $title );
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error_Notice
- * @dataProvider getTitleForWithWarningProvider
- */
- public function testGetTitleForWithWarning( $expected, $name ) {
- $title = SpecialPage::getTitleFor( $name );
- $this->assertEquals( $expected, $title );
- }
-
- public function getTitleForWithWarningProvider() {
- return array(
- array( Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' )
- );
- }
-
- /**
- * @dataProvider requireLoginAnonProvider
- */
- public function testRequireLoginAnon( $expected, $reason, $title ) {
- $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
-
- $user = User::newFromId( 0 );
- $specialPage->getContext()->setUser( $user );
- $specialPage->getContext()->setLanguage( Language::factory( 'en' ) );
-
- $this->setExpectedException( 'UserNotLoggedIn', $expected );
-
- // $specialPage->requireLogin( [ $reason [, $title ] ] )
- call_user_func_array(
- array( $specialPage, 'requireLogin' ),
- array_filter( array( $reason, $title ) )
- );
- }
-
- public function requireLoginAnonProvider() {
- $lang = 'en';
-
- $expected1 = wfMessage( 'exception-nologin-text' )->inLanguage( $lang )->text();
- $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
-
- return array(
- array( $expected1, null, null ),
- array( $expected2, 'about', null ),
- array( $expected2, 'about', 'about' ),
- );
- }
-
- public function testRequireLoginNotAnon() {
- $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
-
- $user = User::newFromName( "UTSysop" );
- $specialPage->getContext()->setUser( $user );
-
- $specialPage->requireLogin();
-
- // no exception thrown, logged in use can access special page
- $this->assertTrue( true );
- }
-
-}
+++ /dev/null
-<?php
-
-/**
- * @group ContentHandler
- * @group Database
- * ^--- important, causes temporary tables to be used instead of the real database
- * @group medium
- **/
-class WikiPageTest extends MediaWikiLangTestCase {
-
- protected $pages_to_delete;
-
- function __construct( $name = null, array $data = array(), $dataName = '' ) {
- parent::__construct( $name, $data, $dataName );
-
- $this->tablesUsed = array_merge(
- $this->tablesUsed,
- array( 'page',
- 'revision',
- 'text',
-
- 'recentchanges',
- 'logging',
-
- 'page_props',
- 'pagelinks',
- 'categorylinks',
- 'langlinks',
- 'externallinks',
- 'imagelinks',
- 'templatelinks',
- 'iwlinks' ) );
- }
-
- protected function setUp() {
- parent::setUp();
- $this->pages_to_delete = array();
-
- LinkCache::singleton()->clear(); # avoid cached redirect status, etc
- }
-
- protected function tearDown() {
- foreach ( $this->pages_to_delete as $p ) {
- /* @var $p WikiPage */
-
- try {
- if ( $p->exists() ) {
- $p->doDeleteArticle( "testing done." );
- }
- } catch ( MWException $ex ) {
- // fail silently
- }
- }
- parent::tearDown();
- }
-
- /**
- * @param Title|string $title
- * @param string|null $model
- * @return WikiPage
- */
- protected function newPage( $title, $model = null ) {
- if ( is_string( $title ) ) {
- $ns = $this->getDefaultWikitextNS();
- $title = Title::newFromText( $title, $ns );
- }
-
- $p = new WikiPage( $title );
-
- $this->pages_to_delete[] = $p;
-
- return $p;
- }
-
- /**
- * @param string|Title|WikiPage $page
- * @param string $text
- * @param int $model
- *
- * @return WikiPage
- */
- protected function createPage( $page, $text, $model = null ) {
- if ( is_string( $page ) || $page instanceof Title ) {
- $page = $this->newPage( $page, $model );
- }
-
- $content = ContentHandler::makeContent( $text, $page->getTitle(), $model );
- $page->doEditContent( $content, "testing", EDIT_NEW );
-
- return $page;
- }
-
- /**
- * @covers WikiPage::doEditContent
- */
- public function testDoEditContent() {
- $page = $this->newPage( "WikiPageTest_testDoEditContent" );
- $title = $page->getTitle();
-
- $content = ContentHandler::makeContent(
- "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
- . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
- $title,
- CONTENT_MODEL_WIKITEXT
- );
-
- $page->doEditContent( $content, "[[testing]] 1" );
-
- $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
- $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
- $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
- $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
-
- $id = $page->getId();
-
- # ------------------------
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
- $n = $res->numRows();
- $res->free();
-
- $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
-
- # ------------------------
- $page = new WikiPage( $title );
-
- $retrieved = $page->getContent();
- $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
-
- # ------------------------
- $content = ContentHandler::makeContent(
- "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
- . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.",
- $title,
- CONTENT_MODEL_WIKITEXT
- );
-
- $page->doEditContent( $content, "testing 2" );
-
- # ------------------------
- $page = new WikiPage( $title );
-
- $retrieved = $page->getContent();
- $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
-
- # ------------------------
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
- $n = $res->numRows();
- $res->free();
-
- $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
- }
-
- /**
- * @covers WikiPage::doEdit
- */
- public function testDoEdit() {
- $this->hideDeprecated( "WikiPage::doEdit" );
- $this->hideDeprecated( "WikiPage::getText" );
- $this->hideDeprecated( "Revision::getText" );
-
- //NOTE: assume help namespace will default to wikitext
- $title = Title::newFromText( "Help:WikiPageTest_testDoEdit" );
-
- $page = $this->newPage( $title );
-
- $text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
- . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
-
- $page->doEdit( $text, "[[testing]] 1" );
-
- $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
- $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
- $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
- $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
-
- $id = $page->getId();
-
- # ------------------------
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
- $n = $res->numRows();
- $res->free();
-
- $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
-
- # ------------------------
- $page = new WikiPage( $title );
-
- $retrieved = $page->getText();
- $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );
-
- # ------------------------
- $text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
- . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.";
-
- $page->doEdit( $text, "testing 2" );
-
- # ------------------------
- $page = new WikiPage( $title );
-
- $retrieved = $page->getText();
- $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );
-
- # ------------------------
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
- $n = $res->numRows();
- $res->free();
-
- $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
- }
-
- /**
- * @covers WikiPage::doQuickEdit
- */
- public function testDoQuickEdit() {
- global $wgUser;
-
- $this->hideDeprecated( "WikiPage::doQuickEdit" );
-
- //NOTE: assume help namespace will default to wikitext
- $page = $this->createPage( "Help:WikiPageTest_testDoQuickEdit", "original text" );
-
- $text = "quick text";
- $page->doQuickEdit( $text, $wgUser, "testing q" );
-
- # ---------------------
- $page = new WikiPage( $page->getTitle() );
- $this->assertEquals( $text, $page->getText() );
- }
-
- /**
- * @covers WikiPage::doQuickEditContent
- */
- public function testDoQuickEditContent() {
- global $wgUser;
-
- $page = $this->createPage(
- "WikiPageTest_testDoQuickEditContent",
- "original text",
- CONTENT_MODEL_WIKITEXT
- );
-
- $content = ContentHandler::makeContent(
- "quick text",
- $page->getTitle(),
- CONTENT_MODEL_WIKITEXT
- );
- $page->doQuickEditContent( $content, $wgUser, "testing q" );
-
- # ---------------------
- $page = new WikiPage( $page->getTitle() );
- $this->assertTrue( $content->equals( $page->getContent() ) );
- }
-
- /**
- * @covers WikiPage::doDeleteArticle
- */
- public function testDoDeleteArticle() {
- $page = $this->createPage(
- "WikiPageTest_testDoDeleteArticle",
- "[[original text]] foo",
- CONTENT_MODEL_WIKITEXT
- );
- $id = $page->getId();
-
- $page->doDeleteArticle( "testing deletion" );
-
- $this->assertFalse(
- $page->getTitle()->getArticleID() > 0,
- "Title object should now have page id 0"
- );
- $this->assertFalse( $page->getId() > 0, "WikiPage should now have page id 0" );
- $this->assertFalse(
- $page->exists(),
- "WikiPage::exists should return false after page was deleted"
- );
- $this->assertNull(
- $page->getContent(),
- "WikiPage::getContent should return null after page was deleted"
- );
- $this->assertFalse(
- $page->getText(),
- "WikiPage::getText should return false after page was deleted"
- );
-
- $t = Title::newFromText( $page->getTitle()->getPrefixedText() );
- $this->assertFalse(
- $t->exists(),
- "Title::exists should return false after page was deleted"
- );
-
- # ------------------------
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
- $n = $res->numRows();
- $res->free();
-
- $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
- }
-
- /**
- * @covers WikiPage::doDeleteUpdates
- */
- public function testDoDeleteUpdates() {
- $page = $this->createPage(
- "WikiPageTest_testDoDeleteArticle",
- "[[original text]] foo",
- CONTENT_MODEL_WIKITEXT
- );
- $id = $page->getId();
-
- $page->doDeleteUpdates( $id );
-
- # ------------------------
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
- $n = $res->numRows();
- $res->free();
-
- $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
- }
-
- /**
- * @covers WikiPage::getRevision
- */
- public function testGetRevision() {
- $page = $this->newPage( "WikiPageTest_testGetRevision" );
-
- $rev = $page->getRevision();
- $this->assertNull( $rev );
-
- # -----------------
- $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
-
- $rev = $page->getRevision();
-
- $this->assertEquals( $page->getLatest(), $rev->getId() );
- $this->assertEquals( "some text", $rev->getContent()->getNativeData() );
- }
-
- /**
- * @covers WikiPage::getContent
- */
- public function testGetContent() {
- $page = $this->newPage( "WikiPageTest_testGetContent" );
-
- $content = $page->getContent();
- $this->assertNull( $content );
-
- # -----------------
- $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
-
- $content = $page->getContent();
- $this->assertEquals( "some text", $content->getNativeData() );
- }
-
- /**
- * @covers WikiPage::getText
- */
- public function testGetText() {
- $this->hideDeprecated( "WikiPage::getText" );
-
- $page = $this->newPage( "WikiPageTest_testGetText" );
-
- $text = $page->getText();
- $this->assertFalse( $text );
-
- # -----------------
- $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
-
- $text = $page->getText();
- $this->assertEquals( "some text", $text );
- }
-
- /**
- * @covers WikiPage::getRawText
- */
- public function testGetRawText() {
- $this->hideDeprecated( "WikiPage::getRawText" );
-
- $page = $this->newPage( "WikiPageTest_testGetRawText" );
-
- $text = $page->getRawText();
- $this->assertFalse( $text );
-
- # -----------------
- $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
-
- $text = $page->getRawText();
- $this->assertEquals( "some text", $text );
- }
-
- /**
- * @covers WikiPage::getContentModel
- */
- public function testGetContentModel() {
- global $wgContentHandlerUseDB;
-
- if ( !$wgContentHandlerUseDB ) {
- $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
- }
-
- $page = $this->createPage(
- "WikiPageTest_testGetContentModel",
- "some text",
- CONTENT_MODEL_JAVASCRIPT
- );
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $page->getContentModel() );
- }
-
- /**
- * @covers WikiPage::getContentHandler
- */
- public function testGetContentHandler() {
- global $wgContentHandlerUseDB;
-
- if ( !$wgContentHandlerUseDB ) {
- $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
- }
-
- $page = $this->createPage(
- "WikiPageTest_testGetContentHandler",
- "some text",
- CONTENT_MODEL_JAVASCRIPT
- );
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertEquals( 'JavaScriptContentHandler', get_class( $page->getContentHandler() ) );
- }
-
- /**
- * @covers WikiPage::exists
- */
- public function testExists() {
- $page = $this->newPage( "WikiPageTest_testExists" );
- $this->assertFalse( $page->exists() );
-
- # -----------------
- $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
- $this->assertTrue( $page->exists() );
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertTrue( $page->exists() );
-
- # -----------------
- $page->doDeleteArticle( "done testing" );
- $this->assertFalse( $page->exists() );
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertFalse( $page->exists() );
- }
-
- public static function provideHasViewableContent() {
- return array(
- array( 'WikiPageTest_testHasViewableContent', false, true ),
- array( 'Special:WikiPageTest_testHasViewableContent', false ),
- array( 'MediaWiki:WikiPageTest_testHasViewableContent', false ),
- array( 'Special:Userlogin', true ),
- array( 'MediaWiki:help', true ),
- );
- }
-
- /**
- * @dataProvider provideHasViewableContent
- * @covers WikiPage::hasViewableContent
- */
- public function testHasViewableContent( $title, $viewable, $create = false ) {
- $page = $this->newPage( $title );
- $this->assertEquals( $viewable, $page->hasViewableContent() );
-
- if ( $create ) {
- $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
- $this->assertTrue( $page->hasViewableContent() );
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertTrue( $page->hasViewableContent() );
- }
- }
-
- public static function provideGetRedirectTarget() {
- return array(
- array( 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT, "hello world", null ),
- array(
- 'WikiPageTest_testGetRedirectTarget_2',
- CONTENT_MODEL_WIKITEXT,
- "#REDIRECT [[hello world]]",
- "Hello world"
- ),
- );
- }
-
- /**
- * @dataProvider provideGetRedirectTarget
- * @covers WikiPage::getRedirectTarget
- */
- public function testGetRedirectTarget( $title, $model, $text, $target ) {
- $this->setMwGlobals( array(
- 'wgCapitalLinks' => true,
- ) );
-
- $page = $this->createPage( $title, $text, $model );
-
- # sanity check, because this test seems to fail for no reason for some people.
- $c = $page->getContent();
- $this->assertEquals( 'WikitextContent', get_class( $c ) );
-
- # now, test the actual redirect
- $t = $page->getRedirectTarget();
- $this->assertEquals( $target, is_null( $t ) ? null : $t->getPrefixedText() );
- }
-
- /**
- * @dataProvider provideGetRedirectTarget
- * @covers WikiPage::isRedirect
- */
- public function testIsRedirect( $title, $model, $text, $target ) {
- $page = $this->createPage( $title, $text, $model );
- $this->assertEquals( !is_null( $target ), $page->isRedirect() );
- }
-
- public static function provideIsCountable() {
- return array(
-
- // any
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '',
- 'any',
- true
- ),
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'any',
- true
- ),
-
- // comma
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'comma',
- false
- ),
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo, bar',
- 'comma',
- true
- ),
-
- // link
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'link',
- false
- ),
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo [[bar]]',
- 'link',
- true
- ),
-
- // redirects
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '#REDIRECT [[bar]]',
- 'any',
- false
- ),
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '#REDIRECT [[bar]]',
- 'comma',
- false
- ),
- array( 'WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- '#REDIRECT [[bar]]',
- 'link',
- false
- ),
-
- // not a content namespace
- array( 'Talk:WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo',
- 'any',
- false
- ),
- array( 'Talk:WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo, bar',
- 'comma',
- false
- ),
- array( 'Talk:WikiPageTest_testIsCountable',
- CONTENT_MODEL_WIKITEXT,
- 'Foo [[bar]]',
- 'link',
- false
- ),
-
- // not a content namespace, different model
- array( 'MediaWiki:WikiPageTest_testIsCountable.js',
- null,
- 'Foo',
- 'any',
- false
- ),
- array( 'MediaWiki:WikiPageTest_testIsCountable.js',
- null,
- 'Foo, bar',
- 'comma',
- false
- ),
- array( 'MediaWiki:WikiPageTest_testIsCountable.js',
- null,
- 'Foo [[bar]]',
- 'link',
- false
- ),
- );
- }
-
- /**
- * @dataProvider provideIsCountable
- * @covers WikiPage::isCountable
- */
- public function testIsCountable( $title, $model, $text, $mode, $expected ) {
- global $wgContentHandlerUseDB;
-
- $this->setMwGlobals( 'wgArticleCountMethod', $mode );
-
- $title = Title::newFromText( $title );
-
- if ( !$wgContentHandlerUseDB
- && $model
- && ContentHandler::getDefaultModelFor( $title ) != $model
- ) {
- $this->markTestSkipped( "Can not use non-default content model $model for "
- . $title->getPrefixedDBkey() . " with \$wgContentHandlerUseDB disabled." );
- }
-
- $page = $this->createPage( $title, $text, $model );
-
- $editInfo = $page->prepareContentForEdit( $page->getContent() );
-
- $v = $page->isCountable();
- $w = $page->isCountable( $editInfo );
-
- $this->assertEquals(
- $expected,
- $v,
- "isCountable( null ) returned unexpected value " . var_export( $v, true )
- . " instead of " . var_export( $expected, true )
- . " in mode `$mode` for text \"$text\""
- );
-
- $this->assertEquals(
- $expected,
- $w,
- "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
- . " instead of " . var_export( $expected, true )
- . " in mode `$mode` for text \"$text\""
- );
- }
-
- public static function provideGetParserOutput() {
- return array(
- array( CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i></p>" ),
- // @todo more...?
- );
- }
-
- /**
- * @dataProvider provideGetParserOutput
- * @covers WikiPage::getParserOutput
- */
- public function testGetParserOutput( $model, $text, $expectedHtml ) {
- $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model );
-
- $opt = $page->makeParserOptions( 'canonical' );
- $po = $page->getParserOutput( $opt );
- $text = $po->getText();
-
- $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
- $text = preg_replace( '!\s*(</p>)!sm', '\1', $text ); # don't let tidy confuse us
-
- $this->assertEquals( $expectedHtml, $text );
-
- return $po;
- }
-
- /**
- * @covers WikiPage::getParserOutput
- */
- public function testGetParserOutput_nonexisting() {
- static $count = 0;
- $count++;
-
- $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
-
- $opt = new ParserOptions();
- $po = $page->getParserOutput( $opt );
-
- $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
- }
-
- /**
- * @covers WikiPage::getParserOutput
- */
- public function testGetParserOutput_badrev() {
- $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT );
-
- $opt = new ParserOptions();
- $po = $page->getParserOutput( $opt, $page->getLatest() + 1234 );
-
- // @todo would be neat to also test deleted revision
-
- $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
- }
-
- public static $sections =
-
- "Intro
-
-== stuff ==
-hello world
-
-== test ==
-just a test
-
-== foo ==
-more stuff
-";
-
- public function dataReplaceSection() {
- //NOTE: assume the Help namespace to contain wikitext
- return array(
- array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "0",
- "No more",
- null,
- trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest::$sections ) )
- ),
- array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "",
- "No more",
- null,
- "No more"
- ),
- array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "2",
- "== TEST ==\nmore fun",
- null,
- trim( preg_replace( '/^== test ==.*== foo ==/sm',
- "== TEST ==\nmore fun\n\n== foo ==",
- WikiPageTest::$sections ) )
- ),
- array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "8",
- "No more",
- null,
- trim( WikiPageTest::$sections )
- ),
- array( 'Help:WikiPageTest_testReplaceSection',
- CONTENT_MODEL_WIKITEXT,
- WikiPageTest::$sections,
- "new",
- "No more",
- "New",
- trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more"
- ),
- );
- }
-
- /**
- * @dataProvider dataReplaceSection
- * @covers WikiPage::replaceSection
- */
- public function testReplaceSection( $title, $model, $text, $section, $with,
- $sectionTitle, $expected
- ) {
- $this->hideDeprecated( "WikiPage::replaceSection" );
-
- $page = $this->createPage( $title, $text, $model );
- $text = $page->replaceSection( $section, $with, $sectionTitle );
- $text = trim( $text );
-
- $this->assertEquals( $expected, $text );
- }
-
- /**
- * @dataProvider dataReplaceSection
- * @covers WikiPage::replaceSectionContent
- */
- public function testReplaceSectionContent( $title, $model, $text, $section,
- $with, $sectionTitle, $expected
- ) {
- $page = $this->createPage( $title, $text, $model );
-
- $content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
- $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
-
- $this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
- }
-
- /**
- * @dataProvider dataReplaceSection
- * @covers WikiPage::replaceSectionAtRev
- */
- public function testReplaceSectionAtRev( $title, $model, $text, $section,
- $with, $sectionTitle, $expected
- ) {
- $page = $this->createPage( $title, $text, $model );
- $baseRevId = $page->getLatest();
-
- $content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
- $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
-
- $this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
- }
-
- /* @todo FIXME: fix this!
- public function testGetUndoText() {
- $this->checkHasDiff3();
-
- $text = "one";
- $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
- $rev1 = $page->getRevision();
-
- $text .= "\n\ntwo";
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section two"
- );
- $rev2 = $page->getRevision();
-
- $text .= "\n\nthree";
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section three"
- );
- $rev3 = $page->getRevision();
-
- $text .= "\n\nfour";
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section four"
- );
- $rev4 = $page->getRevision();
-
- $text .= "\n\nfive";
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section five"
- );
- $rev5 = $page->getRevision();
-
- $text .= "\n\nsix";
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section six"
- );
- $rev6 = $page->getRevision();
-
- $undo6 = $page->getUndoText( $rev6 );
- if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
- $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
-
- $undo3 = $page->getUndoText( $rev4, $rev2 );
- if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
- $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
-
- $undo2 = $page->getUndoText( $rev2 );
- if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
- $this->assertEquals( "one\n\nfive", $undo2 );
- }
- */
-
- /**
- * @todo FIXME: this is a better rollback test than the one below, but it
- * keeps failing in jenkins for some reason.
- */
- public function broken_testDoRollback() {
- $admin = new User();
- $admin->setName( "Admin" );
-
- $text = "one";
- $page = $this->newPage( "WikiPageTest_testDoRollback" );
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
- "section one", EDIT_NEW, false, $admin );
-
- $user1 = new User();
- $user1->setName( "127.0.1.11" );
- $text .= "\n\ntwo";
- $page = new WikiPage( $page->getTitle() );
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section two", 0, false, $user1 );
-
- $user2 = new User();
- $user2->setName( "127.0.2.13" );
- $text .= "\n\nthree";
- $page = new WikiPage( $page->getTitle() );
- $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
- "adding section three", 0, false, $user2 );
-
- # we are having issues with doRollback spuriously failing. Apparently
- # the last revision somehow goes missing or not committed under some
- # circumstances. So, make sure the last revision has the right user name.
- $dbr = wfGetDB( DB_SLAVE );
- $this->assertEquals( 3, Revision::countByPageId( $dbr, $page->getId() ) );
-
- $page = new WikiPage( $page->getTitle() );
- $rev3 = $page->getRevision();
- $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
-
- $rev2 = $rev3->getPrevious();
- $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
-
- $rev1 = $rev2->getPrevious();
- $this->assertEquals( 'Admin', $rev1->getUserText() );
-
- # now, try the actual rollback
- $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
- $token = $admin->getEditToken(
- array( $page->getTitle()->getPrefixedText(), $user2->getName() ),
- null
- );
- $errors = $page->doRollback(
- $user2->getName(),
- "testing revert",
- $token,
- false,
- $details,
- $admin
- );
-
- if ( $errors ) {
- $this->fail( "Rollback failed:\n" . print_r( $errors, true )
- . ";\n" . print_r( $details, true ) );
- }
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
- "rollback did not revert to the correct revision" );
- $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
- }
-
- /**
- * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
- * @covers WikiPage::doRollback
- */
- public function testDoRollback() {
- $admin = new User();
- $admin->setName( "Admin" );
-
- $text = "one";
- $page = $this->newPage( "WikiPageTest_testDoRollback" );
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- "section one",
- EDIT_NEW,
- false,
- $admin
- );
- $rev1 = $page->getRevision();
-
- $user1 = new User();
- $user1->setName( "127.0.1.11" );
- $text .= "\n\ntwo";
- $page = new WikiPage( $page->getTitle() );
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- "adding section two",
- 0,
- false,
- $user1
- );
-
- # now, try the rollback
- $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
- $token = $admin->getEditToken(
- array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
- null
- );
- $errors = $page->doRollback(
- $user1->getName(),
- "testing revert",
- $token,
- false,
- $details,
- $admin
- );
-
- if ( $errors ) {
- $this->fail( "Rollback failed:\n" . print_r( $errors, true )
- . ";\n" . print_r( $details, true ) );
- }
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
- "rollback did not revert to the correct revision" );
- $this->assertEquals( "one", $page->getContent()->getNativeData() );
- }
-
- /**
- * @covers WikiPage::doRollback
- */
- public function testDoRollbackFailureSameContent() {
- $admin = new User();
- $admin->setName( "Admin" );
- $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
-
- $text = "one";
- $page = $this->newPage( "WikiPageTest_testDoRollback" );
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- "section one",
- EDIT_NEW,
- false,
- $admin
- );
- $rev1 = $page->getRevision();
-
- $user1 = new User();
- $user1->setName( "127.0.1.11" );
- $user1->addGroup( "sysop" ); #XXX: make the test user a sysop...
- $text .= "\n\ntwo";
- $page = new WikiPage( $page->getTitle() );
- $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- "adding section two",
- 0,
- false,
- $user1
- );
-
- # now, do a the rollback from the same user was doing the edit before
- $resultDetails = array();
- $token = $user1->getEditToken(
- array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
- null
- );
- $errors = $page->doRollback(
- $user1->getName(),
- "testing revert same user",
- $token,
- false,
- $resultDetails,
- $admin
- );
-
- $this->assertEquals( array(), $errors, "Rollback failed same user" );
-
- # now, try the rollback
- $resultDetails = array();
- $token = $admin->getEditToken(
- array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
- null
- );
- $errors = $page->doRollback(
- $user1->getName(),
- "testing revert",
- $token,
- false,
- $resultDetails,
- $admin
- );
-
- $this->assertEquals( array( array( 'alreadyrolled', 'WikiPageTest testDoRollback',
- '127.0.1.11', 'Admin' ) ), $errors, "Rollback not failed" );
-
- $page = new WikiPage( $page->getTitle() );
- $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
- "rollback did not revert to the correct revision" );
- $this->assertEquals( "one", $page->getContent()->getNativeData() );
- }
-
- public static function provideGetAutosummary() {
- return array(
- array(
- 'Hello there, world!',
- '#REDIRECT [[Foo]]',
- 0,
- '/^Redirected page .*Foo/'
- ),
-
- array(
- null,
- 'Hello world!',
- EDIT_NEW,
- '/^Created page .*Hello/'
- ),
-
- array(
- 'Hello there, world!',
- '',
- 0,
- '/^Blanked/'
- ),
-
- array(
- 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
- eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
- voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
- clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
- 'Hello world!',
- 0,
- '/^Replaced .*Hello/'
- ),
-
- array(
- 'foo',
- 'bar',
- 0,
- '/^$/'
- ),
- );
- }
-
- /**
- * @dataProvider provideGetAutoSummary
- * @covers WikiPage::getAutosummary
- */
- public function testGetAutosummary( $old, $new, $flags, $expected ) {
- $this->hideDeprecated( "WikiPage::getAutosummary" );
-
- $page = $this->newPage( "WikiPageTest_testGetAutosummary" );
-
- $summary = $page->getAutosummary( $old, $new, $flags );
-
- $this->assertTrue( (bool)preg_match( $expected, $summary ),
- "Autosummary didn't match expected pattern $expected: $summary" );
- }
-
- public static function provideGetAutoDeleteReason() {
- return array(
- array(
- array(),
- false,
- false
- ),
-
- array(
- array(
- array( "first edit", null ),
- ),
- "/first edit.*only contributor/",
- false
- ),
-
- array(
- array(
- array( "first edit", null ),
- array( "second edit", null ),
- ),
- "/second edit.*only contributor/",
- true
- ),
-
- array(
- array(
- array( "first edit", "127.0.2.22" ),
- array( "second edit", "127.0.3.33" ),
- ),
- "/second edit/",
- true
- ),
-
- array(
- array(
- array(
- "first edit: "
- . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
- . " nonumy eirmod tempor invidunt ut labore et dolore magna "
- . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
- . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
- . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
- null
- ),
- ),
- '/first edit:.*\.\.\."/',
- false
- ),
-
- array(
- array(
- array( "first edit", "127.0.2.22" ),
- array( "", "127.0.3.33" ),
- ),
- "/before blanking.*first edit/",
- true
- ),
-
- );
- }
-
- /**
- * @dataProvider provideGetAutoDeleteReason
- * @covers WikiPage::getAutoDeleteReason
- */
- public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
- global $wgUser;
-
- //NOTE: assume Help namespace to contain wikitext
- $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
-
- $c = 1;
-
- foreach ( $edits as $edit ) {
- $user = new User();
-
- if ( !empty( $edit[1] ) ) {
- $user->setName( $edit[1] );
- } else {
- $user = $wgUser;
- }
-
- $content = ContentHandler::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
-
- $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW : 0, false, $user );
-
- $c += 1;
- }
-
- $reason = $page->getAutoDeleteReason( $hasHistory );
-
- if ( is_bool( $expectedResult ) || is_null( $expectedResult ) ) {
- $this->assertEquals( $expectedResult, $reason );
- } else {
- $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
- "Autosummary didn't match expected pattern $expectedResult: $reason" );
- }
-
- $this->assertEquals( $expectedHistory, $hasHistory,
- "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
-
- $page->doDeleteArticle( "done" );
- }
-
- public static function providePreSaveTransform() {
- return array(
- array( 'hello this is ~~~',
- "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
- ),
- array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
- 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
- ),
- );
- }
-
- /**
- * @dataProvider providePreSaveTransform
- * @covers WikiPage::preSaveTransform
- */
- public function testPreSaveTransform( $text, $expected ) {
- $this->hideDeprecated( 'WikiPage::preSaveTransform' );
- $user = new User();
- $user->setName( "127.0.0.1" );
-
- //NOTE: assume Help namespace to contain wikitext
- $page = $this->newPage( "Help:WikiPageTest_testPreloadTransform" );
- $text = $page->preSaveTransform( $text, $user );
-
- $this->assertEquals( $expected, $text );
- }
-
- /**
- * @covers WikiPage::factory
- */
- public function testWikiPageFactory() {
- $title = Title::makeTitle( NS_FILE, 'Someimage.png' );
- $page = WikiPage::factory( $title );
- $this->assertEquals( 'WikiFilePage', get_class( $page ) );
-
- $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
- $page = WikiPage::factory( $title );
- $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
-
- $title = Title::makeTitle( NS_MAIN, 'SomePage' );
- $page = WikiPage::factory( $title );
- $this->assertEquals( 'WikiPage', get_class( $page ) );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @group ContentHandler
- * @group Database
- * ^--- important, causes temporary tables to be used instead of the real database
- */
-class WikiPageTestContentHandlerUseDB extends WikiPageTest {
-
- protected function setUp() {
- parent::setUp();
- $this->setMwGlobals( 'wgContentHandlerUseDB', false );
-
- $dbw = wfGetDB( DB_MASTER );
-
- $page_table = $dbw->tableName( 'page' );
- $revision_table = $dbw->tableName( 'revision' );
- $archive_table = $dbw->tableName( 'archive' );
-
- if ( $dbw->fieldExists( $page_table, 'page_content_model' ) ) {
- $dbw->query( "alter table $page_table drop column page_content_model" );
- $dbw->query( "alter table $revision_table drop column rev_content_model" );
- $dbw->query( "alter table $revision_table drop column rev_content_format" );
- $dbw->query( "alter table $archive_table drop column ar_content_model" );
- $dbw->query( "alter table $archive_table drop column ar_content_format" );
- }
- }
-
- /**
- * @covers WikiPage::getContentModel
- */
- public function testGetContentModel() {
- $page = $this->createPage(
- "WikiPageTest_testGetContentModel",
- "some text",
- CONTENT_MODEL_JAVASCRIPT
- );
-
- $page = new WikiPage( $page->getTitle() );
-
- // NOTE: since the content model is not recorded in the database,
- // we expect to get the default, namely CONTENT_MODEL_WIKITEXT
- $this->assertEquals( CONTENT_MODEL_WIKITEXT, $page->getContentModel() );
- }
-
- /**
- * @covers WikiPage::getContentHandler
- */
- public function testGetContentHandler() {
- $page = $this->createPage(
- "WikiPageTest_testGetContentHandler",
- "some text",
- CONTENT_MODEL_JAVASCRIPT
- );
-
- // NOTE: since the content model is not recorded in the database,
- // we expect to get the default, namely CONTENT_MODEL_WIKITEXT
- $page = new WikiPage( $page->getTitle() );
- $this->assertEquals( 'WikitextContentHandler', get_class( $page->getContentHandler() ) );
- }
-}
+++ /dev/null
-<?php
-/**
- * PHPUnit tests for XMLTypeCheck.
- * @author physikerwelt
- * @group Xml
- * @covers XMLTypeCheck
- */
-class XmlTypeCheckTest extends MediaWikiTestCase {
- const WELL_FORMED_XML = "<root><child /></root>";
- const MAL_FORMED_XML = "<root><child /></error>";
-
- /**
- * @covers XMLTypeCheck::newFromString
- * @covers XMLTypeCheck::getRootElement
- */
- public function testWellFormedXML() {
- $testXML = XmlTypeCheck::newFromString( self::WELL_FORMED_XML );
- $this->assertTrue( $testXML->wellFormed );
- $this->assertEquals( 'root', $testXML->getRootElement() );
- }
-
- /**
- * @covers XMLTypeCheck::newFromString
- */
- public function testMalFormedXML() {
- $testXML = XmlTypeCheck::newFromString( self::MAL_FORMED_XML );
- $this->assertFalse( $testXML->wellFormed );
- }
-
-}
--- /dev/null
+<?php
+
+/**
+ * @group Database
+ * @group RequestContext
+ */
+class RequestContextTest extends MediaWikiTestCase {
+
+ /**
+ * Test the relationship between title and wikipage in RequestContext
+ * @covers RequestContext::getWikiPage
+ * @covers RequestContext::getTitle
+ */
+ public function testWikiPageTitle() {
+ $context = new RequestContext();
+
+ $curTitle = Title::newFromText( "A" );
+ $context->setTitle( $curTitle );
+ $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ),
+ "When a title is first set WikiPage should be created on-demand for that title." );
+
+ $curTitle = Title::newFromText( "B" );
+ $context->setWikiPage( WikiPage::factory( $curTitle ) );
+ $this->assertTrue( $curTitle->equals( $context->getTitle() ),
+ "Title must be updated when a new WikiPage is provided." );
+
+ $curTitle = Title::newFromText( "C" );
+ $context->setTitle( $curTitle );
+ $this->assertTrue(
+ $curTitle->equals( $context->getWikiPage()->getTitle() ),
+ "When a title is updated the WikiPage should be purged "
+ . "and recreated on-demand with the new title."
+ );
+ }
+
+ /**
+ * @covers RequestContext::importScopedSession
+ */
+ public function testImportScopedSession() {
+ $context = RequestContext::getMain();
+
+ $oInfo = $context->exportSession();
+ $this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." );
+ $this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." );
+
+ $user = User::newFromName( 'UnitTestContextUser' );
+ $user->addToDatabase();
+
+ $sinfo = array(
+ 'sessionId' => 'd612ee607c87e749ef14da4983a702cd',
+ 'userId' => $user->getId(),
+ 'ip' => '192.0.2.0',
+ 'headers' => array(
+ 'USER-AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0'
+ )
+ );
+ // importScopedSession() sets these variables
+ $this->setMwGlobals( array(
+ 'wgUser' => new User,
+ 'wgRequest' => new FauxRequest,
+ ) );
+ $sc = RequestContext::importScopedSession( $sinfo ); // load new context
+
+ $info = $context->exportSession();
+ $this->assertEquals( $sinfo['ip'], $info['ip'], "Correct IP address." );
+ $this->assertEquals( $sinfo['headers'], $info['headers'], "Correct headers." );
+ $this->assertEquals( $sinfo['sessionId'], $info['sessionId'], "Correct session ID." );
+ $this->assertEquals( $sinfo['userId'], $info['userId'], "Correct user ID." );
+ $this->assertEquals(
+ $sinfo['ip'],
+ $context->getRequest()->getIP(),
+ "Correct context IP address."
+ );
+ $this->assertEquals(
+ $sinfo['headers'],
+ $context->getRequest()->getAllHeaders(),
+ "Correct context headers."
+ );
+ $this->assertEquals( $sinfo['sessionId'], session_id(), "Correct context session ID." );
+ $this->assertEquals( true, $context->getUser()->isLoggedIn(), "Correct context user." );
+ $this->assertEquals( $sinfo['userId'], $context->getUser()->getId(), "Correct context user ID." );
+ $this->assertEquals(
+ 'UnitTestContextUser',
+ $context->getUser()->getName(),
+ "Correct context user name."
+ );
+
+ unset( $sc ); // restore previous context
+
+ $info = $context->exportSession();
+ $this->assertEquals( $oInfo['ip'], $info['ip'], "Correct restored IP address." );
+ $this->assertEquals( $oInfo['headers'], $info['headers'], "Correct restored headers." );
+ $this->assertEquals( $oInfo['sessionId'], $info['sessionId'], "Correct restored session ID." );
+ $this->assertEquals( $oInfo['userId'], $info['userId'], "Correct restored user ID." );
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * @group Database
+ * ^--- make sure temporary tables are used.
+ */
+class LinksUpdateTest extends MediaWikiTestCase {
+
+ function __construct( $name = null, array $data = array(), $dataName = '' ) {
+ parent::__construct( $name, $data, $dataName );
+
+ $this->tablesUsed = array_merge( $this->tablesUsed,
+ array(
+ 'interwiki',
+ 'page_props',
+ 'pagelinks',
+ 'categorylinks',
+ 'langlinks',
+ 'externallinks',
+ 'imagelinks',
+ 'templatelinks',
+ 'iwlinks'
+ )
+ );
+ }
+
+ protected function setUp() {
+ parent::setUp();
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->replace(
+ 'interwiki',
+ array( 'iw_prefix' ),
+ array(
+ 'iw_prefix' => 'linksupdatetest',
+ 'iw_url' => 'http://testing.com/wiki/$1',
+ 'iw_api' => 'http://testing.com/w/api.php',
+ 'iw_local' => 0,
+ 'iw_trans' => 0,
+ 'iw_wikiid' => 'linksupdatetest',
+ )
+ );
+ }
+
+ protected function makeTitleAndParserOutput( $name, $id ) {
+ $t = Title::newFromText( $name );
+ $t->mArticleID = $id; # XXX: this is fugly
+
+ $po = new ParserOutput();
+ $po->setTitleText( $t->getPrefixedText() );
+
+ return array( $t, $po );
+ }
+
+ /**
+ * @covers ParserOutput::addLink
+ */
+ public function testUpdate_pagelinks() {
+ /** @var ParserOutput $po */
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $po->addLink( Title::newFromText( "Foo" ) );
+ $po->addLink( Title::newFromText( "Special:Foo" ) ); // special namespace should be ignored
+ $po->addLink( Title::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored
+ $po->addLink( Title::newFromText( "#Foo" ) ); // hash link should be ignored
+
+ $update = $this->assertLinksUpdate(
+ $t,
+ $po,
+ 'pagelinks',
+ 'pl_namespace,
+ pl_title',
+ 'pl_from = 111',
+ array( array( NS_MAIN, 'Foo' ) )
+ );
+ $this->assertArrayEquals( array(
+ Title::makeTitle( NS_MAIN, 'Foo' ), // newFromText doesn't yield the same internal state....
+ ), $update->getAddedLinks() );
+
+ $po = new ParserOutput();
+ $po->setTitleText( $t->getPrefixedText() );
+
+ $po->addLink( Title::newFromText( "Bar" ) );
+ $po->addLink( Title::newFromText( "Talk:Bar" ) );
+
+ $update = $this->assertLinksUpdate(
+ $t,
+ $po,
+ 'pagelinks',
+ 'pl_namespace,
+ pl_title',
+ 'pl_from = 111',
+ array(
+ array( NS_MAIN, 'Bar' ),
+ array( NS_TALK, 'Bar' ),
+ )
+ );
+ $this->assertArrayEquals( array(
+ Title::makeTitle( NS_MAIN, 'Bar' ),
+ Title::makeTitle( NS_TALK, 'Bar' ),
+ ), $update->getAddedLinks() );
+ $this->assertArrayEquals( array(
+ Title::makeTitle( NS_MAIN, 'Foo' ),
+ ), $update->getRemovedLinks() );
+ }
+
+ /**
+ * @covers ParserOutput::addExternalLink
+ */
+ public function testUpdate_externallinks() {
+ /** @var ParserOutput $po */
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $po->addExternalLink( "http://testing.com/wiki/Foo" );
+
+ $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
+ array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
+ ) );
+ }
+
+ /**
+ * @covers ParserOutput::addCategory
+ */
+ public function testUpdate_categorylinks() {
+ /** @var ParserOutput $po */
+ $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
+
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $po->addCategory( "Foo", "FOO" );
+
+ $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
+ array( 'Foo', "FOO\nTESTING" ),
+ ) );
+ }
+
+ /**
+ * @covers ParserOutput::addInterwikiLink
+ */
+ public function testUpdate_iwlinks() {
+ /** @var ParserOutput $po */
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' );
+ $po->addInterwikiLink( $target );
+
+ $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
+ array( 'linksupdatetest', 'Foo' ),
+ ) );
+ }
+
+ /**
+ * @covers ParserOutput::addTemplate
+ */
+ public function testUpdate_templatelinks() {
+ /** @var ParserOutput $po */
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 );
+
+ $this->assertLinksUpdate(
+ $t,
+ $po,
+ 'templatelinks',
+ 'tl_namespace,
+ tl_title',
+ 'tl_from = 111',
+ array( array( NS_TEMPLATE, 'Foo' ) )
+ );
+ }
+
+ /**
+ * @covers ParserOutput::addImage
+ */
+ public function testUpdate_imagelinks() {
+ /** @var ParserOutput $po */
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $po->addImage( "Foo.png" );
+
+ $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
+ array( 'Foo.png' ),
+ ) );
+ }
+
+ /**
+ * @covers ParserOutput::addLanguageLink
+ */
+ public function testUpdate_langlinks() {
+ $this->setMwGlobals( array(
+ 'wgCapitalLinks' => true,
+ ) );
+
+ /** @var ParserOutput $po */
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() );
+
+ $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
+ array( 'En', 'Foo' ),
+ ) );
+ }
+
+ /**
+ * @covers ParserOutput::setProperty
+ */
+ public function testUpdate_page_props() {
+ global $wgPagePropsHaveSortkey;
+
+ /** @var ParserOutput $po */
+ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
+
+ $fields = array( 'pp_propname', 'pp_value' );
+ $expected = array();
+
+ $po->setProperty( "bool", true );
+ $expected[] = array( "bool", true );
+
+ $po->setProperty( "float", 4.0 + 1.0 / 4.0 );
+ $expected[] = array( "float", 4.0 + 1.0 / 4.0 );
+
+ $po->setProperty( "int", -7 );
+ $expected[] = array( "int", -7 );
+
+ $po->setProperty( "string", "33 bar" );
+ $expected[] = array( "string", "33 bar" );
+
+ // compute expected sortkey values
+ if ( $wgPagePropsHaveSortkey ) {
+ $fields[] = 'pp_sortkey';
+
+ foreach ( $expected as &$row ) {
+ $value = $row[1];
+
+ if ( is_int( $value ) || is_float( $value ) || is_bool( $value ) ) {
+ $row[] = floatval( $value );
+ } else {
+ $row[] = null;
+ }
+ }
+ }
+
+ $this->assertLinksUpdate( $t, $po, 'page_props', $fields, 'pp_page = 111', $expected );
+ }
+
+ public function testUpdate_page_props_without_sortkey() {
+ $this->setMwGlobals( 'wgPagePropsHaveSortkey', false );
+
+ $this->testUpdate_page_props();
+ }
+
+ // @todo test recursive, too!
+
+ protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput,
+ $table, $fields, $condition, array $expectedRows
+ ) {
+ $update = new LinksUpdate( $title, $parserOutput );
+
+ //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
+ $update->beginTransaction();
+ $update->doUpdate();
+ $update->commitTransaction();
+
+ $this->assertSelect( $table, $fields, $condition, $expectedRows );
+ return $update;
+ }
+}
--- /dev/null
+<?php
+
+class MockSearch extends SearchEngine {
+ public static $id;
+ public static $title;
+ public static $text;
+
+ public function __construct( $db ) {
+ }
+
+ public function update( $id, $title, $text ) {
+ self::$id = $id;
+ self::$title = $title;
+ self::$text = $text;
+ }
+}
+
+/**
+ * @group Search
+ * @group Database
+ */
+class SearchUpdateTest extends MediaWikiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+ $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
+ }
+
+ public function updateText( $text ) {
+ return trim( SearchUpdate::updateText( $text ) );
+ }
+
+ /**
+ * @covers SearchUpdate::updateText
+ */
+ public function testUpdateText() {
+ $this->assertEquals(
+ 'test',
+ $this->updateText( '<div>TeSt</div>' ),
+ 'HTML stripped, text lowercased'
+ );
+
+ $this->assertEquals(
+ 'foo bar boz quux',
+ $this->updateText( <<<EOT
+<table style="color:red; font-size:100px">
+ <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
+ <tr><td>boz</td><tr>quux</td></tr>
+</table>
+EOT
+ ), 'Stripping HTML tables' );
+
+ $this->assertEquals(
+ 'a b',
+ $this->updateText( 'a > b' ),
+ 'Handle unclosed tags'
+ );
+
+ $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
+
+ $this->assertNotEquals(
+ '',
+ $this->updateText( $text ),
+ 'Bug 18609'
+ );
+ }
+
+ /**
+ * @covers SearchUpdate::updateText
+ * @todo give this test a real name explaining what is being tested here
+ */
+ public function testBug32712() {
+ $text = "text „http://example.com“ text";
+ $result = $this->updateText( $text );
+ $processed = preg_replace( '/Q/u', 'Q', $result );
+ $this->assertTrue(
+ $processed != '',
+ 'Link surrounded by unicode quotes should not fail UTF-8 validation'
+ );
+ }
+}
--- /dev/null
+<?php
+/**
+ * External Store tests
+ */
+
+class ExternalStoreTest extends MediaWikiTestCase {
+
+ /**
+ * @covers ExternalStore::fetchFromURL
+ */
+ public function testExternalFetchFromURL() {
+ $this->setMwGlobals( 'wgExternalStores', false );
+
+ $this->assertFalse(
+ ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
+ 'Deny if wgExternalStores is not set to a non-empty array'
+ );
+
+ $this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) );
+
+ $this->assertEquals(
+ ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
+ 'Hello',
+ 'Allow FOO://cluster1/200'
+ );
+ $this->assertEquals(
+ ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
+ 'Hello',
+ 'Allow FOO://cluster1/300/0'
+ );
+ # Assertions for r68900
+ $this->assertFalse(
+ ExternalStore::fetchFromURL( 'ftp.example.org' ),
+ 'Deny domain ftp.example.org'
+ );
+ $this->assertFalse(
+ ExternalStore::fetchFromURL( '/example.txt' ),
+ 'Deny path /example.txt'
+ );
+ $this->assertFalse(
+ ExternalStore::fetchFromURL( 'http://' ),
+ 'Deny protocol http://'
+ );
+ }
+}
+
+class ExternalStoreFOO {
+
+ protected $data = array(
+ 'cluster1' => array(
+ '200' => 'Hello',
+ '300' => array(
+ 'Hello', 'World',
+ ),
+ ),
+ );
+
+ /**
+ * Fetch data from given URL
+ * @param string $url An url of the form FOO://cluster/id or FOO://cluster/id/itemid.
+ * @return mixed
+ */
+ function fetchFromURL( $url ) {
+ // Based on ExternalStoreDB
+ $path = explode( '/', $url );
+ $cluster = $path[2];
+ $id = $path[3];
+ if ( isset( $path[4] ) ) {
+ $itemID = $path[4];
+ } else {
+ $itemID = false;
+ }
+
+ if ( !isset( $this->data[$cluster][$id] ) ) {
+ return null;
+ }
+
+ if ( $itemID !== false
+ && is_array( $this->data[$cluster][$id] )
+ && isset( $this->data[$cluster][$id][$itemID] )
+ ) {
+ return $this->data[$cluster][$id][$itemID];
+ }
+
+ return $this->data[$cluster][$id];
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * These tests should work regardless of $wgCapitalLinks
+ * @group Database
+ * @todo Split tests into providers and test methods
+ */
+
+class LocalFileTest extends MediaWikiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( 'wgCapitalLinks', true );
+
+ $info = array(
+ 'name' => 'test',
+ 'directory' => '/testdir',
+ 'url' => '/testurl',
+ 'hashLevels' => 2,
+ 'transformVia404' => false,
+ 'backend' => new FSFileBackend( array(
+ 'name' => 'local-backend',
+ 'wikiId' => wfWikiId(),
+ 'containerPaths' => array(
+ 'cont1' => "/testdir/local-backend/tempimages/cont1",
+ 'cont2' => "/testdir/local-backend/tempimages/cont2"
+ )
+ ) )
+ );
+ $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
+ $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
+ $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
+ $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
+ $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
+ $this->file_lc = $this->repo_lc->newFile( 'test!' );
+ }
+
+ /**
+ * @covers File::getHashPath
+ */
+ public function testGetHashPath() {
+ $this->assertEquals( '', $this->file_hl0->getHashPath() );
+ $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
+ $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
+ }
+
+ /**
+ * @covers File::getRel
+ */
+ public function testGetRel() {
+ $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
+ $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
+ $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
+ }
+
+ /**
+ * @covers File::getUrlRel
+ */
+ public function testGetUrlRel() {
+ $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
+ $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
+ $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
+ }
+
+ /**
+ * @covers File::getArchivePath
+ */
+ public function testGetArchivePath() {
+ $this->assertEquals(
+ 'mwstore://local-backend/test-public/archive',
+ $this->file_hl0->getArchivePath()
+ );
+ $this->assertEquals(
+ 'mwstore://local-backend/test-public/archive/a/a2',
+ $this->file_hl2->getArchivePath()
+ );
+ $this->assertEquals(
+ 'mwstore://local-backend/test-public/archive/!',
+ $this->file_hl0->getArchivePath( '!' )
+ );
+ $this->assertEquals(
+ 'mwstore://local-backend/test-public/archive/a/a2/!',
+ $this->file_hl2->getArchivePath( '!' )
+ );
+ }
+
+ /**
+ * @covers File::getThumbPath
+ */
+ public function testGetThumbPath() {
+ $this->assertEquals(
+ 'mwstore://local-backend/test-thumb/Test!',
+ $this->file_hl0->getThumbPath()
+ );
+ $this->assertEquals(
+ 'mwstore://local-backend/test-thumb/a/a2/Test!',
+ $this->file_hl2->getThumbPath()
+ );
+ $this->assertEquals(
+ 'mwstore://local-backend/test-thumb/Test!/x',
+ $this->file_hl0->getThumbPath( 'x' )
+ );
+ $this->assertEquals(
+ 'mwstore://local-backend/test-thumb/a/a2/Test!/x',
+ $this->file_hl2->getThumbPath( 'x' )
+ );
+ }
+
+ /**
+ * @covers File::getArchiveUrl
+ */
+ public function testGetArchiveUrl() {
+ $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
+ $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
+ $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
+ $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
+ }
+
+ /**
+ * @covers File::getThumbUrl
+ */
+ public function testGetThumbUrl() {
+ $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
+ $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
+ }
+
+ /**
+ * @covers File::getArchiveVirtualUrl
+ */
+ public function testGetArchiveVirtualUrl() {
+ $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
+ $this->assertEquals(
+ 'mwrepo://test/public/archive/a/a2',
+ $this->file_hl2->getArchiveVirtualUrl()
+ );
+ $this->assertEquals(
+ 'mwrepo://test/public/archive/%21',
+ $this->file_hl0->getArchiveVirtualUrl( '!' )
+ );
+ $this->assertEquals(
+ 'mwrepo://test/public/archive/a/a2/%21',
+ $this->file_hl2->getArchiveVirtualUrl( '!' )
+ );
+ }
+
+ /**
+ * @covers File::getThumbVirtualUrl
+ */
+ public function testGetThumbVirtualUrl() {
+ $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
+ $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
+ $this->assertEquals(
+ 'mwrepo://test/thumb/Test%21/%21',
+ $this->file_hl0->getThumbVirtualUrl( '!' )
+ );
+ $this->assertEquals(
+ 'mwrepo://test/thumb/a/a2/Test%21/%21',
+ $this->file_hl2->getThumbVirtualUrl( '!' )
+ );
+ }
+
+ /**
+ * @covers File::getUrl
+ */
+ public function testGetUrl() {
+ $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
+ $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
+ }
+
+ /**
+ * @covers ::wfLocalFile
+ */
+ public function testWfLocalFile() {
+ $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
+ $this->assertThat(
+ $file,
+ $this->isInstanceOf( 'LocalFile' ),
+ 'wfLocalFile() returns LocalFile for valid Titles'
+ );
+ }
+}
--- /dev/null
+<?php
+/**
+ * Test class for ArrayUtils class
+ *
+ * @group Database
+ */
+
+class ArrayUtilsTest extends MediaWikiTestCase {
+ private $search;
+
+ /**
+ * @covers ArrayUtils::findLowerBound
+ * @dataProvider provideFindLowerBound
+ */
+ function testFindLowerBound(
+ $valueCallback, $valueCount, $comparisonCallback, $target, $expected
+ ) {
+ $this->assertSame(
+ ArrayUtils::findLowerBound(
+ $valueCallback, $valueCount, $comparisonCallback, $target
+ ), $expected
+ );
+ }
+
+ function provideFindLowerBound() {
+ $self = $this;
+ $indexValueCallback = function ( $size ) use ( $self ) {
+ return function ( $val ) use ( $self, $size ) {
+ $self->assertTrue( $val >= 0 );
+ $self->assertTrue( $val < $size );
+ return $val;
+ };
+ };
+ $comparisonCallback = function ( $a, $b ) {
+ return $a - $b;
+ };
+
+ return array(
+ array(
+ $indexValueCallback( 0 ),
+ 0,
+ $comparisonCallback,
+ 1,
+ false,
+ ),
+ array(
+ $indexValueCallback( 1 ),
+ 1,
+ $comparisonCallback,
+ -1,
+ false,
+ ),
+ array(
+ $indexValueCallback( 1 ),
+ 1,
+ $comparisonCallback,
+ 0,
+ 0,
+ ),
+ array(
+ $indexValueCallback( 1 ),
+ 1,
+ $comparisonCallback,
+ 1,
+ 0,
+ ),
+ array(
+ $indexValueCallback( 2 ),
+ 2,
+ $comparisonCallback,
+ -1,
+ false,
+ ),
+ array(
+ $indexValueCallback( 2 ),
+ 2,
+ $comparisonCallback,
+ 0,
+ 0,
+ ),
+ array(
+ $indexValueCallback( 2 ),
+ 2,
+ $comparisonCallback,
+ 0.5,
+ 0,
+ ),
+ array(
+ $indexValueCallback( 2 ),
+ 2,
+ $comparisonCallback,
+ 1,
+ 1,
+ ),
+ array(
+ $indexValueCallback( 2 ),
+ 2,
+ $comparisonCallback,
+ 1.5,
+ 1,
+ ),
+ array(
+ $indexValueCallback( 3 ),
+ 3,
+ $comparisonCallback,
+ 1,
+ 1,
+ ),
+ array(
+ $indexValueCallback( 3 ),
+ 3,
+ $comparisonCallback,
+ 1.5,
+ 1,
+ ),
+ array(
+ $indexValueCallback( 3 ),
+ 3,
+ $comparisonCallback,
+ 2,
+ 2,
+ ),
+ array(
+ $indexValueCallback( 3 ),
+ 3,
+ $comparisonCallback,
+ 3,
+ 2,
+ ),
+ );
+ }
+
+ /**
+ * @covers ArrayUtils::arrayDiffAssocRecursive
+ * @dataProvider provideArrayDiffAssocRecursive
+ */
+ function testArrayDiffAssocRecursive( $expected ) {
+ $args = func_get_args();
+ array_shift( $args );
+ $this->assertEquals( call_user_func_array(
+ 'ArrayUtils::arrayDiffAssocRecursive', $args
+ ), $expected );
+ }
+
+ function provideArrayDiffAssocRecursive() {
+ return array(
+ array(
+ array(),
+ array(),
+ array(),
+ ),
+ array(
+ array(),
+ array(),
+ array(),
+ array(),
+ ),
+ array(
+ array( 1 ),
+ array( 1 ),
+ array(),
+ ),
+ array(
+ array( 1 ),
+ array( 1 ),
+ array(),
+ array(),
+ ),
+ array(
+ array(),
+ array(),
+ array( 1 ),
+ ),
+ array(
+ array(),
+ array(),
+ array( 1 ),
+ array( 2 ),
+ ),
+ array(
+ array( '' => 1 ),
+ array( '' => 1 ),
+ array(),
+ ),
+ array(
+ array(),
+ array(),
+ array( '' => 1 ),
+ ),
+ array(
+ array( 1 ),
+ array( 1 ),
+ array( 2 ),
+ ),
+ array(
+ array(),
+ array( 1 ),
+ array( 2 ),
+ array( 1 ),
+ ),
+ array(
+ array(),
+ array( 1 ),
+ array( 1, 2 ),
+ ),
+ array(
+ array( 1 => 1 ),
+ array( 1 => 1 ),
+ array( 1 ),
+ ),
+ array(
+ array(),
+ array( 1 => 1 ),
+ array( 1 ),
+ array( 1 => 1),
+ ),
+ array(
+ array(),
+ array( 1 => 1 ),
+ array( 1, 1, 1 ),
+ ),
+ array(
+ array(),
+ array( array() ),
+ array(),
+ ),
+ array(
+ array(),
+ array( array( array() ) ),
+ array(),
+ ),
+ array(
+ array( 1, array( 1 ) ),
+ array( 1, array( 1 ) ),
+ array(),
+ ),
+ array(
+ array( 1 ),
+ array( 1, array( 1 ) ),
+ array( 2, array( 1 ) ),
+ ),
+ array(
+ array(),
+ array( 1, array( 1 ) ),
+ array( 2, array( 1 ) ),
+ array( 1, array( 2 ) ),
+ ),
+ array(
+ array( 1 ),
+ array( 1, array() ),
+ array( 2 ),
+ ),
+ array(
+ array(),
+ array( 1, array() ),
+ array( 2 ),
+ array( 1 ),
+ ),
+ array(
+ array( 1, array( 1 => 2 ) ),
+ array( 1, array( 1, 2 ) ),
+ array( 2, array( 1 ) ),
+ ),
+ array(
+ array( 1 ),
+ array( 1, array( 1, 2 ) ),
+ array( 2, array( 1 ) ),
+ array( 2, array( 1 => 2 ) ),
+ ),
+ array(
+ array( 1 => array( 1, 2 ) ),
+ array( 1, array( 1, 2 ) ),
+ array( 1, array( 2 ) ),
+ ),
+ array(
+ array( 1 => array( array( 2, 3 ), 2 ) ),
+ array( 1, array( array( 2, 3 ), 2 ) ),
+ array( 1, array( 2 ) ),
+ ),
+ array(
+ array( 1 => array( array( 2 ), 2 ) ),
+ array( 1, array( array( 2, 3 ), 2 ) ),
+ array( 1, array( array( 1 => 3 ) ) ),
+ ),
+ array(
+ array( 1 => array( 1 => 2 ) ),
+ array( 1, array( array( 2, 3 ), 2 ) ),
+ array( 1, array( array( 1 => 3, 0 => 2 ) ) ),
+ ),
+ array(
+ array( 1 => array( 1 => 2 ) ),
+ array( 1, array( array( 2, 3 ), 2 ) ),
+ array( 1, array( array( 1 => 3 ) ) ),
+ array( 1 => array( array( 2 ) ) ),
+ ),
+ array(
+ array(),
+ array( 1, array( array( 2, 3 ), 2 ) ),
+ array( 1 => array( 1 => 2, 0 => array( 1 => 3, 0 => 2 ) ), 0 => 1 ),
+ ),
+ array(
+ array(),
+ array( 1, array( array( 2, 3 ), 2 ) ),
+ array( 1 => array( 1 => 2 ) ),
+ array( 1 => array( array( 1 => 3 ) ) ),
+ array( 1 => array( array( 2 ) ) ),
+ array( 1 ),
+ ),
+ );
+ }
+}
--- /dev/null
+<?php
+/**
+ * PHPUnit tests for XMLTypeCheck.
+ * @author physikerwelt
+ * @group Xml
+ * @covers XMLTypeCheck
+ */
+class XmlTypeCheckTest extends MediaWikiTestCase {
+ const WELL_FORMED_XML = "<root><child /></root>";
+ const MAL_FORMED_XML = "<root><child /></error>";
+
+ /**
+ * @covers XMLTypeCheck::newFromString
+ * @covers XMLTypeCheck::getRootElement
+ */
+ public function testWellFormedXML() {
+ $testXML = XmlTypeCheck::newFromString( self::WELL_FORMED_XML );
+ $this->assertTrue( $testXML->wellFormed );
+ $this->assertEquals( 'root', $testXML->getRootElement() );
+ }
+
+ /**
+ * @covers XMLTypeCheck::newFromString
+ */
+ public function testMalFormedXML() {
+ $testXML = XmlTypeCheck::newFromString( self::MAL_FORMED_XML );
+ $this->assertFalse( $testXML->wellFormed );
+ }
+
+}
--- /dev/null
+<?php
+
+/**
+ * @group Database
+ */
+class ArticleTablesTest extends MediaWikiLangTestCase {
+ /**
+ * Make sure that bug 14404 doesn't strike again. We don't want
+ * templatelinks based on the user language when {{int:}} is used, only the
+ * content language.
+ *
+ * @covers Title::getTemplateLinksFrom
+ * @covers Title::getLinksFrom
+ */
+ public function testTemplatelinksUsesContentLanguage() {
+ $title = Title::newFromText( 'Bug 14404' );
+ $page = WikiPage::factory( $title );
+ $user = new User();
+ $user->mRights = array( 'createpage', 'edit', 'purge' );
+ $this->setMwGlobals( 'wgLanguageCode', 'es' );
+ $this->setMwGlobals( 'wgContLang', Language::factory( 'es' ) );
+ $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) );
+
+ $page->doEditContent(
+ new WikitextContent( '{{:{{int:history}}}}' ),
+ 'Test code for bug 14404',
+ 0,
+ false,
+ $user
+ );
+ $templates1 = $title->getTemplateLinksFrom();
+
+ $this->setMwGlobals( 'wgLang', Language::factory( 'de' ) );
+ $page = WikiPage::factory( $title ); // In order to force the re-rendering of the same wikitext
+
+ // We need an edit, a purge is not enough to regenerate the tables
+ $page->doEditContent(
+ new WikitextContent( '{{:{{int:history}}}}' ),
+ 'Test code for bug 14404',
+ EDIT_UPDATE,
+ false,
+ $user
+ );
+ $templates2 = $title->getTemplateLinksFrom();
+
+ /**
+ * @var Title[] $templates1
+ * @var Title[] $templates2
+ */
+ $this->assertEquals( $templates1, $templates2 );
+ $this->assertEquals( $templates1[0]->getFullText(), 'Historial' );
+ }
+}
--- /dev/null
+<?php
+
+class ArticleTest extends MediaWikiTestCase {
+
+ /**
+ * @var Title
+ */
+ private $title;
+ /**
+ * @var Article
+ */
+ private $article;
+
+ /** creates a title object and its article object */
+ protected function setUp() {
+ parent::setUp();
+ $this->title = Title::makeTitle( NS_MAIN, 'SomePage' );
+ $this->article = new Article( $this->title );
+ }
+
+ /** cleanup title object and its article object */
+ protected function tearDown() {
+ parent::tearDown();
+ $this->title = null;
+ $this->article = null;
+ }
+
+ /**
+ * @covers Article::__get
+ */
+ public function testImplementsGetMagic() {
+ $this->assertEquals( false, $this->article->mLatest, "Article __get magic" );
+ }
+
+ /**
+ * @depends testImplementsGetMagic
+ * @covers Article::__set
+ */
+ public function testImplementsSetMagic() {
+ $this->article->mLatest = 2;
+ $this->assertEquals( 2, $this->article->mLatest, "Article __set magic" );
+ }
+
+ /**
+ * @depends testImplementsSetMagic
+ * @covers Article::__call
+ */
+ public function testImplementsCallMagic() {
+ $this->article->mLatest = 33;
+ $this->article->mDataLoaded = true;
+ $this->assertEquals( 33, $this->article->getLatest(), "Article __call magic" );
+ }
+
+ /**
+ * @covers Article::__get
+ * @covers Article::__set
+ */
+ public function testGetOrSetOnNewProperty() {
+ $this->article->ext_someNewProperty = 12;
+ $this->assertEquals( 12, $this->article->ext_someNewProperty,
+ "Article get/set magic on new field" );
+
+ $this->article->ext_someNewProperty = -8;
+ $this->assertEquals( -8, $this->article->ext_someNewProperty,
+ "Article get/set magic on update to new field" );
+ }
+
+ /**
+ * Checks for the existence of the backwards compatibility static functions
+ * (forwarders to WikiPage class)
+ *
+ * @covers Article::selectFields
+ * @covers Article::onArticleCreate
+ * @covers Article::onArticleDelete
+ * @covers Article::onArticleEdit
+ * @covers Article::getAutosummary
+ */
+ public function testStaticFunctions() {
+ $this->hideDeprecated( 'Article::selectFields' );
+ $this->hideDeprecated( 'Article::getAutosummary' );
+ $this->hideDeprecated( 'WikiPage::getAutosummary' );
+ $this->hideDeprecated( 'CategoryPage::getAutosummary' ); // Inherited from Article
+
+ $this->assertEquals( WikiPage::selectFields(), Article::selectFields(),
+ "Article static functions" );
+ $this->assertEquals( true, is_callable( "Article::onArticleCreate" ),
+ "Article static functions" );
+ $this->assertEquals( true, is_callable( "Article::onArticleDelete" ),
+ "Article static functions" );
+ $this->assertEquals( true, is_callable( "ImagePage::onArticleEdit" ),
+ "Article static functions" );
+ $this->assertTrue( is_string( CategoryPage::getAutosummary( '', '', 0 ) ),
+ "Article static functions" );
+ }
+}
--- /dev/null
+<?php
+/**
+ * For doing Image Page tests that rely on 404 thumb handling
+ */
+class ImagePage404Test extends MediaWikiMediaTestCase {
+
+ protected function getRepoOptions() {
+ return parent::getRepoOptions() + array( 'transformVia404' => true );
+ }
+
+ function setUp() {
+ $this->setMwGlobals( 'wgImageLimits', array(
+ array( 320, 240 ),
+ array( 640, 480 ),
+ array( 800, 600 ),
+ array( 1024, 768 ),
+ array( 1280, 1024 )
+ ) );
+ parent::setUp();
+ }
+
+ function getImagePage( $filename ) {
+ $title = Title::makeTitleSafe( NS_FILE, $filename );
+ $file = $this->dataFile( $filename );
+ $iPage = new ImagePage( $title );
+ $iPage->setFile( $file );
+ return $iPage;
+ }
+
+ /**
+ * @dataProvider providerGetThumbSizes
+ * @param string $filename
+ * @param int $expectedNumberThumbs How many thumbnails to show
+ */
+ function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
+ $iPage = $this->getImagePage( $filename );
+ $reflection = new ReflectionClass( $iPage );
+ $reflMethod = $reflection->getMethod( 'getThumbSizes' );
+ $reflMethod->setAccessible( true );
+
+ $actual = $reflMethod->invoke( $iPage, 545, 700 );
+ $this->assertEquals( count( $actual ), $expectedNumberThumbs );
+ }
+
+ function providerGetThumbSizes() {
+ return array(
+ array( 'animated.gif', 6 ),
+ array( 'Toll_Texas_1.svg', 6 ),
+ array( '80x60-Greyscale.xcf', 6 ),
+ array( 'jpeg-comment-binary.jpg', 6 ),
+ );
+ }
+}
--- /dev/null
+<?php
+class ImagePageTest extends MediaWikiMediaTestCase {
+
+ function setUp() {
+ $this->setMwGlobals( 'wgImageLimits', array(
+ array( 320, 240 ),
+ array( 640, 480 ),
+ array( 800, 600 ),
+ array( 1024, 768 ),
+ array( 1280, 1024 )
+ ) );
+ parent::setUp();
+ }
+
+ function getImagePage( $filename ) {
+ $title = Title::makeTitleSafe( NS_FILE, $filename );
+ $file = $this->dataFile( $filename );
+ $iPage = new ImagePage( $title );
+ $iPage->setFile( $file );
+ return $iPage;
+ }
+
+ /**
+ * @dataProvider providerGetDisplayWidthHeight
+ * @param array $dim Array [maxWidth, maxHeight, width, height]
+ * @param array $expected Array [width, height] The width and height we expect to display at
+ */
+ function testGetDisplayWidthHeight( $dim, $expected ) {
+ $iPage = $this->getImagePage( 'animated.gif' );
+ $reflection = new ReflectionClass( $iPage );
+ $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
+ $reflMethod->setAccessible( true );
+
+ $actual = $reflMethod->invoke( $iPage, $dim[0], $dim[1], $dim[2], $dim[3] );
+ $this->assertEquals( $actual, $expected );
+ }
+
+ function providerGetDisplayWidthHeight() {
+ return array(
+ array(
+ array( 1024.0, 768.0, 600.0, 600.0 ),
+ array( 600.0, 600.0 )
+ ),
+ array(
+ array( 1024.0, 768.0, 1600.0, 600.0 ),
+ array( 1024.0, 384.0 )
+ ),
+ array(
+ array( 1024.0, 768.0, 1024.0, 768.0 ),
+ array( 1024.0, 768.0 )
+ ),
+ array(
+ array( 1024.0, 768.0, 800.0, 1000.0 ),
+ array( 614.0, 768.0 )
+ ),
+ array(
+ array( 1024.0, 768.0, 0, 1000 ),
+ array( 0, 0 )
+ ),
+ array(
+ array( 1024.0, 768.0, 2000, 0 ),
+ array( 0, 0 )
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider providerGetThumbSizes
+ * @param string $filename
+ * @param int $expectedNumberThumbs How many thumbnails to show
+ */
+ function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
+ $iPage = $this->getImagePage( $filename );
+ $reflection = new ReflectionClass( $iPage );
+ $reflMethod = $reflection->getMethod( 'getThumbSizes' );
+ $reflMethod->setAccessible( true );
+
+ $actual = $reflMethod->invoke( $iPage, 545, 700 );
+ $this->assertEquals( count( $actual ), $expectedNumberThumbs );
+ }
+
+ function providerGetThumbSizes() {
+ return array(
+ array( 'animated.gif', 2 ),
+ array( 'Toll_Texas_1.svg', 1 ),
+ array( '80x60-Greyscale.xcf', 1 ),
+ array( 'jpeg-comment-binary.jpg', 2 ),
+ );
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * @group ContentHandler
+ * @group Database
+ * ^--- important, causes temporary tables to be used instead of the real database
+ * @group medium
+ **/
+class WikiPageTest extends MediaWikiLangTestCase {
+
+ protected $pages_to_delete;
+
+ function __construct( $name = null, array $data = array(), $dataName = '' ) {
+ parent::__construct( $name, $data, $dataName );
+
+ $this->tablesUsed = array_merge(
+ $this->tablesUsed,
+ array( 'page',
+ 'revision',
+ 'text',
+
+ 'recentchanges',
+ 'logging',
+
+ 'page_props',
+ 'pagelinks',
+ 'categorylinks',
+ 'langlinks',
+ 'externallinks',
+ 'imagelinks',
+ 'templatelinks',
+ 'iwlinks' ) );
+ }
+
+ protected function setUp() {
+ parent::setUp();
+ $this->pages_to_delete = array();
+
+ LinkCache::singleton()->clear(); # avoid cached redirect status, etc
+ }
+
+ protected function tearDown() {
+ foreach ( $this->pages_to_delete as $p ) {
+ /* @var $p WikiPage */
+
+ try {
+ if ( $p->exists() ) {
+ $p->doDeleteArticle( "testing done." );
+ }
+ } catch ( MWException $ex ) {
+ // fail silently
+ }
+ }
+ parent::tearDown();
+ }
+
+ /**
+ * @param Title|string $title
+ * @param string|null $model
+ * @return WikiPage
+ */
+ protected function newPage( $title, $model = null ) {
+ if ( is_string( $title ) ) {
+ $ns = $this->getDefaultWikitextNS();
+ $title = Title::newFromText( $title, $ns );
+ }
+
+ $p = new WikiPage( $title );
+
+ $this->pages_to_delete[] = $p;
+
+ return $p;
+ }
+
+ /**
+ * @param string|Title|WikiPage $page
+ * @param string $text
+ * @param int $model
+ *
+ * @return WikiPage
+ */
+ protected function createPage( $page, $text, $model = null ) {
+ if ( is_string( $page ) || $page instanceof Title ) {
+ $page = $this->newPage( $page, $model );
+ }
+
+ $content = ContentHandler::makeContent( $text, $page->getTitle(), $model );
+ $page->doEditContent( $content, "testing", EDIT_NEW );
+
+ return $page;
+ }
+
+ /**
+ * @covers WikiPage::doEditContent
+ */
+ public function testDoEditContent() {
+ $page = $this->newPage( "WikiPageTest_testDoEditContent" );
+ $title = $page->getTitle();
+
+ $content = ContentHandler::makeContent(
+ "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
+ . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+ $title,
+ CONTENT_MODEL_WIKITEXT
+ );
+
+ $page->doEditContent( $content, "[[testing]] 1" );
+
+ $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
+ $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
+ $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
+ $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
+
+ $id = $page->getId();
+
+ # ------------------------
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+ $n = $res->numRows();
+ $res->free();
+
+ $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
+
+ # ------------------------
+ $page = new WikiPage( $title );
+
+ $retrieved = $page->getContent();
+ $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
+
+ # ------------------------
+ $content = ContentHandler::makeContent(
+ "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
+ . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.",
+ $title,
+ CONTENT_MODEL_WIKITEXT
+ );
+
+ $page->doEditContent( $content, "testing 2" );
+
+ # ------------------------
+ $page = new WikiPage( $title );
+
+ $retrieved = $page->getContent();
+ $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
+
+ # ------------------------
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+ $n = $res->numRows();
+ $res->free();
+
+ $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
+ }
+
+ /**
+ * @covers WikiPage::doEdit
+ */
+ public function testDoEdit() {
+ $this->hideDeprecated( "WikiPage::doEdit" );
+ $this->hideDeprecated( "WikiPage::getText" );
+ $this->hideDeprecated( "Revision::getText" );
+
+ //NOTE: assume help namespace will default to wikitext
+ $title = Title::newFromText( "Help:WikiPageTest_testDoEdit" );
+
+ $page = $this->newPage( $title );
+
+ $text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
+ . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
+
+ $page->doEdit( $text, "[[testing]] 1" );
+
+ $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
+ $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
+ $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
+ $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
+
+ $id = $page->getId();
+
+ # ------------------------
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+ $n = $res->numRows();
+ $res->free();
+
+ $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
+
+ # ------------------------
+ $page = new WikiPage( $title );
+
+ $retrieved = $page->getText();
+ $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );
+
+ # ------------------------
+ $text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
+ . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.";
+
+ $page->doEdit( $text, "testing 2" );
+
+ # ------------------------
+ $page = new WikiPage( $title );
+
+ $retrieved = $page->getText();
+ $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );
+
+ # ------------------------
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+ $n = $res->numRows();
+ $res->free();
+
+ $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
+ }
+
+ /**
+ * @covers WikiPage::doQuickEdit
+ */
+ public function testDoQuickEdit() {
+ global $wgUser;
+
+ $this->hideDeprecated( "WikiPage::doQuickEdit" );
+
+ //NOTE: assume help namespace will default to wikitext
+ $page = $this->createPage( "Help:WikiPageTest_testDoQuickEdit", "original text" );
+
+ $text = "quick text";
+ $page->doQuickEdit( $text, $wgUser, "testing q" );
+
+ # ---------------------
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertEquals( $text, $page->getText() );
+ }
+
+ /**
+ * @covers WikiPage::doQuickEditContent
+ */
+ public function testDoQuickEditContent() {
+ global $wgUser;
+
+ $page = $this->createPage(
+ "WikiPageTest_testDoQuickEditContent",
+ "original text",
+ CONTENT_MODEL_WIKITEXT
+ );
+
+ $content = ContentHandler::makeContent(
+ "quick text",
+ $page->getTitle(),
+ CONTENT_MODEL_WIKITEXT
+ );
+ $page->doQuickEditContent( $content, $wgUser, "testing q" );
+
+ # ---------------------
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertTrue( $content->equals( $page->getContent() ) );
+ }
+
+ /**
+ * @covers WikiPage::doDeleteArticle
+ */
+ public function testDoDeleteArticle() {
+ $page = $this->createPage(
+ "WikiPageTest_testDoDeleteArticle",
+ "[[original text]] foo",
+ CONTENT_MODEL_WIKITEXT
+ );
+ $id = $page->getId();
+
+ $page->doDeleteArticle( "testing deletion" );
+
+ $this->assertFalse(
+ $page->getTitle()->getArticleID() > 0,
+ "Title object should now have page id 0"
+ );
+ $this->assertFalse( $page->getId() > 0, "WikiPage should now have page id 0" );
+ $this->assertFalse(
+ $page->exists(),
+ "WikiPage::exists should return false after page was deleted"
+ );
+ $this->assertNull(
+ $page->getContent(),
+ "WikiPage::getContent should return null after page was deleted"
+ );
+ $this->assertFalse(
+ $page->getText(),
+ "WikiPage::getText should return false after page was deleted"
+ );
+
+ $t = Title::newFromText( $page->getTitle()->getPrefixedText() );
+ $this->assertFalse(
+ $t->exists(),
+ "Title::exists should return false after page was deleted"
+ );
+
+ # ------------------------
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+ $n = $res->numRows();
+ $res->free();
+
+ $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
+ }
+
+ /**
+ * @covers WikiPage::doDeleteUpdates
+ */
+ public function testDoDeleteUpdates() {
+ $page = $this->createPage(
+ "WikiPageTest_testDoDeleteArticle",
+ "[[original text]] foo",
+ CONTENT_MODEL_WIKITEXT
+ );
+ $id = $page->getId();
+
+ $page->doDeleteUpdates( $id );
+
+ # ------------------------
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+ $n = $res->numRows();
+ $res->free();
+
+ $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
+ }
+
+ /**
+ * @covers WikiPage::getRevision
+ */
+ public function testGetRevision() {
+ $page = $this->newPage( "WikiPageTest_testGetRevision" );
+
+ $rev = $page->getRevision();
+ $this->assertNull( $rev );
+
+ # -----------------
+ $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
+
+ $rev = $page->getRevision();
+
+ $this->assertEquals( $page->getLatest(), $rev->getId() );
+ $this->assertEquals( "some text", $rev->getContent()->getNativeData() );
+ }
+
+ /**
+ * @covers WikiPage::getContent
+ */
+ public function testGetContent() {
+ $page = $this->newPage( "WikiPageTest_testGetContent" );
+
+ $content = $page->getContent();
+ $this->assertNull( $content );
+
+ # -----------------
+ $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
+
+ $content = $page->getContent();
+ $this->assertEquals( "some text", $content->getNativeData() );
+ }
+
+ /**
+ * @covers WikiPage::getText
+ */
+ public function testGetText() {
+ $this->hideDeprecated( "WikiPage::getText" );
+
+ $page = $this->newPage( "WikiPageTest_testGetText" );
+
+ $text = $page->getText();
+ $this->assertFalse( $text );
+
+ # -----------------
+ $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
+
+ $text = $page->getText();
+ $this->assertEquals( "some text", $text );
+ }
+
+ /**
+ * @covers WikiPage::getRawText
+ */
+ public function testGetRawText() {
+ $this->hideDeprecated( "WikiPage::getRawText" );
+
+ $page = $this->newPage( "WikiPageTest_testGetRawText" );
+
+ $text = $page->getRawText();
+ $this->assertFalse( $text );
+
+ # -----------------
+ $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
+
+ $text = $page->getRawText();
+ $this->assertEquals( "some text", $text );
+ }
+
+ /**
+ * @covers WikiPage::getContentModel
+ */
+ public function testGetContentModel() {
+ global $wgContentHandlerUseDB;
+
+ if ( !$wgContentHandlerUseDB ) {
+ $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
+ }
+
+ $page = $this->createPage(
+ "WikiPageTest_testGetContentModel",
+ "some text",
+ CONTENT_MODEL_JAVASCRIPT
+ );
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $page->getContentModel() );
+ }
+
+ /**
+ * @covers WikiPage::getContentHandler
+ */
+ public function testGetContentHandler() {
+ global $wgContentHandlerUseDB;
+
+ if ( !$wgContentHandlerUseDB ) {
+ $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
+ }
+
+ $page = $this->createPage(
+ "WikiPageTest_testGetContentHandler",
+ "some text",
+ CONTENT_MODEL_JAVASCRIPT
+ );
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertEquals( 'JavaScriptContentHandler', get_class( $page->getContentHandler() ) );
+ }
+
+ /**
+ * @covers WikiPage::exists
+ */
+ public function testExists() {
+ $page = $this->newPage( "WikiPageTest_testExists" );
+ $this->assertFalse( $page->exists() );
+
+ # -----------------
+ $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
+ $this->assertTrue( $page->exists() );
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertTrue( $page->exists() );
+
+ # -----------------
+ $page->doDeleteArticle( "done testing" );
+ $this->assertFalse( $page->exists() );
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertFalse( $page->exists() );
+ }
+
+ public static function provideHasViewableContent() {
+ return array(
+ array( 'WikiPageTest_testHasViewableContent', false, true ),
+ array( 'Special:WikiPageTest_testHasViewableContent', false ),
+ array( 'MediaWiki:WikiPageTest_testHasViewableContent', false ),
+ array( 'Special:Userlogin', true ),
+ array( 'MediaWiki:help', true ),
+ );
+ }
+
+ /**
+ * @dataProvider provideHasViewableContent
+ * @covers WikiPage::hasViewableContent
+ */
+ public function testHasViewableContent( $title, $viewable, $create = false ) {
+ $page = $this->newPage( $title );
+ $this->assertEquals( $viewable, $page->hasViewableContent() );
+
+ if ( $create ) {
+ $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
+ $this->assertTrue( $page->hasViewableContent() );
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertTrue( $page->hasViewableContent() );
+ }
+ }
+
+ public static function provideGetRedirectTarget() {
+ return array(
+ array( 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT, "hello world", null ),
+ array(
+ 'WikiPageTest_testGetRedirectTarget_2',
+ CONTENT_MODEL_WIKITEXT,
+ "#REDIRECT [[hello world]]",
+ "Hello world"
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetRedirectTarget
+ * @covers WikiPage::getRedirectTarget
+ */
+ public function testGetRedirectTarget( $title, $model, $text, $target ) {
+ $this->setMwGlobals( array(
+ 'wgCapitalLinks' => true,
+ ) );
+
+ $page = $this->createPage( $title, $text, $model );
+
+ # sanity check, because this test seems to fail for no reason for some people.
+ $c = $page->getContent();
+ $this->assertEquals( 'WikitextContent', get_class( $c ) );
+
+ # now, test the actual redirect
+ $t = $page->getRedirectTarget();
+ $this->assertEquals( $target, is_null( $t ) ? null : $t->getPrefixedText() );
+ }
+
+ /**
+ * @dataProvider provideGetRedirectTarget
+ * @covers WikiPage::isRedirect
+ */
+ public function testIsRedirect( $title, $model, $text, $target ) {
+ $page = $this->createPage( $title, $text, $model );
+ $this->assertEquals( !is_null( $target ), $page->isRedirect() );
+ }
+
+ public static function provideIsCountable() {
+ return array(
+
+ // any
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ '',
+ 'any',
+ true
+ ),
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'any',
+ true
+ ),
+
+ // comma
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'comma',
+ false
+ ),
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo, bar',
+ 'comma',
+ true
+ ),
+
+ // link
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'link',
+ false
+ ),
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo [[bar]]',
+ 'link',
+ true
+ ),
+
+ // redirects
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ '#REDIRECT [[bar]]',
+ 'any',
+ false
+ ),
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ '#REDIRECT [[bar]]',
+ 'comma',
+ false
+ ),
+ array( 'WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ '#REDIRECT [[bar]]',
+ 'link',
+ false
+ ),
+
+ // not a content namespace
+ array( 'Talk:WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo',
+ 'any',
+ false
+ ),
+ array( 'Talk:WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo, bar',
+ 'comma',
+ false
+ ),
+ array( 'Talk:WikiPageTest_testIsCountable',
+ CONTENT_MODEL_WIKITEXT,
+ 'Foo [[bar]]',
+ 'link',
+ false
+ ),
+
+ // not a content namespace, different model
+ array( 'MediaWiki:WikiPageTest_testIsCountable.js',
+ null,
+ 'Foo',
+ 'any',
+ false
+ ),
+ array( 'MediaWiki:WikiPageTest_testIsCountable.js',
+ null,
+ 'Foo, bar',
+ 'comma',
+ false
+ ),
+ array( 'MediaWiki:WikiPageTest_testIsCountable.js',
+ null,
+ 'Foo [[bar]]',
+ 'link',
+ false
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideIsCountable
+ * @covers WikiPage::isCountable
+ */
+ public function testIsCountable( $title, $model, $text, $mode, $expected ) {
+ global $wgContentHandlerUseDB;
+
+ $this->setMwGlobals( 'wgArticleCountMethod', $mode );
+
+ $title = Title::newFromText( $title );
+
+ if ( !$wgContentHandlerUseDB
+ && $model
+ && ContentHandler::getDefaultModelFor( $title ) != $model
+ ) {
+ $this->markTestSkipped( "Can not use non-default content model $model for "
+ . $title->getPrefixedDBkey() . " with \$wgContentHandlerUseDB disabled." );
+ }
+
+ $page = $this->createPage( $title, $text, $model );
+
+ $editInfo = $page->prepareContentForEdit( $page->getContent() );
+
+ $v = $page->isCountable();
+ $w = $page->isCountable( $editInfo );
+
+ $this->assertEquals(
+ $expected,
+ $v,
+ "isCountable( null ) returned unexpected value " . var_export( $v, true )
+ . " instead of " . var_export( $expected, true )
+ . " in mode `$mode` for text \"$text\""
+ );
+
+ $this->assertEquals(
+ $expected,
+ $w,
+ "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
+ . " instead of " . var_export( $expected, true )
+ . " in mode `$mode` for text \"$text\""
+ );
+ }
+
+ public static function provideGetParserOutput() {
+ return array(
+ array( CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i></p>" ),
+ // @todo more...?
+ );
+ }
+
+ /**
+ * @dataProvider provideGetParserOutput
+ * @covers WikiPage::getParserOutput
+ */
+ public function testGetParserOutput( $model, $text, $expectedHtml ) {
+ $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model );
+
+ $opt = $page->makeParserOptions( 'canonical' );
+ $po = $page->getParserOutput( $opt );
+ $text = $po->getText();
+
+ $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
+ $text = preg_replace( '!\s*(</p>)!sm', '\1', $text ); # don't let tidy confuse us
+
+ $this->assertEquals( $expectedHtml, $text );
+
+ return $po;
+ }
+
+ /**
+ * @covers WikiPage::getParserOutput
+ */
+ public function testGetParserOutput_nonexisting() {
+ static $count = 0;
+ $count++;
+
+ $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
+
+ $opt = new ParserOptions();
+ $po = $page->getParserOutput( $opt );
+
+ $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
+ }
+
+ /**
+ * @covers WikiPage::getParserOutput
+ */
+ public function testGetParserOutput_badrev() {
+ $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT );
+
+ $opt = new ParserOptions();
+ $po = $page->getParserOutput( $opt, $page->getLatest() + 1234 );
+
+ // @todo would be neat to also test deleted revision
+
+ $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
+ }
+
+ public static $sections =
+
+ "Intro
+
+== stuff ==
+hello world
+
+== test ==
+just a test
+
+== foo ==
+more stuff
+";
+
+ public function dataReplaceSection() {
+ //NOTE: assume the Help namespace to contain wikitext
+ return array(
+ array( 'Help:WikiPageTest_testReplaceSection',
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "0",
+ "No more",
+ null,
+ trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest::$sections ) )
+ ),
+ array( 'Help:WikiPageTest_testReplaceSection',
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "",
+ "No more",
+ null,
+ "No more"
+ ),
+ array( 'Help:WikiPageTest_testReplaceSection',
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "2",
+ "== TEST ==\nmore fun",
+ null,
+ trim( preg_replace( '/^== test ==.*== foo ==/sm',
+ "== TEST ==\nmore fun\n\n== foo ==",
+ WikiPageTest::$sections ) )
+ ),
+ array( 'Help:WikiPageTest_testReplaceSection',
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "8",
+ "No more",
+ null,
+ trim( WikiPageTest::$sections )
+ ),
+ array( 'Help:WikiPageTest_testReplaceSection',
+ CONTENT_MODEL_WIKITEXT,
+ WikiPageTest::$sections,
+ "new",
+ "No more",
+ "New",
+ trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more"
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider dataReplaceSection
+ * @covers WikiPage::replaceSection
+ */
+ public function testReplaceSection( $title, $model, $text, $section, $with,
+ $sectionTitle, $expected
+ ) {
+ $this->hideDeprecated( "WikiPage::replaceSection" );
+
+ $page = $this->createPage( $title, $text, $model );
+ $text = $page->replaceSection( $section, $with, $sectionTitle );
+ $text = trim( $text );
+
+ $this->assertEquals( $expected, $text );
+ }
+
+ /**
+ * @dataProvider dataReplaceSection
+ * @covers WikiPage::replaceSectionContent
+ */
+ public function testReplaceSectionContent( $title, $model, $text, $section,
+ $with, $sectionTitle, $expected
+ ) {
+ $page = $this->createPage( $title, $text, $model );
+
+ $content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
+ $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
+
+ $this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
+ }
+
+ /**
+ * @dataProvider dataReplaceSection
+ * @covers WikiPage::replaceSectionAtRev
+ */
+ public function testReplaceSectionAtRev( $title, $model, $text, $section,
+ $with, $sectionTitle, $expected
+ ) {
+ $page = $this->createPage( $title, $text, $model );
+ $baseRevId = $page->getLatest();
+
+ $content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
+ $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
+
+ $this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
+ }
+
+ /* @todo FIXME: fix this!
+ public function testGetUndoText() {
+ $this->checkHasDiff3();
+
+ $text = "one";
+ $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
+ $rev1 = $page->getRevision();
+
+ $text .= "\n\ntwo";
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle() ),
+ "adding section two"
+ );
+ $rev2 = $page->getRevision();
+
+ $text .= "\n\nthree";
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle() ),
+ "adding section three"
+ );
+ $rev3 = $page->getRevision();
+
+ $text .= "\n\nfour";
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle() ),
+ "adding section four"
+ );
+ $rev4 = $page->getRevision();
+
+ $text .= "\n\nfive";
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle() ),
+ "adding section five"
+ );
+ $rev5 = $page->getRevision();
+
+ $text .= "\n\nsix";
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle() ),
+ "adding section six"
+ );
+ $rev6 = $page->getRevision();
+
+ $undo6 = $page->getUndoText( $rev6 );
+ if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
+ $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
+
+ $undo3 = $page->getUndoText( $rev4, $rev2 );
+ if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
+ $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
+
+ $undo2 = $page->getUndoText( $rev2 );
+ if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
+ $this->assertEquals( "one\n\nfive", $undo2 );
+ }
+ */
+
+ /**
+ * @todo FIXME: this is a better rollback test than the one below, but it
+ * keeps failing in jenkins for some reason.
+ */
+ public function broken_testDoRollback() {
+ $admin = new User();
+ $admin->setName( "Admin" );
+
+ $text = "one";
+ $page = $this->newPage( "WikiPageTest_testDoRollback" );
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
+ "section one", EDIT_NEW, false, $admin );
+
+ $user1 = new User();
+ $user1->setName( "127.0.1.11" );
+ $text .= "\n\ntwo";
+ $page = new WikiPage( $page->getTitle() );
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
+ "adding section two", 0, false, $user1 );
+
+ $user2 = new User();
+ $user2->setName( "127.0.2.13" );
+ $text .= "\n\nthree";
+ $page = new WikiPage( $page->getTitle() );
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
+ "adding section three", 0, false, $user2 );
+
+ # we are having issues with doRollback spuriously failing. Apparently
+ # the last revision somehow goes missing or not committed under some
+ # circumstances. So, make sure the last revision has the right user name.
+ $dbr = wfGetDB( DB_SLAVE );
+ $this->assertEquals( 3, Revision::countByPageId( $dbr, $page->getId() ) );
+
+ $page = new WikiPage( $page->getTitle() );
+ $rev3 = $page->getRevision();
+ $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
+
+ $rev2 = $rev3->getPrevious();
+ $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
+
+ $rev1 = $rev2->getPrevious();
+ $this->assertEquals( 'Admin', $rev1->getUserText() );
+
+ # now, try the actual rollback
+ $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
+ $token = $admin->getEditToken(
+ array( $page->getTitle()->getPrefixedText(), $user2->getName() ),
+ null
+ );
+ $errors = $page->doRollback(
+ $user2->getName(),
+ "testing revert",
+ $token,
+ false,
+ $details,
+ $admin
+ );
+
+ if ( $errors ) {
+ $this->fail( "Rollback failed:\n" . print_r( $errors, true )
+ . ";\n" . print_r( $details, true ) );
+ }
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
+ "rollback did not revert to the correct revision" );
+ $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
+ }
+
+ /**
+ * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
+ * @covers WikiPage::doRollback
+ */
+ public function testDoRollback() {
+ $admin = new User();
+ $admin->setName( "Admin" );
+
+ $text = "one";
+ $page = $this->newPage( "WikiPageTest_testDoRollback" );
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ "section one",
+ EDIT_NEW,
+ false,
+ $admin
+ );
+ $rev1 = $page->getRevision();
+
+ $user1 = new User();
+ $user1->setName( "127.0.1.11" );
+ $text .= "\n\ntwo";
+ $page = new WikiPage( $page->getTitle() );
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ "adding section two",
+ 0,
+ false,
+ $user1
+ );
+
+ # now, try the rollback
+ $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
+ $token = $admin->getEditToken(
+ array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
+ null
+ );
+ $errors = $page->doRollback(
+ $user1->getName(),
+ "testing revert",
+ $token,
+ false,
+ $details,
+ $admin
+ );
+
+ if ( $errors ) {
+ $this->fail( "Rollback failed:\n" . print_r( $errors, true )
+ . ";\n" . print_r( $details, true ) );
+ }
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
+ "rollback did not revert to the correct revision" );
+ $this->assertEquals( "one", $page->getContent()->getNativeData() );
+ }
+
+ /**
+ * @covers WikiPage::doRollback
+ */
+ public function testDoRollbackFailureSameContent() {
+ $admin = new User();
+ $admin->setName( "Admin" );
+ $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
+
+ $text = "one";
+ $page = $this->newPage( "WikiPageTest_testDoRollback" );
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ "section one",
+ EDIT_NEW,
+ false,
+ $admin
+ );
+ $rev1 = $page->getRevision();
+
+ $user1 = new User();
+ $user1->setName( "127.0.1.11" );
+ $user1->addGroup( "sysop" ); #XXX: make the test user a sysop...
+ $text .= "\n\ntwo";
+ $page = new WikiPage( $page->getTitle() );
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ "adding section two",
+ 0,
+ false,
+ $user1
+ );
+
+ # now, do a the rollback from the same user was doing the edit before
+ $resultDetails = array();
+ $token = $user1->getEditToken(
+ array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
+ null
+ );
+ $errors = $page->doRollback(
+ $user1->getName(),
+ "testing revert same user",
+ $token,
+ false,
+ $resultDetails,
+ $admin
+ );
+
+ $this->assertEquals( array(), $errors, "Rollback failed same user" );
+
+ # now, try the rollback
+ $resultDetails = array();
+ $token = $admin->getEditToken(
+ array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
+ null
+ );
+ $errors = $page->doRollback(
+ $user1->getName(),
+ "testing revert",
+ $token,
+ false,
+ $resultDetails,
+ $admin
+ );
+
+ $this->assertEquals( array( array( 'alreadyrolled', 'WikiPageTest testDoRollback',
+ '127.0.1.11', 'Admin' ) ), $errors, "Rollback not failed" );
+
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
+ "rollback did not revert to the correct revision" );
+ $this->assertEquals( "one", $page->getContent()->getNativeData() );
+ }
+
+ public static function provideGetAutosummary() {
+ return array(
+ array(
+ 'Hello there, world!',
+ '#REDIRECT [[Foo]]',
+ 0,
+ '/^Redirected page .*Foo/'
+ ),
+
+ array(
+ null,
+ 'Hello world!',
+ EDIT_NEW,
+ '/^Created page .*Hello/'
+ ),
+
+ array(
+ 'Hello there, world!',
+ '',
+ 0,
+ '/^Blanked/'
+ ),
+
+ array(
+ 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
+ eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
+ voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
+ clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
+ 'Hello world!',
+ 0,
+ '/^Replaced .*Hello/'
+ ),
+
+ array(
+ 'foo',
+ 'bar',
+ 0,
+ '/^$/'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetAutoSummary
+ * @covers WikiPage::getAutosummary
+ */
+ public function testGetAutosummary( $old, $new, $flags, $expected ) {
+ $this->hideDeprecated( "WikiPage::getAutosummary" );
+
+ $page = $this->newPage( "WikiPageTest_testGetAutosummary" );
+
+ $summary = $page->getAutosummary( $old, $new, $flags );
+
+ $this->assertTrue( (bool)preg_match( $expected, $summary ),
+ "Autosummary didn't match expected pattern $expected: $summary" );
+ }
+
+ public static function provideGetAutoDeleteReason() {
+ return array(
+ array(
+ array(),
+ false,
+ false
+ ),
+
+ array(
+ array(
+ array( "first edit", null ),
+ ),
+ "/first edit.*only contributor/",
+ false
+ ),
+
+ array(
+ array(
+ array( "first edit", null ),
+ array( "second edit", null ),
+ ),
+ "/second edit.*only contributor/",
+ true
+ ),
+
+ array(
+ array(
+ array( "first edit", "127.0.2.22" ),
+ array( "second edit", "127.0.3.33" ),
+ ),
+ "/second edit/",
+ true
+ ),
+
+ array(
+ array(
+ array(
+ "first edit: "
+ . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
+ . " nonumy eirmod tempor invidunt ut labore et dolore magna "
+ . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
+ . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
+ . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
+ null
+ ),
+ ),
+ '/first edit:.*\.\.\."/',
+ false
+ ),
+
+ array(
+ array(
+ array( "first edit", "127.0.2.22" ),
+ array( "", "127.0.3.33" ),
+ ),
+ "/before blanking.*first edit/",
+ true
+ ),
+
+ );
+ }
+
+ /**
+ * @dataProvider provideGetAutoDeleteReason
+ * @covers WikiPage::getAutoDeleteReason
+ */
+ public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
+ global $wgUser;
+
+ //NOTE: assume Help namespace to contain wikitext
+ $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
+
+ $c = 1;
+
+ foreach ( $edits as $edit ) {
+ $user = new User();
+
+ if ( !empty( $edit[1] ) ) {
+ $user->setName( $edit[1] );
+ } else {
+ $user = $wgUser;
+ }
+
+ $content = ContentHandler::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
+
+ $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW : 0, false, $user );
+
+ $c += 1;
+ }
+
+ $reason = $page->getAutoDeleteReason( $hasHistory );
+
+ if ( is_bool( $expectedResult ) || is_null( $expectedResult ) ) {
+ $this->assertEquals( $expectedResult, $reason );
+ } else {
+ $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
+ "Autosummary didn't match expected pattern $expectedResult: $reason" );
+ }
+
+ $this->assertEquals( $expectedHistory, $hasHistory,
+ "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
+
+ $page->doDeleteArticle( "done" );
+ }
+
+ public static function providePreSaveTransform() {
+ return array(
+ array( 'hello this is ~~~',
+ "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
+ ),
+ array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider providePreSaveTransform
+ * @covers WikiPage::preSaveTransform
+ */
+ public function testPreSaveTransform( $text, $expected ) {
+ $this->hideDeprecated( 'WikiPage::preSaveTransform' );
+ $user = new User();
+ $user->setName( "127.0.0.1" );
+
+ //NOTE: assume Help namespace to contain wikitext
+ $page = $this->newPage( "Help:WikiPageTest_testPreloadTransform" );
+ $text = $page->preSaveTransform( $text, $user );
+
+ $this->assertEquals( $expected, $text );
+ }
+
+ /**
+ * @covers WikiPage::factory
+ */
+ public function testWikiPageFactory() {
+ $title = Title::makeTitle( NS_FILE, 'Someimage.png' );
+ $page = WikiPage::factory( $title );
+ $this->assertEquals( 'WikiFilePage', get_class( $page ) );
+
+ $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
+ $page = WikiPage::factory( $title );
+ $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
+
+ $title = Title::makeTitle( NS_MAIN, 'SomePage' );
+ $page = WikiPage::factory( $title );
+ $this->assertEquals( 'WikiPage', get_class( $page ) );
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * @group ContentHandler
+ * @group Database
+ * ^--- important, causes temporary tables to be used instead of the real database
+ */
+class WikiPageTestContentHandlerUseDB extends WikiPageTest {
+
+ protected function setUp() {
+ parent::setUp();
+ $this->setMwGlobals( 'wgContentHandlerUseDB', false );
+
+ $dbw = wfGetDB( DB_MASTER );
+
+ $page_table = $dbw->tableName( 'page' );
+ $revision_table = $dbw->tableName( 'revision' );
+ $archive_table = $dbw->tableName( 'archive' );
+
+ if ( $dbw->fieldExists( $page_table, 'page_content_model' ) ) {
+ $dbw->query( "alter table $page_table drop column page_content_model" );
+ $dbw->query( "alter table $revision_table drop column rev_content_model" );
+ $dbw->query( "alter table $revision_table drop column rev_content_format" );
+ $dbw->query( "alter table $archive_table drop column ar_content_model" );
+ $dbw->query( "alter table $archive_table drop column ar_content_format" );
+ }
+ }
+
+ /**
+ * @covers WikiPage::getContentModel
+ */
+ public function testGetContentModel() {
+ $page = $this->createPage(
+ "WikiPageTest_testGetContentModel",
+ "some text",
+ CONTENT_MODEL_JAVASCRIPT
+ );
+
+ $page = new WikiPage( $page->getTitle() );
+
+ // NOTE: since the content model is not recorded in the database,
+ // we expect to get the default, namely CONTENT_MODEL_WIKITEXT
+ $this->assertEquals( CONTENT_MODEL_WIKITEXT, $page->getContentModel() );
+ }
+
+ /**
+ * @covers WikiPage::getContentHandler
+ */
+ public function testGetContentHandler() {
+ $page = $this->createPage(
+ "WikiPageTest_testGetContentHandler",
+ "some text",
+ CONTENT_MODEL_JAVASCRIPT
+ );
+
+ // NOTE: since the content model is not recorded in the database,
+ // we expect to get the default, namely CONTENT_MODEL_WIKITEXT
+ $page = new WikiPage( $page->getTitle() );
+ $this->assertEquals( 'WikitextContentHandler', get_class( $page->getContentHandler() ) );
+ }
+}
--- /dev/null
+<?php
+/**
+ * Testing framework for the Password infrastructure
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+class PasswordTest extends MediaWikiTestCase {
+ /**
+ * @covers InvalidPassword::equals
+ */
+ public function testInvalidUnequalInvalid() {
+ $invalid1 = User::getPasswordFactory()->newFromCiphertext( null );
+ $invalid2 = User::getPasswordFactory()->newFromCiphertext( null );
+
+ $this->assertFalse( $invalid1->equals( $invalid2 ) );
+ }
+
+ public function testInvalidPlaintext() {
+ $invalid = User::getPasswordFactory()->newFromPlaintext( null );
+
+ $this->assertInstanceOf( 'InvalidPassword', $invalid );
+ }
+}
+++ /dev/null
-<?php
-
-class MockSearch extends SearchEngine {
- public static $id;
- public static $title;
- public static $text;
-
- public function __construct( $db ) {
- }
-
- public function update( $id, $title, $text ) {
- self::$id = $id;
- self::$title = $title;
- self::$text = $text;
- }
-}
-
-/**
- * @group Search
- * @group Database
- */
-class SearchUpdateTest extends MediaWikiTestCase {
-
- protected function setUp() {
- parent::setUp();
- $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
- }
-
- public function updateText( $text ) {
- return trim( SearchUpdate::updateText( $text ) );
- }
-
- /**
- * @covers SearchUpdate::updateText
- */
- public function testUpdateText() {
- $this->assertEquals(
- 'test',
- $this->updateText( '<div>TeSt</div>' ),
- 'HTML stripped, text lowercased'
- );
-
- $this->assertEquals(
- 'foo bar boz quux',
- $this->updateText( <<<EOT
-<table style="color:red; font-size:100px">
- <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
- <tr><td>boz</td><tr>quux</td></tr>
-</table>
-EOT
- ), 'Stripping HTML tables' );
-
- $this->assertEquals(
- 'a b',
- $this->updateText( 'a > b' ),
- 'Handle unclosed tags'
- );
-
- $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
-
- $this->assertNotEquals(
- '',
- $this->updateText( $text ),
- 'Bug 18609'
- );
- }
-
- /**
- * @covers SearchUpdate::updateText
- * @todo give this test a real name explaining what is being tested here
- */
- public function testBug32712() {
- $text = "text „http://example.com“ text";
- $result = $this->updateText( $text );
- $processed = preg_replace( '/Q/u', 'Q', $result );
- $this->assertTrue(
- $processed != '',
- 'Link surrounded by unicode quotes should not fail UTF-8 validation'
- );
- }
-}
--- /dev/null
+<?php
+
+/**
+ * @covers SpecialPage
+ *
+ * @group Database
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < aude.wiki@gmail.com >
+ */
+class SpecialPageTest extends MediaWikiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( array(
+ 'wgScript' => '/index.php',
+ 'wgContLang' => Language::factory( 'en' )
+ ) );
+ }
+
+ /**
+ * @dataProvider getTitleForProvider
+ */
+ public function testGetTitleFor( $expectedName, $name ) {
+ $title = SpecialPage::getTitleFor( $name );
+ $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
+ $this->assertEquals( $expected, $title );
+ }
+
+ public function getTitleForProvider() {
+ return array(
+ array( 'UserLogin', 'Userlogin' )
+ );
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error_Notice
+ */
+ public function testInvalidGetTitleFor() {
+ $title = SpecialPage::getTitleFor( 'cat' );
+ $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
+ $this->assertEquals( $expected, $title );
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error_Notice
+ * @dataProvider getTitleForWithWarningProvider
+ */
+ public function testGetTitleForWithWarning( $expected, $name ) {
+ $title = SpecialPage::getTitleFor( $name );
+ $this->assertEquals( $expected, $title );
+ }
+
+ public function getTitleForWithWarningProvider() {
+ return array(
+ array( Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' )
+ );
+ }
+
+ /**
+ * @dataProvider requireLoginAnonProvider
+ */
+ public function testRequireLoginAnon( $expected, $reason, $title ) {
+ $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
+
+ $user = User::newFromId( 0 );
+ $specialPage->getContext()->setUser( $user );
+ $specialPage->getContext()->setLanguage( Language::factory( 'en' ) );
+
+ $this->setExpectedException( 'UserNotLoggedIn', $expected );
+
+ // $specialPage->requireLogin( [ $reason [, $title ] ] )
+ call_user_func_array(
+ array( $specialPage, 'requireLogin' ),
+ array_filter( array( $reason, $title ) )
+ );
+ }
+
+ public function requireLoginAnonProvider() {
+ $lang = 'en';
+
+ $expected1 = wfMessage( 'exception-nologin-text' )->inLanguage( $lang )->text();
+ $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
+
+ return array(
+ array( $expected1, null, null ),
+ array( $expected2, 'about', null ),
+ array( $expected2, 'about', 'about' ),
+ );
+ }
+
+ public function testRequireLoginNotAnon() {
+ $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
+
+ $user = User::newFromName( "UTSysop" );
+ $specialPage->getContext()->setUser( $user );
+
+ $specialPage->requireLogin();
+
+ // no exception thrown, logged in use can access special page
+ $this->assertTrue( true );
+ }
+
+}
--- /dev/null
+<?php
+
+/**
+ * @covers MWFunction
+ */
+class MWFunctionTest extends MediaWikiTestCase {
+ public function testNewObjFunction() {
+ $arg1 = 'Foo';
+ $arg2 = 'Bar';
+ $arg3 = array( 'Baz' );
+ $arg4 = new ExampleObject;
+
+ $args = array( $arg1, $arg2, $arg3, $arg4 );
+
+ $newObject = new MWBlankClass( $arg1, $arg2, $arg3, $arg4 );
+ $this->hideDeprecated( 'MWFunction::newObj' );
+ $this->assertEquals(
+ MWFunction::newObj( 'MWBlankClass', $args )->args,
+ $newObject->args
+ );
+ }
+}
+
+class MWBlankClass {
+
+ public $args = array();
+
+ function __construct( $arg1, $arg2, $arg3, $arg4 ) {
+ $this->args = array( $arg1, $arg2, $arg3, $arg4 );
+ }
+}
+
+class ExampleObject {
+}