Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 19 - call to undefined method WikiPage::factory() #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/IdProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@
}

/**
* Checks whether a WikiPage with the following id/title already exists
* Function to check if string id/title already exists, i.e. is already used as a
* WikiPage (if page already exists)
*
* @param string $text The title or ID to check for uniqueness of the wiki page.
* @return \Closure
*/
private static function isUniqueId() {
return function ( $id ) {
$title = Title::newFromText( $id );
return function ( $text ) {
$title = Title::newFromText( $text );

// If no Title object is found, the page does not exist
if ( $title === null ) {
return true;

Check warning on line 74 in src/IdProviderFactory.php

View check run for this annotation

Codecov / codecov/patch

src/IdProviderFactory.php#L74

Added line #L74 was not covered by tests
}

// MW 1.36+
if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
Expand Down
20 changes: 20 additions & 0 deletions tests/phpunit/Unit/IdProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,24 @@ public function testIncrementCreatesIncrementIdGenerator() {
$provider = IdProviderFactory::increment();
$this->assertEquals( IncrementIdGenerator::class, $provider->generatorClass() );
}

public function testIsUniqueId() {
// Call the private method using Reflection
$reflection = new \ReflectionMethod( IdProviderFactory::class, 'isUniqueId' );
$reflection->setAccessible( true );
$isUniqueClosure = $reflection->invoke( null );

$this->assertTrue( $isUniqueClosure( 'NewPage' ) );
}

public function testParamGet() {
// Call the private method using Reflection
$reflection = new \ReflectionMethod( IdProviderFactory::class, 'paramGet' );
$reflection->setAccessible( true );

$params = [ 'key' => 'value' ];

$this->assertEquals( 'value', $reflection->invoke( null, $params, 'key', 'default' ) );
$this->assertEquals( 'default', $reflection->invoke( null, $params, 'missing_key', 'default' ) );
}
}