Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/95647
Change subject: Add basic unit test for dieOnBadUser api method
......................................................................
Add basic unit test for dieOnBadUser api method
Change-Id: Ic9fd4e63b0a7e3508c600f34decb8ce18abc1597
---
R tests/ApiThankIntegrationTest.php
A tests/ApiThankUnitTest.php
2 files changed, 83 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks
refs/changes/47/95647/1
diff --git a/tests/ApiThankTest.php b/tests/ApiThankIntegrationTest.php
similarity index 96%
rename from tests/ApiThankTest.php
rename to tests/ApiThankIntegrationTest.php
index e92efc6..72529c7 100644
--- a/tests/ApiThankTest.php
+++ b/tests/ApiThankIntegrationTest.php
@@ -1,6 +1,8 @@
<?php
/**
+ * Integration tests for the Thanks api module
+ *
* @covers ApiThank
*
* @group Thanks
diff --git a/tests/ApiThankUnitTest.php b/tests/ApiThankUnitTest.php
new file mode 100644
index 0000000..c45098d
--- /dev/null
+++ b/tests/ApiThankUnitTest.php
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * Unit tests for the thanks api modul
+ *
+ * @group Thanks
+ * @group API
+ *
+ * @author Adam Shorland
+ */
+class ApiThankUnitTest extends \PHPUnit_Framework_TestCase {
+
+ static $moduleName = 'wbmergeitems';
+
+ protected function getModule() {
+ return new ApiThank( new ApiMain(), self::$moduleName );
+ }
+
+ /**
+ * @dataProvider provideDieOnBadUser
+ * @covers ApiThank::dieOnBadUser
+ */
+ public function testDieOnBadUser( $user, $expectedError ) {
+ $module = $this->getModule();
+ $method = new ReflectionMethod( $module, 'dieOnBadUser' );
+ $method->setAccessible( true );
+
+ if( $expectedError ) {
+ $this->setExpectedException( 'UsageException',
$expectedError );
+ }
+
+ $method->invoke( $module, $user );
+ //perhaps the method should return true.. For now we must do
this
+ $this->assertTrue( true );
+ }
+
+ public function provideDieOnBadUser() {
+ $testCases = array();
+
+ $mockUser = $this->getMock( 'User' );
+ $mockUser->expects( $this->once() )
+ ->method( 'isAnon' )
+ ->will( $this->returnValue( true ) );
+
+ $testCases[ 'anon' ] = array( $mockUser, 'Anonymous users
cannot send thanks' );
+
+ $mockUser = $this->getMock( 'User' );
+ $mockUser->expects( $this->once() )
+ ->method( 'isAnon' )
+ ->will( $this->returnValue( false ) );
+ $mockUser->expects( $this->once() )
+ ->method( 'pingLimiter' )
+ ->will( $this->returnValue( true ) );
+
+ $testCases[ 'ping' ] = array( $mockUser, "You've exceeded your
rate limit. Please wait some time and try again" );
+
+ $mockUser = $this->getMock( 'User' );
+ $mockUser->expects( $this->once() )
+ ->method( 'isAnon' )
+ ->will( $this->returnValue( false ) );
+ $mockUser->expects( $this->once() )
+ ->method( 'pingLimiter' )
+ ->will( $this->returnValue( false ) );
+ $mockUser->expects( $this->once() )
+ ->method( 'isBlocked' )
+ ->will( $this->returnValue( true ) );
+
+ $testCases[ 'blocked' ] = array( $mockUser, 'You have been
blocked from editing' );
+
+ return $testCases;
+ }
+
+ //@todo test userAlreadySentThanksForRevision
+ //@todo test getRevisionFromParams
+ //@todo test getTitleFromRevision
+ //@todo test getSourceFromParams
+ //@todo test getUserIdFromRevision
+ //@todo test markResultSuccess
+ //@todo test sendThanks
+
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/95647
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic9fd4e63b0a7e3508c600f34decb8ce18abc1597
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits