jenkins-bot has submitted this change and it was merged.
Change subject: Tidy up WikiGrok\Api\ApiResponse unit tests
......................................................................
Tidy up WikiGrok\Api\ApiResponse unit tests
Change-Id: Ia052c501520bafe3eecdd7f0c3d0e2043011034e
---
M tests/phpunit/api/ApiResponseTest.php
1 file changed, 70 insertions(+), 146 deletions(-)
Approvals:
Kaldari: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/phpunit/api/ApiResponseTest.php
b/tests/phpunit/api/ApiResponseTest.php
index 4d95c2b..0a1db4b 100644
--- a/tests/phpunit/api/ApiResponseTest.php
+++ b/tests/phpunit/api/ApiResponseTest.php
@@ -57,9 +57,12 @@
class ApiResponseTest extends MediaWikiTestCase {
+ /** @var \WikiGrok\EventLogger */
private $eventLogger;
private $context;
+ /** @var \ApiResponse */
private $api;
+ private $user;
protected function setUp() {
parent::setUp();
@@ -89,120 +92,44 @@
'task_type' => 'mobile a',
'claims' => json_encode( $claims ),
'mobile_mode' => 'beta',
+ 'testing' => true,
) );
$this->context->setRequest( $request );
$this->api->execute();
}
/**
- * @expectedException UsageException
+ * @dataProvider provideBadClaims
+ * @expectedException \UsageException
*/
- public function testExecuteThrowsWhenThereAreNoClaims() {
- self::runExecuteWithClaims( array() );
+ public function testExecuteWithBadClaims( $claims ) {
+ $this->runExecuteWithClaims( $claims );
}
- /**
- * @expectedException UsageException
- */
- public function testExecuteThrowsWhenClaimMissingPropId() {
- $claims = array(
- array(
- // Missing propid
- 'prop' => 'occupation',
- 'valueid' => 'Q3423',
- 'value' => 'insurance broker',
- 'correct' => true,
- )
+ public static function provideBadClaims() {
+ $goodClaim = array(
+ 'prop' => 'occupation',
+ 'valueid' => 'Q3423',
+ 'value' => 'insurance broker',
+ 'correct' => true,
);
- self::runExecuteWithClaims( $claims );
- }
- /**
- * @expectedException UsageException
- */
- public function testExecuteThrowsWhenClaimMissingProp() {
- $claims = array(
- array(
- // Missing prop
- 'propid' => 'P103',
- 'valueid' => 'Q3423',
- 'value' => 'insurance broker',
- 'correct' => true,
- )
- );
- self::runExecuteWithClaims( $claims );
- }
+ $result = array();
+ $result[] = array( array() ); // No claims
- /**
- * @expectedException UsageException
- */
- public function testExecuteThrowsWhenClaimMissingValueId() {
- $claims = array(
- array(
- // Missing valueid
- 'propid' => 'P103',
- 'prop' => 'occupation',
- 'value' => 'insurance broker',
- 'correct' => true,
- )
- );
- self::runExecuteWithClaims( $claims );
- }
+ // Generate a claim with a property missing for each property
that a well-
+ // formed claim should have.
+ foreach ( $goodClaim as $key => $value ) {
+ $claim = $goodClaim;
+ unset( $claim[$key] );
- /**
- * @expectedException UsageException
- */
- public function testExecuteThrowsWhenClaimMissingValue() {
- $claims = array(
- array(
- // Missing value
- 'propid' => 'P103',
- 'prop' => 'occupation',
- 'valueid' => 'Q3423',
- 'correct' => true,
- )
- );
- self::runExecuteWithClaims( $claims );
- }
-
- /**
- * @expectedException UsageException
- */
- public function testExecuteThrowsWhenClaimMissingCorrect() {
- $claims = array(
- array(
- // Missing correct
- 'propid' => 'P103',
- 'prop' => 'occupation',
- 'valueid' => 'Q3423',
- 'value' => 'insurance broker',
- )
- );
- self::runExecuteWithClaims( $claims );
- }
-
- /**
- * @dataProvider provideExecute
- */
- public function testExecute( $requestData, $expectedEvents ) {
- $request = new FauxRequest( $requestData );
- $this->context->setRequest( $request );
-
- foreach ( $expectedEvents as $i => $expectedEvent ) {
- $this->eventLogger->expects( $this->at( $i ) )
- ->method( 'logEvent' )
- ->with(
- ApiResponse::SCHEMA,
- ApiResponse::SCHEMA_REV_ID,
- $expectedEvent
- )
- ->will( $this->returnValue( true ) );
+ $result[] = array( array( $claim ) );
}
- $this->api->execute();
+ return $result;
}
- public static function provideExecute() {
+ public function testExecute() {
$claims = array(
array(
'propid' => 'P103',
@@ -220,57 +147,54 @@
),
);
- return array(
+ $expectedEvents = array(
array(
- array(
- 'page_id' => 1,
- 'user_token' => '987654321fedcba',
- 'subject_id' => 2,
- 'subject' => 'Vessels',
- 'task_token' => 'abcdef0123456789',
- 'task_type' => 'mobile a',
- 'claims' => json_encode( $claims ),
- 'mobile_mode' => 'beta',
- 'testing' => true,
- ),
- array(
- array(
- 'pageId' => 1,
- 'userToken' =>
'987654321fedcba',
- 'userEditCount' => 1234,
- 'taskToken' =>
'abcdef0123456789',
- 'subjectId' => 2,
- 'subject' => 'Vessels',
- 'taskType' => 'mobile a',
- 'mobileMode' => 'beta',
- 'propertyId' => 'P103',
- 'property' => 'occupation',
- 'valueId' => 'Q3423',
- 'value' => 'insurance broker',
- 'response' => true,
- 'testing' => true,
- 'isLoggedIn' => true,
- ),
- array(
- 'pageId' => 1,
- 'userToken' =>
'987654321fedcba',
- 'userEditCount' => 1234,
- 'taskToken' =>
'abcdef0123456789',
- 'subjectId' => 2,
- 'subject' => 'Vessels',
- 'taskType' => 'mobile a',
- 'mobileMode' => 'beta',
- 'propertyId' => 'P103',
- 'property' => 'occupation',
- 'valueId' => 'Q7566',
- 'value' => 'engineer',
- 'response' => false,
- 'testing' => true,
- 'isLoggedIn' => true,
- ),
- ),
+ 'pageId' => 1,
+ 'userToken' => '987654321fedcba',
+ 'userEditCount' => 1234,
+ 'taskToken' => 'abcdef0123456789',
+ 'subjectId' => 2,
+ 'subject' => 'Vessels',
+ 'taskType' => 'mobile a',
+ 'mobileMode' => 'beta',
+ 'propertyId' => 'P103',
+ 'property' => 'occupation',
+ 'valueId' => 'Q3423',
+ 'value' => 'insurance broker',
+ 'response' => true,
+ 'testing' => true,
+ 'isLoggedIn' => true,
+ ),
+ array(
+ 'pageId' => 1,
+ 'userToken' => '987654321fedcba',
+ 'userEditCount' => 1234,
+ 'taskToken' => 'abcdef0123456789',
+ 'subjectId' => 2,
+ 'subject' => 'Vessels',
+ 'taskType' => 'mobile a',
+ 'mobileMode' => 'beta',
+ 'propertyId' => 'P103',
+ 'property' => 'occupation',
+ 'valueId' => 'Q7566',
+ 'value' => 'engineer',
+ 'response' => false,
+ 'testing' => true,
+ 'isLoggedIn' => true,
),
);
- }
+ foreach ( $expectedEvents as $i => $expectedEvent ) {
+ $this->eventLogger->expects( $this->at( $i ) )
+ ->method( 'logEvent' )
+ ->with(
+ ApiResponse::SCHEMA,
+ ApiResponse::SCHEMA_REV_ID,
+ $expectedEvent
+ )
+ ->will( $this->returnValue( true ) );
+ }
+
+ $this->runExecuteWithClaims( $claims );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/173311
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia052c501520bafe3eecdd7f0c3d0e2043011034e
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/WikiGrok
Gerrit-Branch: master
Gerrit-Owner: Phuedx <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits