From a91d0a7622b69680b1c8c16116c725bc7152f2e5 Mon Sep 17 00:00:00 2001 From: alexey Date: Wed, 1 Aug 2018 11:49:20 +0300 Subject: [PATCH 1/4] Fixed tests --- test/{ => integration}/RestTestTakerTest.php | 112 +++-- test/{ => integration}/TestTakerTest.php | 435 +++++++++---------- 2 files changed, 270 insertions(+), 277 deletions(-) rename test/{ => integration}/RestTestTakerTest.php (76%) rename test/{ => integration}/TestTakerTest.php (96%) diff --git a/test/RestTestTakerTest.php b/test/integration/RestTestTakerTest.php similarity index 76% rename from test/RestTestTakerTest.php rename to test/integration/RestTestTakerTest.php index cbdc7a3e..02e3e610 100755 --- a/test/RestTestTakerTest.php +++ b/test/integration/RestTestTakerTest.php @@ -15,7 +15,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -namespace oat\taoTestTaker\test; + +namespace oat\taoTestTaker\test\integration; + +include_once dirname(__FILE__) . '/../../includes/raw_start.php'; use oat\tao\model\TaoOntology; use oat\generis\model\GenerisRdf; @@ -31,9 +34,6 @@ */ class RestTestTakerTest extends RestTestCase { - - private $genLogin; - private function checkPropertyValues($propertyValues, $property, $valueType = "literal", $value) { if (is_array($propertyValues)) { @@ -59,13 +59,11 @@ public function serviceProvider() ); } - private function getUrl() { - return $this->host.'taoTestTaker/Api'; + private function getUrl() + { + return $this->host . 'taoTestTaker/Api'; } - /** - * - */ public function testCreateTestTaker() { // create a new test taker without aprameters, should return a 400 @@ -157,54 +155,52 @@ public function testUpdateTestTaker($uriSubject) } $this->checkPropertyValues($data["data"]["properties"], GenerisRdf::PROPERTY_USER_LASTNAME, "literal", 'patrick'); - } - - public function testCreateTestTaker2() - { - $returnedData = $this->curl($this->getUrl(), CURLOPT_POST, "data", array( - 'login: 2_dummy_login', - 'password: dummy' - )); - $data = json_decode($returnedData, true); - $this->assertEquals($data["success"], true); - return $data["data"]["uriResource"]; - } - - /** - * remove all test takers - * - * @depends testCreateTestTaker - * @depends testCreateTestTaker2 - */ - public function testDeleteTestTakers($uriSubject, $uri2Subject) - { - // get all test takers - - $returnedData = $this->curl($this->getUrl()); - $data = json_decode($returnedData, true); - $this->assertEquals($data["success"], true); - $this->assertGreaterThanOrEqual(2, count($data["data"])); - $beforeDelete = count($data["data"]); - - - $returnedData = $this->curl($this->getUrl(), "DELETE", CURLINFO_HTTP_CODE, array( - 'uri: ' . $uriSubject - )); - $this->assertEquals($returnedData, 200); - - $returnedData = $this->curl($this->getUrl(), "DELETE", "data", array( - 'uri: ' . $uri2Subject - )); - $data = json_decode($returnedData, true); - $this->assertEquals($data["success"], true); - - - //check the removal - $returnedData = $this->curl($this->getUrl()); - $data = json_decode($returnedData, true); - $this->assertEquals($data["success"], true); - $this->assertCount($beforeDelete - 2 , $data["data"]); - - } + } + + public function testCreateTestTaker2() + { + $returnedData = $this->curl($this->getUrl(), CURLOPT_POST, "data", array( + 'login: 2_dummy_login', + 'password: dummy' + )); + $data = json_decode($returnedData, true); + $this->assertEquals($data["success"], true); + return $data["data"]["uriResource"]; + } + + /** + * remove all test takers + * + * @depends testCreateTestTaker + * @depends testCreateTestTaker2 + */ + public function testDeleteTestTakers($uriSubject, $uri2Subject) + { + // get all test takers + + $returnedData = $this->curl($this->getUrl()); + $data = json_decode($returnedData, true); + $this->assertEquals($data["success"], true); + $this->assertGreaterThanOrEqual(2, count($data["data"])); + $beforeDelete = count($data["data"]); + + + $returnedData = $this->curl($this->getUrl(), "DELETE", CURLINFO_HTTP_CODE, array( + 'uri: ' . $uriSubject + )); + $this->assertEquals($returnedData, 200); + + $returnedData = $this->curl($this->getUrl(), "DELETE", "data", array( + 'uri: ' . $uri2Subject + )); + $data = json_decode($returnedData, true); + $this->assertEquals($data["success"], true); + + //check the removal + $returnedData = $this->curl($this->getUrl()); + $data = json_decode($returnedData, true); + $this->assertEquals($data["success"], true); + $this->assertCount($beforeDelete - 2, $data["data"]); + } } diff --git a/test/TestTakerTest.php b/test/integration/TestTakerTest.php similarity index 96% rename from test/TestTakerTest.php rename to test/integration/TestTakerTest.php index ce834c61..bacf99c7 100755 --- a/test/TestTakerTest.php +++ b/test/integration/TestTakerTest.php @@ -1,220 +1,217 @@ - - * @package taoTestTaker - */ -class TestTakerTest extends TaoPhpUnitTestRunner -{ - - /** - * @var TestTakerService - */ - protected $subjectsService = null; - - /** - * tests initialization - * - * @return void - */ - public function setUp() - { - TaoPhpUnitTestRunner::initTest(); - // load constants - \common_ext_ExtensionsManager::singleton()->getExtensionById('taoTestTaker'); - $this->subjectsService = TestTakerService::singleton(); - } - - /** - * Test the user service implementation - * @see tao_models_classes_ServiceFactory::get - * @see TestTakerService::__construct - * @return void - */ - public function testService() - { - $this->assertIsA($this->subjectsService, '\tao_models_classes_Service'); - $this->assertIsA($this->subjectsService, 'oat\taoTestTaker\models\TestTakerService'); - } - - /** - * @return \core_kernel_classes_Class|null - */ - public function testGetRootClass() - { - $subjectClass = $this->subjectsService->getRootClass(); - $this->assertIsA($subjectClass, 'core_kernel_classes_Class'); - $this->assertEquals(TaoOntology::SUBJECT_CLASS_URI, $subjectClass->getUri()); - - $this->assertTrue($this->subjectsService->isSubjectClass($subjectClass)); - - return $subjectClass; - } - - /** - * @depends testGetRootClass - * @param $subjectClass - * @return \core_kernel_classes_Class - */ - public function testSubClassCreate($subjectClass) - { - $subSubjectClassLabel = 'subSubject class'; - $subSubjectClass = $this->subjectsService->createSubClass($subjectClass, $subSubjectClassLabel); - $this->assertIsA($subSubjectClass, 'core_kernel_classes_Class'); - $this->assertEquals($subSubjectClassLabel, $subSubjectClass->getLabel()); - - $this->assertTrue($this->subjectsService->isSubjectClass($subSubjectClass)); - - return $subSubjectClass; - } - - /** - * @depends testGetRootClass - * @param $class - * @return \core_kernel_classes_Resource - */ - public function testInstantiateClass($class) - { - $subjectInstanceLabel = 'subject instance'; - return $this->instantiateClass($class, $subjectInstanceLabel); - } - - /** - * @depends testSubClassCreate - * @param $class - * @return \core_kernel_classes_Resource - */ - public function testInstantiateSubClass($class) - { - $subSubjectInstanceLabel = 'subSubject instance'; - return $this->instantiateClass($class, $subSubjectInstanceLabel); - } - - /** - * @param $class - * @param $label - * @return \core_kernel_classes_Resource - */ - protected function instantiateClass($class, $label) - { - $instance = $this->subjectsService->createInstance($class, $label); - $this->assertIsA($instance, 'core_kernel_classes_Resource'); - $this->assertEquals($label, $instance->getLabel()); - - $instance->removePropertyValues(new \core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL)); - $instance->setLabel($label); - - - $this->assertIsA($instance, 'core_kernel_classes_Resource'); - $this->assertEquals($label, $instance->getLabel()); - return $instance; - } - - /** - * @depends testInstantiateClass - * @param \core_kernel_classes_Resource $instance - */ - public function testSetTestTakerRole($instance) - { - $this->subjectsService->setTestTakerRole($instance); - $propertyRoles = new \core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_ROLES); - $values = $instance->getPropertyValues($propertyRoles); - $this->assertEquals($values[0], TaoOntology::PROPERTY_INSTANCE_ROLE_DELIVERY); - } - - /** - * @depends testInstantiateClass - * @param $instance - * @expectedException \core_kernel_classes_EmptyProperty - */ - public function testFailClone($instance) - { - $this->subjectsService->cloneInstance($instance); - } - - /** - * @depends testInstantiateClass - * @param \core_kernel_classes_Resource $instance - */ - public function testClone($instance) - { - - $propertyLogin = new \core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_LOGIN); - $instance->setPropertyValue($propertyLogin, 'testUser'); - - $propertyName = new \core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_FIRSTNAME); - $instance->setPropertyValue($propertyName, 'Cool Name'); - - $clone = $this->subjectsService->cloneInstance($instance); - $instanceValues = $instance->getPropertyValues($propertyName); - $cloneValues = $clone->getPropertyValues($propertyName); - $this->assertEquals($instanceValues[0], $cloneValues[0]); - - $instanceValues = $instance->getPropertyValues($propertyLogin); - $cloneValues = $clone->getPropertyValues($propertyLogin); - $this->assertNotEquals($instanceValues[0], $cloneValues[0]); - - $this->assertNotEquals($instance, $clone); - $this->assertTrue($this->subjectsService->deleteSubject($clone)); - $this->assertFalse($clone->exists()); - - } - - - /** - * @depends testSubClassCreate - * @param $class - */ - public function testDeleteClass($class) - { - $this->assertTrue($this->subjectsService->deleteClass($class)); - $this->assertFalse($class->exists()); - } - - /** - * @depends testInstantiateClass - * @depends testInstantiateSubClass - * @param \core_kernel_classes_Resource $instance - */ - public function testDeleteInstance($instance1, $instance2) - { - $this->assertTrue($this->subjectsService->deleteSubject($instance1)); - $this->assertFalse($instance1->exists()); - - $this->assertTrue($this->subjectsService->deleteSubject($instance2)); - $this->assertFalse($instance2->exists()); - - } - - + + * @package taoTestTaker + */ +class TestTakerTest extends TaoPhpUnitTestRunner +{ + + /** + * @var TestTakerService + */ + protected $subjectsService = null; + + /** + * tests initialization + * + * @return void + */ + public function setUp() + { + TaoPhpUnitTestRunner::initTest(); + // load constants + \common_ext_ExtensionsManager::singleton()->getExtensionById('taoTestTaker'); + $this->subjectsService = TestTakerService::singleton(); + } + + /** + * Test the user service implementation + * @see tao_models_classes_ServiceFactory::get + * @see TestTakerService::__construct + * @return void + */ + public function testService() + { + $this->assertIsA($this->subjectsService, '\tao_models_classes_Service'); + $this->assertIsA($this->subjectsService, 'oat\taoTestTaker\models\TestTakerService'); + } + + /** + * @return \core_kernel_classes_Class|null + */ + public function testGetRootClass() + { + $subjectClass = $this->subjectsService->getRootClass(); + $this->assertIsA($subjectClass, 'core_kernel_classes_Class'); + $this->assertEquals(TaoOntology::SUBJECT_CLASS_URI, $subjectClass->getUri()); + + $this->assertTrue($this->subjectsService->isSubjectClass($subjectClass)); + + return $subjectClass; + } + + /** + * @depends testGetRootClass + * @param $subjectClass + * @return \core_kernel_classes_Class + */ + public function testSubClassCreate($subjectClass) + { + $subSubjectClassLabel = 'subSubject class'; + $subSubjectClass = $this->subjectsService->createSubClass($subjectClass, $subSubjectClassLabel); + $this->assertIsA($subSubjectClass, 'core_kernel_classes_Class'); + $this->assertEquals($subSubjectClassLabel, $subSubjectClass->getLabel()); + + $this->assertTrue($this->subjectsService->isSubjectClass($subSubjectClass)); + + return $subSubjectClass; + } + + /** + * @depends testGetRootClass + * @param $class + * @return \core_kernel_classes_Resource + */ + public function testInstantiateClass($class) + { + $subjectInstanceLabel = 'subject instance'; + return $this->instantiateClass($class, $subjectInstanceLabel); + } + + /** + * @depends testSubClassCreate + * @param $class + * @return \core_kernel_classes_Resource + */ + public function testInstantiateSubClass($class) + { + $subSubjectInstanceLabel = 'subSubject instance'; + return $this->instantiateClass($class, $subSubjectInstanceLabel); + } + + /** + * @param $class + * @param $label + * @return \core_kernel_classes_Resource + */ + protected function instantiateClass($class, $label) + { + $instance = $this->subjectsService->createInstance($class, $label); + $this->assertIsA($instance, 'core_kernel_classes_Resource'); + $this->assertEquals($label, $instance->getLabel()); + + $instance->removePropertyValues(new \core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL)); + $instance->setLabel($label); + + + $this->assertIsA($instance, 'core_kernel_classes_Resource'); + $this->assertEquals($label, $instance->getLabel()); + return $instance; + } + + /** + * @depends testInstantiateClass + * @param \core_kernel_classes_Resource $instance + */ + public function testSetTestTakerRole($instance) + { + $this->subjectsService->setTestTakerRole($instance); + $propertyRoles = new \core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_ROLES); + $values = $instance->getPropertyValues($propertyRoles); + $this->assertEquals($values[0], TaoOntology::PROPERTY_INSTANCE_ROLE_DELIVERY); + } + + /** + * @depends testInstantiateClass + * @param $instance + * @expectedException \core_kernel_classes_EmptyProperty + */ + public function testFailClone($instance) + { + $this->subjectsService->cloneInstance($instance); + } + + /** + * @depends testInstantiateClass + * @param \core_kernel_classes_Resource $instance + */ + public function testClone($instance) + { + + $propertyLogin = new \core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_LOGIN); + $instance->setPropertyValue($propertyLogin, 'testUser'); + + $propertyName = new \core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_FIRSTNAME); + $instance->setPropertyValue($propertyName, 'Cool Name'); + + $clone = $this->subjectsService->cloneInstance($instance); + $instanceValues = $instance->getPropertyValues($propertyName); + $cloneValues = $clone->getPropertyValues($propertyName); + $this->assertEquals($instanceValues[0], $cloneValues[0]); + + $instanceValues = $instance->getPropertyValues($propertyLogin); + $cloneValues = $clone->getPropertyValues($propertyLogin); + $this->assertNotEquals($instanceValues[0], $cloneValues[0]); + + $this->assertNotEquals($instance, $clone); + $this->assertTrue($this->subjectsService->deleteSubject($clone)); + $this->assertFalse($clone->exists()); + + } + + + /** + * @depends testSubClassCreate + * @param $class + */ + public function testDeleteClass($class) + { + $this->assertTrue($this->subjectsService->deleteClass($class)); + $this->assertFalse($class->exists()); + } + + /** + * @depends testInstantiateClass + * @depends testInstantiateSubClass + * @param \core_kernel_classes_Resource $instance + */ + public function testDeleteInstance($instance1, $instance2) + { + $this->assertTrue($this->subjectsService->deleteSubject($instance1)); + $this->assertFalse($instance1->exists()); + + // @todo fix deletion (returns false) + $this->assertTrue($this->subjectsService->deleteSubject($instance2)); + $this->assertFalse($instance2->exists()); + } } \ No newline at end of file From 3276c58fb26784de82fcdd5bae6bc1c659baa64f Mon Sep 17 00:00:00 2001 From: alexey Date: Wed, 8 Aug 2018 17:47:55 +0300 Subject: [PATCH 2/4] Changed version after fixing tests --- manifest.php | 2 +- scripts/update/Updater.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.php b/manifest.php index 69bba823..162e9072 100755 --- a/manifest.php +++ b/manifest.php @@ -33,7 +33,7 @@ 'label' => 'Test-taker core extension', 'description' => 'TAO TestTaker extension', 'license' => 'GPL-2.0', - 'version' => '3.10.0', + 'version' => '3.10.1', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => array( 'tao' => '>=19.11.0', diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index 8595ae2a..24be4ebb 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -83,6 +83,6 @@ public function update($initialVersion) $this->setVersion('3.7.0'); } - $this->skip('3.7.0', '3.10.0'); + $this->skip('3.7.0', '3.10.1'); } } From abb7c925751b0bca8874a8696af1f562bbcbcc1e Mon Sep 17 00:00:00 2001 From: bugalot Date: Thu, 9 Aug 2018 13:10:35 +0200 Subject: [PATCH 3/4] Fix wrong test case. --- test/integration/RestTestTakerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/RestTestTakerTest.php b/test/integration/RestTestTakerTest.php index 02e3e610..98e62305 100755 --- a/test/integration/RestTestTakerTest.php +++ b/test/integration/RestTestTakerTest.php @@ -22,8 +22,8 @@ use oat\tao\model\TaoOntology; use oat\generis\model\GenerisRdf; -use oat\tao\test\RestTestCase; use \core_kernel_users_Service; +use oat\tao\test\integration\RestTestCase; /** * connects as a client agent on the rest controller From 3c1629b708ff18f8086c5f75cc91658c1923817c Mon Sep 17 00:00:00 2001 From: bugalot Date: Thu, 9 Aug 2018 13:11:08 +0200 Subject: [PATCH 4/4] Bump version 3.10.2 --- manifest.php | 2 +- scripts/update/Updater.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.php b/manifest.php index 162e9072..e499a33f 100755 --- a/manifest.php +++ b/manifest.php @@ -33,7 +33,7 @@ 'label' => 'Test-taker core extension', 'description' => 'TAO TestTaker extension', 'license' => 'GPL-2.0', - 'version' => '3.10.1', + 'version' => '3.10.2', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => array( 'tao' => '>=19.11.0', diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index 24be4ebb..9e372e02 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -83,6 +83,6 @@ public function update($initialVersion) $this->setVersion('3.7.0'); } - $this->skip('3.7.0', '3.10.1'); + $this->skip('3.7.0', '3.10.2'); } }