GemsTracker

GEneric Medical Survey Tracker

User Tools

Site Tools


Sidebar

Quick Links

Main site / download

API Docs
Bug tracker
Demo site
GitHub

Index

devzone:testing:project:eventsurveycompleted

EventSurveyCompletedAbstract

The class allows for very quick testing of Survey Completed events. The assumption is that the score script uses only `getRawAnswers()` from the token object. If not, have a look at the abstract class to create a more complex stub.

The only two methods you need to implement are:

public function getEventClass() This method should return your Event class.

public function surveyDataProvider() Next you have to provide the test cases with input data and expected result of your `processTokenData`. The input data can be obtained by assigning the DisplayVars event to your survey and checking for answers. That way you can just copy/paste some real survey data.

Our full test class for the BmiCalculation script in the GemsTracker core would look like this (and is included as an example in the test library):

<?php
class BMITest extends Gems_Test_EventSurveyCompletedAbstract {
 
    /**
     * Return the Event to test
     * 
     * @return Gems_Event_SurveyCompletedEventInterface
     */
    public function getEventClass() {
        return new Gems_Event_Survey_Completed_BmiCalculation();
    }
 
    /**
     * Should return an array of arrays, containing two elements, first the input tokendata and second the expected output
     * 
     * @return array
     */
    public function surveyDataProvider() {
        return array(
            array(
                array(
                    'id'            => 1,
                    'submitdate'    => '2013-05-28 15:32:40',
                    'lastpage'      => 2,
                    'startlanguage' => 'nl',
                    'token'         => '4d7v_q544',
                    'datestamp'     => '2013-05-28 15:32:40',
                    'startdate'     => '2013-05-28 15:32:40',
                    'LENGTH'        => 185,
                    'WEIGHT'        => 78,
                    'BMI'           => null
                ),
                array('BMI' => 22.79)),
            array(
                array(
                    'id'            => 1,
                    'submitdate'    => '2013-05-28 15:32:40',
                    'lastpage'      => 2,
                    'startlanguage' => 'nl',
                    'token'         => '4d7v_q544',
                    'datestamp'     => '2013-05-28 15:32:40',
                    'startdate'     => '2013-05-28 15:32:40',
                    'LENGTH'        => 165,
                    'WEIGHT'        => 70,
                    'BMI'           => null
                ),
                array('BMI' => 25.71))
        );
    }
 
}
devzone/testing/project/eventsurveycompleted.txt · Last modified: 2020/03/12 12:06 (external edit)