Example #1
0
    /**
     * Test moodle_notes_create_notes web service function
     *
     * @param webservice_rest_client|webservice_soap_client|webservice_xmlrpc_client $client the protocol test client
     * @since Moodle 2.1
     */
    private function moodle_notes_create_notes($client) {
        global $DB, $CFG;

        $note1 = array();
        $note1['userid'] = 2; // about who is the note
        $note1['publishstate'] = 'personal'; // can be course, site, personal
        $note1['courseid'] = 2; // in Moodle a notes is always created into a course, even a site note.
        $note1['text'] = 'This is a personal note about the user';
        $note1['clientnoteid'] = 'note_1';

        $note2 = array();
        $note2['userid'] = 40000; // mostly likely going to fail
        $note2['publishstate'] = 'course';
        $note2['courseid'] = 2;
        $note2['text'] = 'This is a teacher note about the user';
        $note2['clientnoteid'] = 'note_2';

        $note3 = array();
        $note3['userid'] = 2;
        $note3['publishstate'] = 'site';
        $note3['courseid'] = 30000; // mostly likely going to fail
        $note3['text'] = 'This is a teacher site-wide note about the user';
        $note3['clientnoteid'] = 'note_3';

        $function = 'moodle_notes_create_notes';
        $params = array('notes' => array($note1, $note2, $note3));
        $notes = $client->call($function, $params);

        $this->assertEqual(3, count($notes)); // 1 info is a success, 2 others should be failed
    }