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
96 lines
2.3 KiB
PHP
96 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Revision;
|
|
|
|
use MediaWiki\Revision\ContributionsSegment;
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
|
use MockTitleTrait;
|
|
|
|
class ContributionsSegmentTest extends \MediaWikiUnitTestCase {
|
|
use MockTitleTrait;
|
|
|
|
public static function provideFlags() {
|
|
yield [
|
|
[]
|
|
];
|
|
yield [
|
|
[
|
|
'newest' => false,
|
|
'oldest' => true
|
|
]
|
|
];
|
|
yield [
|
|
[
|
|
'newest' => true,
|
|
'oldest' => false,
|
|
]
|
|
];
|
|
yield [
|
|
[
|
|
'newest' => false,
|
|
'oldest' => false
|
|
]
|
|
];
|
|
yield [
|
|
[
|
|
'newest' => true,
|
|
'oldest' => true,
|
|
]
|
|
];
|
|
yield [
|
|
[
|
|
'oldest' => true,
|
|
]
|
|
];
|
|
yield [
|
|
[
|
|
'newest' => true,
|
|
]
|
|
];
|
|
yield [
|
|
[
|
|
'oldest' => false,
|
|
]
|
|
];
|
|
yield [
|
|
[
|
|
'newest' => false,
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideFlags
|
|
* @covers \MediaWiki\Revision\ContributionsSegment
|
|
*/
|
|
public function testFlags( $flags ) {
|
|
$contributionsSegment = new ContributionsSegment( [], [], null, null, [], $flags );
|
|
$this->assertSame( $flags['newest'] ?? false, $contributionsSegment->isNewest() );
|
|
$this->assertSame( $flags['oldest'] ?? false, $contributionsSegment->isOldest() );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Revision\ContributionsSegment
|
|
*/
|
|
public function testConstruction() {
|
|
$mockTitle = $this->makeMockTitle( 'Foo', [ 'id' => 1 ] );
|
|
$revisionRecords = [ new MutableRevisionRecord( $mockTitle ), new MutableRevisionRecord( $mockTitle ) ];
|
|
$before = 'before';
|
|
$after = 'after';
|
|
$tags = [ 3 => [ 'frob' ] ];
|
|
$deltas = [ 3 => -7, 5 => null ];
|
|
|
|
$contributionsSegment =
|
|
new ContributionsSegment( $revisionRecords, $tags, $before, $after, $deltas );
|
|
$this->assertSame( $revisionRecords, $contributionsSegment->getRevisions() );
|
|
$this->assertSame( $tags[3], $contributionsSegment->getTagsForRevision( 3 ) );
|
|
$this->assertSame( [], $contributionsSegment->getTagsForRevision( 17 ) );
|
|
$this->assertSame( $before, $contributionsSegment->getBefore() );
|
|
$this->assertSame( $after, $contributionsSegment->getAfter() );
|
|
$this->assertFalse( $contributionsSegment->isNewest(), 'isNewest' );
|
|
$this->assertFalse( $contributionsSegment->isOldest(), 'isOldest' );
|
|
$this->assertSame( $deltas[3], $contributionsSegment->getDeltaForRevision( 3 ) );
|
|
$this->assertNull( $contributionsSegment->getDeltaForRevision( 5 ) );
|
|
$this->assertNull( $contributionsSegment->getDeltaForRevision( 77 ) );
|
|
}
|
|
}
|