<commit_before><?php
/******************
 * If got Maximum function nesting level of '100' reached
 * Change xdebug.max_nesting_level=200 and max_input_nesting_level=200 in
 * php.ini
 *
 * Details about ExtendedTestCase:
 * http://42pixels.com/blog/testing-controllers-the-slightly-less-hard-way
 */

App::import('Controller', 'Events');
App::import('Lib', 'ExtendedAuthTestCase');

// mock instead of needing to create a new controller for every test
Mock::generatePartial('EventsController',
    'MockEventsController',
    array('isAuthorized', 'render', 'redirect', '_stop', 'header'));

/**
 * EventsControllerTest
 *
 * @uses ExtendedAuthTestCase
 * @package Tests
 * @author  <NAME> <<EMAIL>>
 */
class EventsControllerTest extends ExtendedAuthTestCase {
    public $controller = null;

    public $fixtures = array(
        'app.course', 'app.role', 'app.user', 'app.group',
        'app.roles_user', 'app.event', 'app.event_template_type',
        'app.group_event', 'app.evaluation_submission',
        'app.survey_group_set', 'app.survey_group',
        'app.survey_group_member', 'app.question',
        'app.response', 'app.survey_question', 'app.user_course',
        'app.user_enrol', 'app.groups_member', 'app.survey',
        'app.personalize', 'app.penalty', 'app.evaluation_simple',
        'app.faculty', 'app.user_tutor', 'app.course_department',
        'app.evaluation_rubric', 'app.evaluation_rubric_detail',
        'app.evaluation_mixeval', 'app.evaluation_mixeval_detail',
        'app.user_faculty', 'app.department', 'app.sys_parameter',
        'app.oauth_token', 'app.rubric', 'app.rubrics_criteria',
        'app.rubrics_criteria_comment', 'app.rubrics_lom',
        'app.simple_evaluation', 'app.survey_input', 'app.mixevals_question',
        'app.mixevals_question_desc', 'app.mixeval'
    );

    function startCase() {
        echo "Start Event controller test.\n";
        $this->defaultLogin = array(
            'User' => array(
                'username' => 'root',
                'password' => <PASSWORD>('<PASSWORD>')
            )
        );
    }

    function endCase() {
    }

    function startTest($method) {
        echo $method.TEST_LB;
        $this->controller = new MockEventsController();
    }

    public function endTest($method)
    {
        // defer logout to end of the test as some of the test need check flash
        // message. After logging out, message is destoryed.
        if (isset($this->controller->Auth)) {
            $this->controller->Auth->logout();
        }
        unset($this->controller);
        ClassRegistry::flush();
    }

    public function getController()
    {
        return $this->controller;
    }

    function testIndex() {
        $result = $this->testAction('/events/index', array('return' => 'vars'));

        $this->assertEqual(count($result["paramsForList"]['data']['entries']), 7);
        $this->assertEqual(sort(Set::extract($result["paramsForList"]['data']['entries'], '/Event/id')), array(1,2,3,6));
        $events = Set::sort($result["paramsForList"]['data']['entries'], '{n}.Event.id', 'asc');
        $this->assertEqual($events[0]['Event']['Title'], 'Term 1 Evaluation');
        $this->assertEqual($events[0]['Event']['event_template_type_id'], 1);
        $this->assertEqual($events[0]['Course']['course'], 'MECH 328');
        $this->assertEqual($events[0]['!Custom']['isReleased'], 'Open Now');

        $this->assertEqual($events[1]['Event']['Title'], 'Term Report Evaluation');
        $this->assertEqual($events[1]['Event']['event_template_type_id'], 2);
        $this->assertEqual($events[1]['Course']['course'], 'MECH 328');
        $this->assertEqual($events[1]['!Custom']['isReleased'], 'Open Now');

        $this->assertEqual($events[2]['Event']['Title'], 'Project Evaluation');
        $this->assertEqual($events[2]['Event']['event_template_type_id'], 4);
        $this->assertEqual($events[2]['Course']['course'], 'MECH 328');
        $this->assertEqual($events[2]['!Custom']['isReleased'], 'Open Now');

    }

    function testView() {
        $result = $this->testAction('/events/view/1', array('return' => 'vars'));

        $this->assertEqual($result['event']['Course']['full_name'], 'MECH 328 - Mechanical Engineering Design Project');
        $this->assertEqual($result['event']['Event']['title'], 'Term 1 Evaluation');
        $this->assertEqual($result['event']['Event']['event_template_type_id'], 1);
        $this->assertEqual(count($result['event']['Group']), 2);
        $groups = Set::sort($result['event']['Group'], '{n}.id', 'asc');
        $this->assertEqual($groups[0]['id'], 1);
        $this->assertEqual($groups[0]['group_name'], 'Reapers');
        $this->assertEqual(count($groups[0]['Member']), 4);
        $this->assertEqual($groups[1]['id'], 2);
        $this->assertEqual($groups[1]['group_name'], 'Lazy Engineers');
        $this->assertEqual(count($groups[1]['Member']), 4);
        $this->assertEqual($result['event']['SimpleEvaluation']['id'], 1);
        $this->assertEqual($result['event']['SimpleEvaluation']['name'], 'Module 1 Project Evaluation');
        $penalties = Set::sort($result['event']['Penalty'], '{n}.id', 'asc');
        $this->assertEqual(Set::extract($penalties, '/id'), array(1,2,3,4));
        $this->assertEqual(Set::extract($penalties, '/days_late'), array(1,2,3,4));
        $this->assertEqual($result['event']['EventTemplateType']['id'], 1);
        $this->assertEqual($result['event']['EventTemplateType']['type_name'], 'SIMPLE');

        $result = $this->testAction('/events/view/2', array('return' => 'vars'));

        $this->assertEqual($result['event']['Event']['title'], 'Term Report Evaluation');
        $this->assertEqual($result['event']['Event']['event_template_type_id'], 2);
        $this->assertEqual($result['event']['Group'][0]['group_name'], 'Reapers');
        $this->assertEqual($result['event']['Group'][0]['Member'][0]['first_name'], 'Ed');
        $this->assertEqual($result['event']['Group'][0]['Member'][0]['last_name'], 'Student');
    }

    function testAdd() {
        $result = $this->testAction('/events/add/1', array('return' => 'vars'));

        // make sure the correct course
        $this->assertEqual($result['course_id'], 1);
        // available evaluations
        $this->assertEqual($result['rubrics'][1], 'Term Report Evaluation');
        $this->assertEqual($result['simpleEvaluations'][1], 'Module 1 Project Evaluation');
        $this->assertEqual($result['mixevals'][1], 'Default Mix Evalution');
        // evauation types
        $this->assertEqual(count($result['eventTemplateTypes']), 3);
        // course list
        ksort($result['courses']);
        $this->assertEqual($result['courses'], array(
            1 => 'MECH 328 - Mechanical Engineering Design Project',
            2 => 'APSC 201 - Technical Communication',
        ));
        // group list
        ksort($result['groups']);
        $this->assertEqual($result['groups'], array(
            1 => 'Reapers',
            2 => 'Lazy Engineers',
        ));
    }<commit_msg>Fix event controller test to account for surveys.<commit_after><?php
/******************
 * If got Maximum function nesting level of '100' reached
 * Change xdebug.max_nesting_level=200 and max_input_nesting_level=200 in
 * php.ini
 *
 * Details about ExtendedTestCase:
 * http://42pixels.com/blog/testing-controllers-the-slightly-less-hard-way
 */

App::import('Controller', 'Events');
App::import('Lib', 'ExtendedAuthTestCase');

// mock instead of needing to create a new controller for every test
Mock::generatePartial('EventsController',
    'MockEventsController',
    array('isAuthorized', 'render', 'redirect', '_stop', 'header'));

/**
 * EventsControllerTest
 *
 * @uses ExtendedAuthTestCase
 * @package Tests
 * @author  <NAME> <<EMAIL>>
 */
class EventsControllerTest extends ExtendedAuthTestCase {
    public $controller = null;

    public $fixtures = array(
        'app.course', 'app.role', 'app.user', 'app.group',
        'app.roles_user', 'app.event', 'app.event_template_type',
        'app.group_event', 'app.evaluation_submission',
        'app.survey_group_set', 'app.survey_group',
        'app.survey_group_member', 'app.question',
        'app.response', 'app.survey_question', 'app.user_course',
        'app.user_enrol', 'app.groups_member', 'app.survey',
        'app.personalize', 'app.penalty', 'app.evaluation_simple',
        'app.faculty', 'app.user_tutor', 'app.course_department',
        'app.evaluation_rubric', 'app.evaluation_rubric_detail',
        'app.evaluation_mixeval', 'app.evaluation_mixeval_detail',
        'app.user_faculty', 'app.department', 'app.sys_parameter',
        'app.oauth_token', 'app.rubric', 'app.rubrics_criteria',
        'app.rubrics_criteria_comment', 'app.rubrics_lom',
        'app.simple_evaluation', 'app.survey_input', 'app.mixevals_question',
        'app.mixevals_question_desc', 'app.mixeval'
    );

    function startCase() {
        echo "Start Event controller test.\n";
        $this->defaultLogin = array(
            'User' => array(
                'username' => 'root',
                'password' => <PASSWORD>('<PASSWORD>')
            )
        );
    }

    function endCase() {
    }

    function startTest($method) {
        echo $method.TEST_LB;
        $this->controller = new MockEventsController();
    }

    public function endTest($method)
    {
        // defer logout to end of the test as some of the test need check flash
        // message. After logging out, message is destoryed.
        if (isset($this->controller->Auth)) {
            $this->controller->Auth->logout();
        }
        unset($this->controller);
        ClassRegistry::flush();
    }

    public function getController()
    {
        return $this->controller;
    }

    function testIndex() {
        $result = $this->testAction('/events/index', array('return' => 'vars'));

        $this->assertEqual(count($result["paramsForList"]['data']['entries']), 
            9);
        $this->assertEqual(sort(Set::extract($result["paramsForList"]['data']['entries'], '/Event/id')), array(1,2,3,6));
        $events = Set::sort($result["paramsForList"]['data']['entries'], '{n}.Event.id', 'asc');
        $this->assertEqual($events[0]['Event']['Title'], 'Term 1 Evaluation');
        $this->assertEqual($events[0]['Event']['event_template_type_id'], 1);
        $this->assertEqual($events[0]['Course']['course'], 'MECH 328');
        $this->assertEqual($events[0]['!Custom']['isReleased'], 'Open Now');

        $this->assertEqual($events[1]['Event']['Title'], 'Term Report Evaluation');
        $this->assertEqual($events[1]['Event']['event_template_type_id'], 2);
        $this->assertEqual($events[1]['Course']['course'], 'MECH 328');
        $this->assertEqual($events[1]['!Custom']['isReleased'], 'Open Now');

        $this->assertEqual($events[2]['Event']['Title'], 'Project Evaluation');
        $this->assertEqual($events[2]['Event']['event_template_type_id'], 4);
        $this->assertEqual($events[2]['Course']['course'], 'MECH 328');
        $this->assertEqual($events[2]['!Custom']['isReleased'], 'Open Now');

    }

    function testView() {
        $result = $this->testAction('/events/view/1', array('return' => 'vars'));

        $this->assertEqual($result['event']['Course']['full_name'], 'MECH 328 - Mechanical Engineering Design Project');
        $this->assertEqual($result['event']['Event']['title'], 'Term 1 Evaluation');
        $this->assertEqual($result['event']['Event']['event_template_type_id'], 1);
        $this->assertEqual(count($result['event']['Group']), 2);
        $groups = Set::sort($result['event']['Group'], '{n}.id', 'asc');
        $this->assertEqual($groups[0]['id'], 1);
        $this->assertEqual($groups[0]['group_name'], 'Reapers');
        $this->assertEqual(count($groups[0]['Member']), 4);
        $this->assertEqual($groups[1]['id'], 2);
        $this->assertEqual($groups[1]['group_name'], 'Lazy Engineers');
        $this->assertEqual(count($groups[1]['Member']), 4);
        $this->assertEqual($result['event']['SimpleEvaluation']['id'], 1);
        $this->assertEqual($result['event']['SimpleEvaluation']['name'], 'Module 1 Project Evaluation');
        $penalties = Set::sort($result['event']['Penalty'], '{n}.id', 'asc');
        $this->assertEqual(Set::extract($penalties, '/id'), array(1,2,3,4));
        $this->assertEqual(Set::extract($penalties, '/days_late'), array(1,2,3,4));
        $this->assertEqual($result['event']['EventTemplateType']['id'], 1);
        $this->assertEqual($result['event']['EventTemplateType']['type_name'], 'SIMPLE');

        $result = $this->testAction('/events/view/2', array('return' => 'vars'));

        $this->assertEqual($result['event']['Event']['title'], 'Term Report Evaluation');
        $this->assertEqual($result['event']['Event']['event_template_type_id'], 2);
        $this->assertEqual($result['event']['Group'][0]['group_name'], 'Reapers');
        $this->assertEqual($result['event']['Group'][0]['Member'][0]['first_name'], 'Ed');
        $this->assertEqual($result['event']['Group'][0]['Member'][0]['last_name'], 'Student');
    }

    function testAdd() {
        $result = $this->testAction('/events/add/1', array('return' => 'vars'));

        // make sure the correct course
        $this->assertEqual($result['course_id'], 1);
        // available evaluations
        $this->assertEqual($result['rubrics'][1], 'Term Report Evaluation');
        $this->assertEqual($result['simpleEvaluations'][1], 'Module 1 Project Evaluation');
        $this->assertEqual($result['mixevals'][1], 'Default Mix Evalution');
        // evauation types
        $this->assertEqual(count($result['eventTemplateTypes']), 4);
        // course list
        ksort($result['courses']);
        $this->assertEqual($result['courses'], array(
            1 => 'MECH 328 - Mechanical Engineering Design Project',
            2 => 'APSC 201 - Technical Communication',
        ));
        // group list
        ksort($result['groups']);
        $this->assertEqual($result['groups'], array(
            1 => 'Reapers',
            2 => 'Lazy Engineers',
        ));
    }
{'fraction_non_alphanumeric': 0.20537914525100331, 'fraction_numerical': 0.01309582482574104, 'mean_word_length': 3.687788778877888, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4819297', 'n_tokens_mistral': 4220, 'n_tokens_neox': 4036, 'n_words': 699}