Changeset 4141a27 in iPeer


Ignore:
Timestamp:
2013-01-03T12:06:52-08:00 (6 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
025352e, c73a6cfd
Parents:
b84cd62 (diff), 194d9cd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'dev' into hotfix

Location:
app
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • app/models/question.php

    rb84cd62 r4141a27  
    3737    public $actsAs = array('ExtendAssociations', 'Containable', 'Habtamable');
    3838
    39 
    40     /**
    41      * sets the data variable up with proper formating in the array for display
    42      *
    43      * @param array $data : $data obtained as return value from
    44      *                                    SurveyQuestion::getQuestionsID($survey_id);
    45      *
    46      * @access public
    47      * @return void
    48      */
    49     function fillQuestion($data)
    50     {
    51         for ($i=0; $i<count($data); $i++) {
    52             $data[$i]['Question'] = $this->find('all', array('conditions' => array('id' => $data[$i]['SurveyQuestion']['question_id']),
    53                 'fields' => array('prompt', 'type')));
    54             $data[$i]['Question'] = $data[$i]['Question'][0]['Question'];
    55             $data[$i]['Question']['number'] = $data[$i]['SurveyQuestion']['number'];
    56             $data[$i]['Question']['id'] = $data[$i]['SurveyQuestion']['question_id'];
    57             $data[$i]['Question']['sq_id'] = $data[$i]['SurveyQuestion']['id'];
    58             unset($data[$i]['SurveyQuestion']);
    59         }
    60         return $data;
    61     }
    62 
    63 
    6439    /**
    6540     * getTypeById
  • app/models/response.php

    rb84cd62 r4141a27  
    1313    public $name = 'Response';
    1414    public $belongsTo = array('Question');
    15 
    16     /**
    17      * fillResponse
    18      * prepares the data public with all the response info from the form for display
    19      *
    20      * @param mixed $data
    21      *
    22      * @access public
    23      * @return void
    24      */
    25     function fillResponse($data)
    26     {
    27         for ($i=0; $i<count($data); $i++) {
    28             $tmp = $this->find('all', array('conditions' => array('question_id' => $data[$i]['Question']['id']),
    29                 'fields' => array('response', 'id')));
    30             $count = count($tmp);
    31             for ($j=0; $j<$count; $j++) {
    32                 if (!empty($tmp)) {
    33                     $data[$i]['Question']['Responses']['response_'.$j]['response'] = $tmp[$j]['Response']['response'];
    34                     $data[$i]['Question']['Responses']['response_'.$j]['id'] = $tmp[$j]['Response']['id'];
    35                 }
    36             }
    37         }
    38         return $data;
    39     }
    4015
    4116
  • app/tests/cases/controllers/evaluations_controller.test.php

    rb84cd62 r4141a27  
    161161        );
    162162
    163         // rubric evaluation
    164163        $result = $this->testAction('/evaluations/makeEvaluation/4', array('return' => 'vars'));
    165164        $this->assertEqual($result['eventId'], 4);
    166165        $this->assertEqual($result['courseId'], 1);
    167         $this->assertEqual(count($result['questions']), 2);
    168         $this->assertEqual($result['questions'][0]['Question']['prompt'], 'What was your GPA last term?');
    169         $this->assertEqual($result['questions'][1]['Question']['prompt'], 'Do you own a laptop?');
    170         $this->assertEqual(count($result['questions'][0]['Question']['Responses']), 4);
    171         $this->assertEqual(count($result['questions'][1]['Question']['Responses']), 2);
     166        $this->assertEqual(count($result['survey']['Question']), 2);
     167        $this->assertEqual($result['survey']['Question'][0]['prompt'], 'What was your GPA last term?');
     168        $this->assertEqual($result['survey']['Question'][1]['prompt'], 'Do you own a laptop?');
     169        $this->assertEqual(count($result['survey']['Question'][0]['Response']), 4);
     170        $this->assertEqual(count($result['survey']['Question'][1]['Response']), 2);
    172171        $message = $this->controller->Session->read('Message.flash');
    173172        $this->assertEqual($message['message'], '');
  • app/tests/cases/models/question.test.php

    rb84cd62 r4141a27  
    3939    }
    4040
    41     function testFillQuestion()
    42     {
    43         $data = $this->SurveyQuestion->find('all', array('conditions'=> array('survey_id' => 1),
    44             'fields' => array('number', 'question_id', 'id'),
    45             'order' => 'number'));
    46         $ret = $this->Question->fillQuestion($data);
    47         // Compare the result with fixture data
    48         $firstQuestion = $ret[0]['Question'];
    49         $this->assertEqual($firstQuestion['prompt'], 'What was your GPA last term?');
    50         $this->assertEqual($firstQuestion['id'], 1);
    51         $this->assertEqual($firstQuestion['number'], 1);
    52         $secondQuestion = $ret[1]['Question'];
    53         $this->assertEqual($secondQuestion['prompt'], 'Do you own a laptop?');
    54         $this->assertEqual($secondQuestion['id'], 2);
    55         $this->assertEqual($secondQuestion['number'], 2);
    56         // Check that Survey Question has been unset
    57         $this->assertFalse(isset($firstQuestion['SurveyQuestion']));
    58         $this->assertFalse(isset($secondQuestion['SurveyQuestion']));
    59     }
    60 
    6141    function testGetTypeById()
    6242    {
  • app/tests/cases/models/response.test.php

    rb84cd62 r4141a27  
    4040    }
    4141
    42     function testFillQuestion()
    43     {
    44         $data = $this->SurveyQuestion->find('all', array('conditions'=> array('survey_id' => 1),
    45             'fields' => array('number', 'question_id', 'id'),
    46             'order' => 'number'));
    47         $ret = $this->Question->fillQuestion($data);
    48         // Assert reponse index didn't exist in the input prior to calling fillResponse
    49         $this->assertTrue(empty($ret[0]['Question']['Responses']['response_0']['response']));
    50         $this->assertTrue(empty($ret[1]['Question']['Responses']['response_0']['response']));
    51         $result = $this->Response->fillResponse($ret);
    52         // Assert that responses index are merged with array
    53         $this->assertEqual($result[0]['Question']['Responses']['response_0']['response'], '4+');
    54         $this->assertEqual($result[0]['Question']['Responses']['response_0']['id'], 1);
    55         $this->assertEqual($result[0]['Question']['Responses']['response_1']['response'], '3-4');
    56         $this->assertEqual($result[0]['Question']['Responses']['response_1']['id'], 2);
    57         $this->assertEqual($result[0]['Question']['Responses']['response_2']['response'], '2-3');
    58         $this->assertEqual($result[0]['Question']['Responses']['response_2']['id'], 3);
    59         $this->assertEqual($result[0]['Question']['Responses']['response_3']['response'], '<2');
    60         $this->assertEqual($result[0]['Question']['Responses']['response_3']['id'], 4);
    61         $this->assertEqual($result[1]['Question']['Responses']['response_0']['response'], 'yes');
    62         $this->assertEqual($result[1]['Question']['Responses']['response_0']['id'], 5);
    63         $this->assertEqual($result[1]['Question']['Responses']['response_1']['response'], 'no');
    64         $this->assertEqual($result[1]['Question']['Responses']['response_1']['id'], 6);
    65     }
    66 
    6742    function testGetResponseByQuestionId()
    6843    {
Note: See TracChangeset for help on using the changeset viewer.