|
17 | 17 | use MediaWiki\Extension\IdProvider\Generators\UuidGenerator;
|
18 | 18 | use MediaWiki\Extension\IdProvider\IdProviderFactory;
|
19 | 19 | use PHPUnit\Framework\TestCase;
|
| 20 | +use Title; |
20 | 21 |
|
21 | 22 | /**
|
22 | 23 | * @group IDProvider
|
@@ -57,7 +58,27 @@ public function testGetUniqueIdChecker() {
|
57 | 58 | $reflection->setAccessible( true );
|
58 | 59 | $isUniqueClosure = $reflection->invoke( null );
|
59 | 60 |
|
60 |
| - $this->assertTrue( $isUniqueClosure( 'NewPage' ) ); |
| 61 | + // check when id/title is from the page which exists and return false when page already exists |
| 62 | + $this->assertFalse( $isUniqueClosure( 'Main Page' ) ); |
| 63 | + |
| 64 | + // check when id/title is from the page which not exists and return true if page do not exists |
| 65 | + $this->assertTrue( $isUniqueClosure( 'Non existing page' ) ); |
| 66 | + } |
| 67 | + |
| 68 | + public function testGetUniqueIdCheckerWhenTitleIsMalformed() { |
| 69 | + // Call the private method using Reflection |
| 70 | + $reflection = new \ReflectionMethod( IdProviderFactory::class, 'getUniqueIdChecker' ); |
| 71 | + $reflection->setAccessible( true ); |
| 72 | + $isUniqueClosure = $reflection->invoke( null ); |
| 73 | + |
| 74 | + $title = Title::newFromText( 'nonexisting title' ); |
| 75 | + |
| 76 | + // Asserts that an InvalidArgumentException is thrown and that message is good |
| 77 | + $this->expectException( \InvalidArgumentException::class ); |
| 78 | + $this->expectExceptionMessage( '$text must be a string' ); |
| 79 | + |
| 80 | + // add object instead of string, it should thrown the InvalidArgumentException |
| 81 | + $isUniqueClosure( $title ); |
61 | 82 | }
|
62 | 83 |
|
63 | 84 | public function testParamGet() {
|
|
0 commit comments