Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optional time_limit access in create of question sets #11 #14

Merged
merged 1 commit into from
Mar 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sleep is necessary right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - we are proving that a short time limit expires and the client receives the expired flag properly set as NOW expired. I made it short, but it still adds briefly to the test run. But it confirms that it is returned AND it is accessible to the client code.


$retrieved_qs = $person->question_sets->retrieve($qs->id);
$this->assertSame($retrieved_qs->expired, true);
}

public function testAllQuestionSet()
{
$person = self::createTestPerson();
Expand Down