| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Specials\SpecialBookSources; |
| 4 |
use MediaWiki\Title\TitleFactory; |
| 5 |
|
| 6 |
class SpecialBookSourcesTest extends SpecialPageTestBase { |
| 7 |
public static function provideISBNs() { |
| 8 |
return [ |
| 9 |
[ '978-0-300-14424-6', true ], |
| 10 |
[ '0-14-020652-3', true ], |
| 11 |
[ '020652-3', false ], |
| 12 |
[ '9781234567897', true ], |
| 13 |
[ '1-4133-0454-0', true ], |
| 14 |
[ '978-1413304541', true ], |
| 15 |
[ '0136091814', true ], |
| 16 |
[ '0136091812', false ], |
| 17 |
[ '9780136091813', true ], |
| 18 |
[ '9780136091817', false ], |
| 19 |
[ '123456789X', true ], |
| 20 |
|
| 21 |
|
| 22 |
[ '1413304541', false ], |
| 23 |
[ '141330454X', false ], |
| 24 |
[ '1413304540', true ], |
| 25 |
[ '14133X4540', false ], |
| 26 |
[ '97814133X4541', false ], |
| 27 |
[ '978035642615X', false ], |
| 28 |
[ '9781413304541', true ], |
| 29 |
[ '9780356426150', true ], |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function testIsValidISBN( $isbn, $isValid ) { |
| 38 |
$this->assertSame( $isValid, SpecialBookSources::isValidISBN( $isbn ) ); |
| 39 |
} |
| 40 |
|
| 41 |
protected function newSpecialPage() { |
| 42 |
$services = $this->getServiceContainer(); |
| 43 |
return new SpecialBookSources( |
| 44 |
$services->getRevisionLookup(), |
| 45 |
$services->getTitleFactory() |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public function testExecute() { |
| 53 |
$this->setService( 'TitleFactory', $this->createMock( TitleFactory::class ) ); |
| 54 |
[ $html, ] = $this->executeSpecialPage( 'Invalid', null, 'qqx' ); |
| 55 |
$this->assertStringContainsString( '(booksources-invalid-isbn)', $html ); |
| 56 |
[ $html, ] = $this->executeSpecialPage( '0-7475-3269-9', null, 'qqx' ); |
| 57 |
$this->assertStringNotContainsString( '(booksources-invalid-isbn)', $html ); |
| 58 |
$this->assertStringContainsString( '(booksources-text)', $html ); |
| 59 |
} |
| 60 |
} |