Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/engine/simpletest/testquestionattemptiterator.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once(dirname(__FILE__) . '/../lib.php');
00030 require_once(dirname(__FILE__) . '/helpers.php');
00031 
00032 
00039 class question_attempt_iterator_test extends UnitTestCase {
00040     private $quba;
00041     private $qas = array();
00042     private $iterator;
00043 
00044     public function setUp() {
00045         $this->quba = question_engine::make_questions_usage_by_activity('unit_test',
00046                 get_context_instance(CONTEXT_SYSTEM));
00047         $this->quba->set_preferred_behaviour('deferredfeedback');
00048 
00049         $slot = $this->quba->add_question(test_question_maker::make_question('description'));
00050         $this->qas[$slot] = $this->quba->get_question_attempt($slot);
00051 
00052         $slot = $this->quba->add_question(test_question_maker::make_question('description'));
00053         $this->qas[$slot] = $this->quba->get_question_attempt($slot);
00054 
00055         $this->iterator = $this->quba->get_attempt_iterator();
00056     }
00057 
00058     public function tearDown() {
00059         $this->quba = null;
00060         $this->iterator = null;
00061     }
00062 
00063     public function test_foreach_loop() {
00064         $i = 1;
00065         foreach ($this->iterator as $key => $qa) {
00066             $this->assertEqual($i, $key);
00067             $this->assertIdentical($this->qas[$i], $qa);
00068             $i++;
00069         }
00070         $this->assertEqual(3, $i);
00071     }
00072 
00073     public function test_offsetExists_before_start() {
00074         $this->assertFalse(isset($this->iterator[0]));
00075     }
00076 
00077     public function test_offsetExists_at_start() {
00078         $this->assertTrue(isset($this->iterator[1]));
00079     }
00080 
00081     public function test_offsetExists_at_endt() {
00082         $this->assertTrue(isset($this->iterator[2]));
00083     }
00084 
00085     public function test_offsetExists_past_end() {
00086         $this->assertFalse(isset($this->iterator[3]));
00087     }
00088 
00089     public function test_offsetGet_before_start() {
00090         $this->expectException();
00091         $step = $this->iterator[0];
00092     }
00093 
00094     public function test_offsetGet_at_start() {
00095         $this->assertIdentical($this->qas[1], $this->iterator[1]);
00096     }
00097 
00098     public function test_offsetGet_at_end() {
00099         $this->assertIdentical($this->qas[2], $this->iterator[2]);
00100     }
00101 
00102     public function test_offsetGet_past_end() {
00103         $this->expectException();
00104         $step = $this->iterator[3];
00105     }
00106 
00107     public function test_cannot_set() {
00108         $this->expectException();
00109         $this->iterator[0] = null;
00110     }
00111 
00112     public function test_cannot_unset() {
00113         $this->expectException();
00114         unset($this->iterator[2]);
00115     }
00116 }
 All Data Structures Namespaces Files Functions Variables Enumerations