PageRenderTime 23ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/question/tests/Question_ChoiceTest.php

https://github.com/kodeplay/kodelearn
PHP | 92 lines | 84 code | 5 blank | 3 comment | 0 complexity | b4a518cddc59613fa1e1d472ca7e0f34 MD5 | raw file
  1. <?php defined('SYSPATH') or die('No direct access allowed.');
  2. class Question_ChoiceTest extends Kohana_UnitTest_TestCase {
  3. public function test_process_attrs() {
  4. // for answers
  5. $formdata = array(
  6. 'choice' => array(
  7. 'question1',
  8. 'question2'
  9. ),
  10. 'correct' => array(
  11. '1',
  12. '0'
  13. ),
  14. 'explain' => array(
  15. 'hello world',
  16. 'hello kodelearn'
  17. )
  18. );
  19. $question = Question::factory('choice');
  20. $attributes = $question->process_attrs($formdata);
  21. $this->assertEquals($attributes, array(
  22. 0 => array(
  23. 'attribute_name' => 'choice',
  24. 'attribute_value' => 'question1',
  25. 'correctness' => '1',
  26. 'explanation' => 'hello world'
  27. ),
  28. 1 => array(
  29. 'attribute_name' => 'choice',
  30. 'attribute_value' => 'question2',
  31. 'correctness' => '0',
  32. 'explanation' => 'hello kodelearn'
  33. )
  34. ));
  35. }
  36. public function test_subtype() {
  37. $attributes = array(
  38. 0 => array(
  39. 'attribute_name' => 'choice',
  40. 'attribute_value' => 'question1',
  41. 'correctness' => '1',
  42. 'explanation' => 'hello world'
  43. ),
  44. 1 => array(
  45. 'attribute_name' => 'choice',
  46. 'attribute_value' => 'question2',
  47. 'correctness' => '0',
  48. 'explanation' => 'hello kodelearn'
  49. )
  50. );
  51. $question = Question::factory('choice');
  52. $this->assertEquals($question->choice_type($attributes), 'unique');
  53. $attributes = array(
  54. 0 => array(
  55. 'attribute_name' => 'choice',
  56. 'attribute_value' => 'question1',
  57. 'correctness' => '1',
  58. 'explanation' => 'hello world'
  59. ),
  60. 1 => array(
  61. 'attribute_name' => 'choice',
  62. 'attribute_value' => 'question2',
  63. 'correctness' => '0',
  64. 'explanation' => 'hello kodelearn'
  65. ),
  66. 1 => array(
  67. 'attribute_name' => 'choice',
  68. 'attribute_value' => 'question3',
  69. 'correctness' => '1',
  70. 'explanation' => 'hello kodelearn'
  71. )
  72. );
  73. $this->assertEquals($question->choice_type($attributes), 'multiple');
  74. }
  75. // TODO testing using a test database
  76. public function test_check_answer() {
  77. // try to load a question of type choice
  78. $ques = ORM::factory('question', 2);
  79. $question = Question::factory($ques);
  80. $submitted = array(4);
  81. $this->assertTrue($question->check_answer($submitted));
  82. $ques = ORM::factory('question', 1);
  83. $question = Question::factory($ques);
  84. $submitted = array('echo', 'print_r');
  85. $this->assertTrue($question->check_answer($submitted));
  86. }
  87. }