Debian Codegraph @

tests/phpunit/unit/includes/search/FauxSearchResultTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Revision\MutableRevisionRecord;
4
5 /**
6 * @group Search
7 * @covers \FauxSearchResultSet
8 */
9 class FauxSearchResultTest extends MediaWikiUnitTestCase {
10 use MockTitleTrait;
11
12 public function testConstruct() {
13 $title = $this->makeMockTitle( 'Foo', [ 'id' => 0 ] );
14 $r = new FauxSearchResult( $title );
15 $this->assertSame( $title, $r->getTitle() );
16 $this->assertTrue( $r->isMissingRevision() );
17 $this->assertNull( $r->getFile() );
18 $this->assertSame( 0, $r->getWordCount() );
19
20 $title = $this->makeMockTitle( 'Foo', [ 'id' => 1 ] );
21 $rev = new MutableRevisionRecord( $title );
22 $rev->setTimestamp( '20000101000000' );
23 $r = new FauxSearchResult( $title, $rev );
24 $this->assertFalse( $r->isMissingRevision() );
25 $this->assertSame( '20000101000000', $r->getTimestamp() );
26
27 $title = $this->makeMockTitle( 'Foo', [ 'id' => 1 ] );
28 $rev = new MutableRevisionRecord( $title );
29 $r = new FauxSearchResult( $title, $rev, null, '123' );
30 $this->assertSame( 3, $r->getByteSize() );
31
32 $title = $this->makeMockTitle( 'Foo', [ 'id' => 0 ] );
33 $file = $this->getFileMock( 'Foo.png' );
34 $r = new FauxSearchResult( $title, null, $file );
35 $this->assertSame( $file, $r->getFile() );
36 }
37
38 /**
39 * @param string $filename
40 * @return File
41 */
42 private function getFileMock( $filename ) {
43 $title = $this->getMockBuilder( File::class )
44 ->disableOriginalConstructor()
45 ->onlyMethods( [ 'getName' ] )
46 ->getMock();
47 $title->method( 'getName' )
48 ->willReturn( $filename );
49 return $title;
50 }
51
52 }