From c7753de2b8b5ab64a2ff82caed81ee7fdf8a80cf Mon Sep 17 00:00:00 2001 From: Tim Chambers Date: Thu, 24 Mar 2016 13:14:51 -0700 Subject: [PATCH] Fix optional time_limit access in create of question sets #11 Optional time_limit value was not provided access by PHP. Add test to verify access to time_limit. Add test to confirm expired response. Bump to v4.0.3 --- VERSION | 2 +- lib/ApiResource.php | 6 ++++-- lib/QuestionSet.php | 6 ++++-- tests/QuestionSetTest.php | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 4d54dad..c4e41f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.2 +4.0.3 diff --git a/lib/ApiResource.php b/lib/ApiResource.php index 054ad44..54b1c91 100644 --- a/lib/ApiResource.php +++ b/lib/ApiResource.php @@ -159,12 +159,14 @@ protected function _search() } /** + * @param Integer $time_limit seconds before question set expires. + * * @return QuestionSet The created QuestionSet. */ - protected function _createQuestionSet() + protected function _createQuestionSet($time_limit) { $url = static::classUrl(); - $params = array('person_id' => $this->id); + $params = array('person_id' => $this->id, 'time_limit' => $time_limit); $response = static::_makeRequest('post', $url, $params); $qs_obj = Util\Util::convertToBlockScoreObject($response); $this->addExisting($qs_obj); diff --git a/lib/QuestionSet.php b/lib/QuestionSet.php index a7f0746..b555bca 100644 --- a/lib/QuestionSet.php +++ b/lib/QuestionSet.php @@ -18,11 +18,13 @@ public function __construct($id) } /** + * @param Integer $time_limit seconds before question set expires. + * * @return QuestionSet The created QuestionSet. */ - public function create() + public function create($time_limit = 0) { - return self::_createQuestionSet(); + return self::_createQuestionSet($time_limit); } /** diff --git a/tests/QuestionSetTest.php b/tests/QuestionSetTest.php index 83244d0..bdedd2d 100644 --- a/tests/QuestionSetTest.php +++ b/tests/QuestionSetTest.php @@ -35,6 +35,24 @@ public function testCreateQuestionSet() } } + public function testCreateQuestionSetWithTimeLimit() + { + $person = self::createTestPerson(); + $qs = $person->question_sets->create(17); + + $this->assertSame($qs->time_limit, 17); + } + + public function testTimeLimitExpired() + { + $person = self::createTestPerson(); + $qs = $person->question_sets->create(2); + sleep(4); + + $retrieved_qs = $person->question_sets->retrieve($qs->id); + $this->assertSame($retrieved_qs->expired, true); + } + public function testAllQuestionSet() { $person = self::createTestPerson();