Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Test the behaviour of summarise_response().
- *
- * @dataProvider summarise_response_text_attachments_provider
- * @param integer $responserequired 0 or 1 depending on if the response is required or not.
- * @param integer $attachmentsrequired Number or attachments required; -1 is unlimited.
- * @param integer $filesattached Number of files attached.
- * @return void
- */
- public function test_summarise_response_text_attachments(int $responserequired, int $attachmentsrequired, int $filesattached): void {
- $this->resetAfterTest();
- // Create sample attachments.
- $attachments = $this->create_user_and_sample_attachments($filesattached);
- // Create the essay question under test.
- $essay = test_question_maker::make_an_essay_question();
- $essay->start_attempt(new question_attempt_step(), 1);
- $essay->responserequired = $responserequired;
- $essay->attachmentsrequired = $attachmentsrequired;
- $essay->responseformat = 'editor';
- $textanswer = '';
- $expected = '';
- if ($responserequired) {
- $textanswer = 'This is the text input for my essay.';
- $expected .= $textanswer;
- }
- if ($filesattached) {
- $expected .= 'Attachments:';
- for ($i = 0; $i < $filesattached; $i++) {
- if ($i > 0) {
- $expected .= ',';
- }
- $expected .= " $i (1 bytes)";
- $result = $essay->summarise_response(
- ['answer' => $textanswer, 'answerformat' => FORMAT_HTML, 'attachments' => $attachments[$i + 1]]
- );
- $this->assertEquals($expected, $result);
- }
- }
- }
- /**
- * Data provider for test_summarise_response_text_attachments().
- *
- * @return array
- */
- public function summarise_response_text_attachments_provider(): array {
- return [
- 'Text required, 1 attachments required' => [
- 'responserequired' => 1,
- 'attachmentsrequired' => 1,
- 'filesattached' => 4,
- ],
- 'Text not required, 4 attachments required' => [
- 'responserequired' => 0,
- 'attachmentsrequired' => 4,
- 'filesattached' => 4,
- ],
- 'Text not required, 4 attachments required' => [
- 'responserequired' => 0,
- 'attachmentsrequired' => -1,
- 'filesattached' => 2,
- ],
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement