Skip to content

Commit ba5185f

Browse files
committed
IdProviderFactoryTest.php
- add new test cases to check whenever the page exists or not
1 parent e9f6665 commit ba5185f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/phpunit/Unit/IdProviderFactoryTest.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use MediaWiki\Extension\IdProvider\Generators\UuidGenerator;
1818
use MediaWiki\Extension\IdProvider\IdProviderFactory;
1919
use PHPUnit\Framework\TestCase;
20+
use Title;
2021

2122
/**
2223
* @group IDProvider
@@ -57,7 +58,27 @@ public function testGetUniqueIdChecker() {
5758
$reflection->setAccessible( true );
5859
$isUniqueClosure = $reflection->invoke( null );
5960

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 );
6182
}
6283

6384
public function testParamGet() {

0 commit comments

Comments
 (0)