Actualización
This commit is contained in:
87
plugin/pens/lib/tests/test_pens_package_handler.php
Normal file
87
plugin/pens/lib/tests/test_pens_package_handler.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of php-pens.
|
||||
*
|
||||
* php-pens is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* php-pens is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with php-pens. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the PENSPackageHandler class
|
||||
*
|
||||
* This class provides unit tests for the PENSPackageHandler class
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
require_once 'simpletest/autorun.php';
|
||||
require_once __DIR__.'/../pens.php';
|
||||
|
||||
class MyPackageHandler extends PENSPackageHandler {
|
||||
public function processPackage($request, $path_to_package) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit tests for the PENSPackageHandler class
|
||||
*
|
||||
* This class provides unit tests for the PENSPackageHandler class
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class TestPENSPackageHandler extends UnitTestCase {
|
||||
|
||||
public function testSupportedPackageTypesInvalid() {
|
||||
$object = new MyPackageHandler();
|
||||
$object->setSupportedPackageTypes("testing");
|
||||
$this->assertEqual($object->getSupportedPackageTypes(), null);
|
||||
}
|
||||
|
||||
public function testSupportedPackageTypesInvalid2() {
|
||||
$object = new MyPackageHandler();
|
||||
$object->setSupportedPackageTypes(array("aicc-pkg", "testing"));
|
||||
$this->assertEqual($object->getSupportedPackageTypes(), array("aicc-pkg"));
|
||||
}
|
||||
|
||||
public function testSupportedPackageTypesValid() {
|
||||
$object = new MyPackageHandler();
|
||||
$object->setSupportedPackageTypes(array("aicc-pkg", "lms-qti"));
|
||||
$this->assertEqual($object->getSupportedPackageTypes(), array("aicc-pkg", "lms-qti"));
|
||||
}
|
||||
|
||||
public function testSupportedPackageFormatsInvalid() {
|
||||
$object = new MyPackageHandler();
|
||||
$object->setSupportedPackageFormats("testing");
|
||||
$this->assertEqual($object->getSupportedPackageFormats(), null);
|
||||
}
|
||||
|
||||
public function testSupportedPackageFormatsInvalid2() {
|
||||
$object = new MyPackageHandler();
|
||||
$object->setSupportedPackageFormats(array("zip", "testing"));
|
||||
$this->assertEqual($object->getSupportedPackageFormats(), array("zip"));
|
||||
}
|
||||
|
||||
public function testSupportedPackageFormatsValid() {
|
||||
$object = new MyPackageHandler();
|
||||
$object->setSupportedPackageFormats(array("zip", "jar"));
|
||||
$this->assertEqual($object->getSupportedPackageFormats(), array("zip", "jar"));
|
||||
}
|
||||
}
|
||||
213
plugin/pens/lib/tests/test_pens_request.php
Normal file
213
plugin/pens/lib/tests/test_pens_request.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of php-pens.
|
||||
*
|
||||
* php-pens is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* php-pens is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with php-pens. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the PENSRequest class
|
||||
*
|
||||
* This class provides unit tests for the PENSRequest class
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
require_once 'simpletest/autorun.php';
|
||||
require_once __DIR__.'/../pens.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the PENSRequest class
|
||||
*
|
||||
* This class provides unit tests for the PENSRequest class
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class TestPENSRequest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Valid arguments to be used for tests
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $args = null;
|
||||
|
||||
public function setUp() {
|
||||
$this->args = array(
|
||||
"pens-version" => "1.0.0",
|
||||
"command" => "collect",
|
||||
"package-type" => "aicc-pkg",
|
||||
"package-type-version" => "1.0",
|
||||
"package-format" => "zip",
|
||||
"package-id" => "http://myurl.com/12345",
|
||||
"package-url" => "http://myurl.com/mypackage.zip",
|
||||
"package-url-expiry" => "2006-04-01T06:51:29Z",
|
||||
"client" => "Authorware7",
|
||||
"receipt" => "mailto:name@domain.com",
|
||||
"package-url-user-id" => "guillaumev",
|
||||
"package-url-account" => "toto",
|
||||
"package-url-password" => "12345",
|
||||
"system-user-id" => "guillaumev",
|
||||
"system-password" => "12345",
|
||||
"alerts" => "http://myurl.com/alerts",
|
||||
"vendor-data" => "here are my data");
|
||||
}
|
||||
|
||||
public function createObject($myargs) {
|
||||
return PENSRequestFactory::createPENSRequest($myargs);
|
||||
}
|
||||
|
||||
public function exceptionTestForValue($key, $value, $code) {
|
||||
try {
|
||||
$myargs = $this->args;
|
||||
if($value === null) {
|
||||
unset($myargs[$key]);
|
||||
} else {
|
||||
$myargs[$key] = $value;
|
||||
}
|
||||
$object = $this->createObject($myargs);
|
||||
$this->fail();
|
||||
} catch(PENSException $e) {
|
||||
$this->assertEqual($e->getCode(), $code);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPensVersionInvalid() {
|
||||
$this->exceptionTestForValue("pens-version", "0.8.0", 2001);
|
||||
}
|
||||
|
||||
public function testPensVersionNull() {
|
||||
$this->exceptionTestForValue("pens-version", null, 2001);
|
||||
}
|
||||
|
||||
|
||||
public function testCommandInvalid() {
|
||||
$this->exceptionTestForValue("command", "testing", 2002);
|
||||
}
|
||||
|
||||
public function testCommandNull() {
|
||||
$this->exceptionTestForValue("command", null, 2002);
|
||||
}
|
||||
|
||||
public function testPackageTypeInvalid() {
|
||||
$this->exceptionTestForValue("package-type", "testing", 2003);
|
||||
}
|
||||
|
||||
public function testPackageTypeNull() {
|
||||
$this->exceptionTestForValue("package-type", null, 2003);
|
||||
}
|
||||
|
||||
public function testPackageTypeVersionNull() {
|
||||
$this->exceptionTestForValue("package-type-version", null, 2004);
|
||||
}
|
||||
|
||||
public function testPackageFormatInvalid() {
|
||||
$this->exceptionTestForValue("package-format", "testing", 2005);
|
||||
}
|
||||
|
||||
public function testPackageFormatNull() {
|
||||
$this->exceptionTestForValue("package-format", null, 2005);
|
||||
}
|
||||
|
||||
public function testPackageIdInvalid() {
|
||||
$this->exceptionTestForValue("package-id", "testing", 2007);
|
||||
}
|
||||
|
||||
public function testPackageIdNull() {
|
||||
$this->exceptionTestForValue("package-id", null, 2007);
|
||||
}
|
||||
|
||||
public function testPackageUrlInvalid() {
|
||||
$this->exceptionTestForValue("package-url", "testing", 2008);
|
||||
}
|
||||
|
||||
public function testPackageUrlInvalid2() {
|
||||
$this->exceptionTestForValue("package-url", "http://myurl.com/mypackage", 2008);
|
||||
}
|
||||
|
||||
public function testPackageUrlNull() {
|
||||
$this->exceptionTestForValue("package-url", null, 2008);
|
||||
}
|
||||
|
||||
public function testPackageUrlExpiryNull() {
|
||||
$this->exceptionTestForValue("package-url-expiry", null, 2009);
|
||||
}
|
||||
|
||||
public function testPackageUrlExpiryInvalid() {
|
||||
$this->exceptionTestForValue("package-url-expiry", "testing", 2009);
|
||||
}
|
||||
|
||||
public function testClientNull() {
|
||||
$this->exceptionTestForValue("client", null, 2010);
|
||||
}
|
||||
|
||||
public function testReceiptNull() {
|
||||
$this->exceptionTestForValue("receipt", null, 2011);
|
||||
}
|
||||
|
||||
public function testReceiptInvalid() {
|
||||
$this->exceptionTestForValue("receipt", "testing", 2011);
|
||||
}
|
||||
|
||||
public function testAlertsInvalid() {
|
||||
$this->exceptionTestForValue("alerts", "testing", 1201);
|
||||
}
|
||||
|
||||
public function testReceiptValid() {
|
||||
try {
|
||||
$myargs = $this->args;
|
||||
$myargs["receipt"] = "mailto:name@domain.com,name2@domain.com";
|
||||
$object = $this->createObject($myargs);
|
||||
$this->pass();
|
||||
} catch(PENSException $e) {
|
||||
$this->fail();
|
||||
}
|
||||
}
|
||||
|
||||
public function testValid() {
|
||||
try {
|
||||
$object = $this->createObject($this->args);
|
||||
$this->assertIsA($object, "PENSRequestCollect");
|
||||
$this->assertEqual($object->getPensVersion(), "1.0.0");
|
||||
$this->assertEqual($object->getPackageType(), "aicc-pkg");
|
||||
$this->assertEqual($object->getPackageTypeVersion(), "1.0");
|
||||
$this->assertEqual($object->getPackageFormat(), "zip");
|
||||
$this->assertEqual($object->getPackageId(), "http://myurl.com/12345");
|
||||
$this->assertEqual($object->getPackageUrl(), "http://myurl.com/mypackage.zip");
|
||||
$this->assertIsA($object->getPackageUrlExpiry(), "DateTime");
|
||||
$this->assertEqual($object->getClient(), "Authorware7");
|
||||
$this->assertEqual($object->getReceipt(), "mailto:name@domain.com");
|
||||
$this->assertEqual($object->getPackageUrlUserId(), "guillaumev");
|
||||
$this->assertEqual($object->getPackageUrlAccount(), "toto");
|
||||
$this->assertEqual($object->getPackageUrlPassword(), "12345");
|
||||
$this->assertEqual($object->getSystemUserId(), "guillaumev");
|
||||
$this->assertEqual($object->getSystemPassword(), "12345");
|
||||
$this->assertEqual($object->getAlerts(), "http://myurl.com/alerts");
|
||||
$this->assertEqual($object->getVendorData(), "here are my data");
|
||||
|
||||
} catch(PENSException $e) {
|
||||
$this->fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
68
plugin/pens/lib/tests/test_pens_response.php
Normal file
68
plugin/pens/lib/tests/test_pens_response.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of php-pens.
|
||||
*
|
||||
* php-pens is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* php-pens is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with php-pens. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the PENSResponse class
|
||||
*
|
||||
* This class provides unit tests for the PENSResponse class
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
require_once 'simpletest/autorun.php';
|
||||
require_once __DIR__.'/../pens.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the PENSResponse class
|
||||
*
|
||||
* This class provides unit tests for the PENSResponse class
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class TestPENSResponse extends UnitTestCase {
|
||||
|
||||
public function testCreationFromPENSException() {
|
||||
$object = new PENSResponse(new PENSException(1101));
|
||||
$this->assertEqual($object->getError(), 1101);
|
||||
$this->assertNotNull($object->getErrorText());
|
||||
}
|
||||
|
||||
public function testCreationFromArguments() {
|
||||
$object = new PENSResponse(0, "collect command received and understood");
|
||||
$this->assertIdentical($object->getError(), 0);
|
||||
$this->assertEqual($object->getErrorText(), "collect command received and understood");
|
||||
}
|
||||
|
||||
public function testCreationFromHTTPResponse() {
|
||||
$eol = PENSConfig::$eol;
|
||||
$response = "error=1101".$eol."error-text=unable to parse PENS command".$eol."version=1.0.0".$eol."pens-data=".$eol;
|
||||
$object = new PENSResponse($response);
|
||||
$this->assertIdentical($object->getError(), 1101);
|
||||
$this->assertIdentical($object->getErrorText(), "unable to parse PENS command");
|
||||
$this->assertIdentical($object->getVersion(), "1.0.0");
|
||||
$this->assertNull($object->getPensData());
|
||||
}
|
||||
}
|
||||
122
plugin/pens/lib/tests/test_pens_server.php
Normal file
122
plugin/pens/lib/tests/test_pens_server.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of php-pens.
|
||||
*
|
||||
* php-pens is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* php-pens is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with php-pens. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Functional tests for the PENS Server
|
||||
*
|
||||
* This class provides functional testing of the PENS Server
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
require_once("simpletest/autorun.php");
|
||||
require_once("simpletest/web_tester.php");
|
||||
|
||||
define(PENS_TEST_SERVER_URL, "http://localhost/pens/pens_server_test.php");
|
||||
define(PENS_TEST_RECEIPT_MAILTO, "mailto:test@test.com");
|
||||
|
||||
/**
|
||||
* Functional tests for the PENS Server
|
||||
*
|
||||
* This class provides functional tests for the PENS Server
|
||||
*
|
||||
* @package PENS
|
||||
* @subpackage Tests
|
||||
* @author Guillaume Viguier-Just <guillaume@viguierjust.com>
|
||||
* @licence http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class TestPENSServer extends WebTestCase {
|
||||
|
||||
private $_valid_params = array(
|
||||
"command" => "collect",
|
||||
"pens-version" => "1.0.0",
|
||||
"package-type" => "aicc-pkg",
|
||||
"package-type-version" => "1.0",
|
||||
"package-format" => "zip",
|
||||
"package-id" => "http://myurl.com/12345",
|
||||
"package-url" => "http://www.aicc.org/pens/sample/captivatequiz.zip",
|
||||
"package-url-expiry" => "2099-04-09T14:17:43Z",
|
||||
"client" => "test-pens-server",
|
||||
"receipt" => PENS_TEST_RECEIPT_MAILTO);
|
||||
|
||||
public function testEmptyQuery() {
|
||||
$this->get(PENS_TEST_SERVER_URL);
|
||||
$this->assertText("error=2002");
|
||||
}
|
||||
|
||||
public function testValidQuery() {
|
||||
$this->get(PENS_TEST_SERVER_URL, $this->_valid_params);
|
||||
$this->assertText("error=0");
|
||||
}
|
||||
|
||||
private function invalidParameterTest($name, $value, $error) {
|
||||
$params = $this->_valid_params;
|
||||
$params[$name] = $value;
|
||||
$this->get(PENS_TEST_SERVER_URL, $params);
|
||||
$this->assertText("error=".$error);
|
||||
}
|
||||
|
||||
private function validParameterTest($name, $value) {
|
||||
$params = $this->_valid_params;
|
||||
$params[$name] = $value;
|
||||
$this->get(PENS_TEST_SERVER_URL, $params);
|
||||
$this->assertText("error=0");
|
||||
}
|
||||
|
||||
public function testInvalidCommand() {
|
||||
$this->invalidParameterTest("command", "invalid", 2002);
|
||||
}
|
||||
|
||||
public function testInvalidVersion() {
|
||||
$this->invalidParameterTest("pens-version", "0.8.0", 2001);
|
||||
}
|
||||
|
||||
public function testInvalidPackageType() {
|
||||
$this->invalidParameterTest("package-type", "invalid", 2003);
|
||||
}
|
||||
|
||||
public function testEmptyPackageTypeVersion() {
|
||||
$this->invalidParameterTest("package-type-version", null, 2004);
|
||||
}
|
||||
|
||||
public function testInvalidPackageFormat() {
|
||||
$this->invalidParameterTest("package-format", "invalid", 2005);
|
||||
}
|
||||
|
||||
public function testInvalidPackageId() {
|
||||
$this->invalidParameterTest("package-id", "invalid", 2007);
|
||||
}
|
||||
|
||||
public function testInvalidPackageUrl() {
|
||||
$this->invalidParameterTest("package-url", "invalid", 2008);
|
||||
}
|
||||
|
||||
public function testInvalidPackageUrlExpiry() {
|
||||
$this->invalidParameterTest("package-url-expiry", "invalid", 2009);
|
||||
}
|
||||
|
||||
public function testValidPackageUrlExpiry() {
|
||||
$this->validParameterTest("package-url-expiry", "2099-01-01");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user