[Pkg-owncloud-commits] [owncloud] 25/111: Add tests for OC_API::mergeResponses()
David Prévot
taffit at moszumanska.debian.org
Wed Nov 20 21:38:37 UTC 2013
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit 959513fdc866910855b886051394962ab0ee582e
Author: tomneedham <tom at owncloud.com>
Date: Thu Nov 14 00:40:09 2013 +0000
Add tests for OC_API::mergeResponses()
---
tests/lib/api.php | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 159 insertions(+)
diff --git a/tests/lib/api.php b/tests/lib/api.php
new file mode 100644
index 0000000..6cff182
--- /dev/null
+++ b/tests/lib/api.php
@@ -0,0 +1,159 @@
+<?php
+/**
+ * Copyright (c) 2013 Tom Needham <tom at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_API extends PHPUnit_Framework_TestCase {
+
+ // Helps build a response variable
+ public function buildResponse($shipped=true, $data=null, $code=100) {
+ return array(
+ 'shipped' => $shipped,
+ 'response' => new OC_OCS_Result($data, $code),
+ 'app' => uniqid('testapp_', true),
+ );
+ }
+
+ // Validate details of the result
+ public function checkResult($result, $success=true) {
+ // Check response is of correct type
+ $this->assertEquals('OC_OCS_Result', get_class($result));
+ // CHeck if it succeeded
+ $this->assertEquals($success, $result->succeeded());
+ }
+
+ // Test the merging of multiple responses
+ public function testMergeResponses(){
+ // Tests that app responses are merged correctly
+ // Setup some data arrays
+ $data1 = array(
+ 'users' => array(
+ 'tom' => array(
+ 'key' => 'value',
+ ),
+ 'frank' => array(
+ 'key' => 'value',
+ ),
+ ));
+
+ $data2 = array(
+ 'users' => array(
+ 'tom' => array(
+ 'key' => 'newvalue',
+ ),
+ 'jan' => array(
+ 'key' => 'value',
+ ),
+ ));
+ // Test merging one success result
+ $response = $this->buildResponse(true, $data1);
+ $result = OC_API::mergeResponses(array($response));
+ $this->assertEquals($response['response'], $result);
+ $this->checkResult($result);
+
+ $response = $this->buildResponse(true, $data1, 101);
+ $result = OC_API::mergeResponses(array($response));
+ $this->assertEquals($response['response'], $result);
+ $this->checkResult($result);
+
+ $response = $this->buildResponse(true, $data1, 997);
+ $result = OC_API::mergeResponses(array($response));
+ $this->assertEquals($response['response'], $result);
+ $this->checkResult($result, false);
+
+ // Two shipped success results
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(true, $data1O),
+ $this->buildResponse(true, $data2),
+ ));
+ $this->checkResult($result);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // Two shipped results, one success and one failure
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(true, $data1),
+ $this->buildResponse(true, $data2, 997),
+ ));
+ $this->checkResult($result, false);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // Two shipped results, both failure
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(true, $data1, 997),
+ $this->buildResponse(true, $data2, 997),
+ ));
+ $this->checkResult($result, false);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // Two third party success results
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(false, $data1),
+ $this->buildResponse(false, $data2),
+ ));
+ $this->checkResult($result);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // Two third party results, one success and one failure
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(false, $data1),
+ $this->buildResponse(false, $data2, 997),
+ ));
+ $this->checkResult($result, false);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // Two third party results, both failure
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(false, $data1, 997),
+ $this->buildResponse(false, $data2, 997),
+ ));
+ $this->checkResult($result, false);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // One of each, both success
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(false, $data1),
+ $this->buildResponse(true, $data2),
+ ));
+ $this->checkResult($result);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // One of each, both failure
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(false, $data1, 997),
+ $this->buildResponse(true, $data2, 997),
+ ));
+ $this->checkResult($result, false);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // One of each, shipped success
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(false, $data1, 997),
+ $this->buildResponse(true, $data2),
+ ));
+ $this->checkResult($result);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ // One of each, third party success
+ $result = OC_API::mergeResponses(array(
+ $this->buildResponse(false, $data1),
+ $this->buildResponse(true, $data2, 997),
+ ));
+ $this->checkResult($result, false);
+ $resultData = $result->getData();
+ $this->assertArrayHasKey('jan', $resultData['users']);
+
+ }
+
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list