Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Unit\Parser\Parsoid;
|
|
|
|
use MediaWiki\Parser\Parsoid\ParsoidRenderID;
|
|
use MediaWikiUnitTestCase;
|
|
|
|
class ParsoidRenderIdTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidRenderID
|
|
*/
|
|
public function testConstruction() {
|
|
$renderID = new ParsoidRenderID( 1, '123-abc' );
|
|
$this->assertSame( 1, $renderID->getRevisionID() );
|
|
$this->assertEquals( '123-abc', $renderID->getUniqueID() );
|
|
$this->assertEquals( '1/123-abc', $renderID->__toString() );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidRenderID::newFromKey
|
|
*/
|
|
public function testRoundTrip() {
|
|
$renderID = new ParsoidRenderID( 1, '123-abc' );
|
|
$stringRenderID = $renderID->__toString();
|
|
$backToRenderID = $renderID::newFromKey( $stringRenderID );
|
|
$this->assertSame( $stringRenderID, $backToRenderID->__toString() );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideETags
|
|
*
|
|
* @param string $eTag
|
|
* @param ParsoidRenderID $renderId
|
|
*
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidRenderID::newFromETag
|
|
*/
|
|
public function testNewFromETag( $eTag, $renderId ) {
|
|
$actual = ParsoidRenderID::newFromETag( $eTag );
|
|
$this->assertSame( $renderId->getKey(), $actual->getKey() );
|
|
}
|
|
|
|
public static function provideETags() {
|
|
yield [ '"1/abc/stash"', new ParsoidRenderID( 1, 'abc' ) ];
|
|
yield [ '"1/abc"', new ParsoidRenderID( 1, 'abc' ) ];
|
|
yield [ '"1/abc/stash/stash"', new ParsoidRenderID( 1, 'abc' ) ];
|
|
yield [ 'W/"1/abc"', new ParsoidRenderID( 1, 'abc' ) ];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideBadETags
|
|
*
|
|
* @param string $eTag
|
|
*
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidRenderID::newFromETag
|
|
*/
|
|
public function testNewFromBadETag( $eTag ) {
|
|
// make sure it doesn't explode
|
|
$this->assertNull( ParsoidRenderID::newFromETag( $eTag ) );
|
|
}
|
|
|
|
public static function provideBadETags() {
|
|
yield [ '' ];
|
|
yield [ '0' ];
|
|
yield [ '""' ];
|
|
yield [ '"/"' ];
|
|
yield [ '"x/y"' ];
|
|
yield [ '"1/foo"XXX' ];
|
|
yield [ 'XXX"1/foo"' ];
|
|
}
|
|
}
|