Skip to content

Commit

Permalink
Merge pull request #14 from BlockScore/fix/add_optional_time_limit
Browse files Browse the repository at this point in the history
Fix optional time_limit access in create of question sets #11
  • Loading branch information
alainmeier committed Mar 24, 2016
2 parents 5ecb8e3 + c7753de commit 30cd78a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.2
4.0.3
6 changes: 4 additions & 2 deletions lib/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions lib/QuestionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/QuestionSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 30cd78a

Please sign in to comment.