Skip to content

Commit

Permalink
post tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffcaseyyet committed Oct 24, 2024
1 parent 5eb9ea6 commit 5009e2a
Show file tree
Hide file tree
Showing 13 changed files with 426 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/transformer/events/mod_forum/post_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ function post_deleted(array $config, \stdClass $event) {

$other = unserialize($event->other);
$discussionid = $other['discussionid'];
$post->discussion = $discussionid;
$discussion = $repo->read_record_by_id('forum_discussions', $discussionid);

return [[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://activitystrea.ms/delete',
'display' => [
'en-US' => 'Deleted'
$lang => 'Deleted'
],
],
'object' => utils\get_activity\forum_discussion_post_reply($config, $course, $post),
Expand Down
4 changes: 2 additions & 2 deletions tests/mod_forum/discussion_created/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
}
},
"verb": {
"id": "http://activitystrea.ms/schema/1.0/create",
"id": "http://activitystrea.ms/create",
"display": {
"en": "created"
"en": "Created"
}
},
"object": {
Expand Down
4 changes: 3 additions & 1 deletion tests/mod_forum/post_created/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"forum_posts": [
{
"id": 1,
"message": "<div class=\"text_to_html\">test_response_text</div>"
"message": "<div class=\"text_to_html\">test_response_text</div>",
"discussion": 1,
"subject": "Re: test_forum_discussion_name"
}
]
}
1 change: 1 addition & 0 deletions tests/mod_forum/post_created/post_created_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @copyright Jerret Fowler <[email protected]>
* Ryan Smith <https://www.linkedin.com/in/ryan-smith-uk/>
* David Pesce <[email protected]>
* Cliff Casey <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class post_created_test extends \logstore_xapi\xapi_test_case {
Expand Down
31 changes: 16 additions & 15 deletions tests/mod_forum/post_created/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
"verb": {
"id": "http://id.tincanapi.com/verb/replied",
"display": {
"en": "replied to"
"en": "Replied"
}
},
"object": {
"id": "http://www.example.org/mod/forum/discuss.php?d=1",
"id": "http://www.example.org/mod/forum/discuss.php?d=1#p1",
"definition": {
"type": "http://id.tincanapi.com/activitytype/discussion",
"type": "http://id.tincanapi.com/activitytype/forum-reply",
"name": {
"en": "test_forum_discussion_name"
"en": "Re: test_forum_discussion_name"
},
"description": {
"en": "test_response_text"
}
}
},
"result": {
"response": "test_response_text"
},
"context": {
"language": "en",
"extensions": {
Expand All @@ -37,6 +37,15 @@
},
"contextActivities": {
"parent": [
{
"id": "http://www.example.org/mod/forum/discuss.php?d=1",
"definition": {
"type": "http://id.tincanapi.com/activitytype/discussion",
"name": {
"en": "test_forum_discussion_name"
}
}
},
{
"id": "http://www.example.org/mod/forum/view.php?id=1",
"definition": {
Expand Down Expand Up @@ -66,14 +75,6 @@
}
}
],
"other": [
{
"id": "http://www.example.org/mod/forum/discuss.php?d=1#p1",
"definition": {
"type": "http://id.tincanapi.com/activitytype/forum-reply"
}
}
],
"category": [
{
"id": "http://www.example.org",
Expand Down
28 changes: 28 additions & 0 deletions tests/mod_forum/post_deleted/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"modules": [
{
"id": 1,
"name": "forum"
}
],
"forum": [
{
"id": 1,
"name": "test_forum_name"
}
],
"forum_discussions": [
{
"id": 1,
"name": "test_forum_discussion_name"
}
],
"forum_posts": [
{
"id": 1,
"message": "<div class=\"text_to_html\">test_response_text</div>",
"discussion": 1,
"subject": "Re: test_forum_discussion_name"
}
]
}
11 changes: 11 additions & 0 deletions tests/mod_forum/post_deleted/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": 1,
"userid": 1,
"courseid": 1,
"timecreated": 1433946701,
"objecttable": "forum",
"objectid": 1,
"contextinstanceid": 1,
"other": "a:3:{s:12:\"discussionid\";i:1;s:7:\"forumid\";i:2;s:9:\"forumtype\";s:7:\"general\";}",
"eventname": "\\mod_forum\\event\\post_deleted"
}
73 changes: 73 additions & 0 deletions tests/mod_forum/post_deleted/post_deleted_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace logstore_xapi\mod_forum\post_created;

defined('MOODLE_INTERNAL') || die();

global $CFG;

require_once($CFG->dirroot . '/admin/tool/log/store/xapi/tests/xapi_test_case.php');

/**
* Unit test for mod_forum post deleted event.
*
* @package logstore_xapi
* @copyright Jerret Fowler <[email protected]>
* Ryan Smith <https://www.linkedin.com/in/ryan-smith-uk/>
* David Pesce <[email protected]>
* Cliff Casey <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class post_deleted_test extends \logstore_xapi\xapi_test_case {

/**
* Retrieve the directory of the unit test.
*
* @return string
*/
protected function get_test_dir() {
return __DIR__;
}

/**
* Retrieve the plugin type being tested.
*
* @return string
*/
protected function get_plugin_type() {
return "mod";
}

/**
* Retrieve the plugin name being tested.
*
* @return string
*/
protected function get_plugin_name() {
return "forum";
}

/**
* Appease auto-detecting of test cases. xapi_test_case has default test cases.
*
* @covers ::post_created
* @return void
*/
public function test_init() {

}
}
86 changes: 86 additions & 0 deletions tests/mod_forum/post_deleted/statements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[
{
"actor": {
"name": "test_fullname",
"account": {
"homePage": "http://www.example.org",
"name": "1"
}
},
"verb": {
"id": "http://activitystrea.ms/delete",
"display": {
"en": "Deleted"
}
},
"object": {
"id": "http://www.example.org/mod/forum/discuss.php?d=1#p1",
"definition": {
"type": "http://id.tincanapi.com/activitytype/forum-reply"
}
},
"context": {
"language": "en",
"extensions": {
"http://lrs.learninglocker.net/define/extensions/info": {
"http://moodle.org": "1.0.0",
"https://github.com/xAPI-vle/moodle-logstore_xapi": "0.0.0-development",
"event_name": "\\mod_forum\\event\\post_deleted",
"event_function": "\\src\\transformer\\events\\mod_forum\\post_deleted"
}
},
"contextActivities": {
"parent": [
{
"id": "http://www.example.org/mod/forum/discuss.php?d=1",
"definition": {
"type": "http://id.tincanapi.com/activitytype/discussion",
"name": {
"en": "test_forum_discussion_name"
}
}
},
{
"id": "http://www.example.org/mod/forum/view.php?id=1",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/forum",
"name": {
"en": "test_forum_name"
}
}
},
{
"id": "http://www.example.org/course/section.php?id=1",
"objectType": "Activity",
"definition": {
"name": {
"en": "test_name Section 0"
},
"type": "http://id.tincanapi.com/activitytype/section"
}
},
{
"id": "http://www.example.org/course/view.php?id=1",
"definition": {
"type": "https://w3id.org/xapi/cmi5/activitytype/course",
"name": {
"en": "test_name"
}
}
}
],
"category": [
{
"id": "http://www.example.org",
"definition": {
"type": "http://id.tincanapi.com/activitytype/lms",
"name": {
"en": "test_name"
}
}
}
]
}
}
}
]
28 changes: 28 additions & 0 deletions tests/mod_forum/post_updated/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"modules": [
{
"id": 1,
"name": "forum"
}
],
"forum": [
{
"id": 1,
"name": "test_forum_name"
}
],
"forum_discussions": [
{
"id": 1,
"name": "test_forum_discussion_name"
}
],
"forum_posts": [
{
"id": 1,
"message": "<div class=\"text_to_html\">test_response_text</div>",
"discussion": 1,
"subject": "Re: test_forum_discussion_name"
}
]
}
11 changes: 11 additions & 0 deletions tests/mod_forum/post_updated/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": 1,
"userid": 1,
"courseid": 1,
"timecreated": 1433946701,
"objecttable": "forum",
"objectid": 1,
"contextinstanceid": 1,
"other": "a:3:{s:12:\"discussionid\";i:1;s:7:\"forumid\";i:2;s:9:\"forumtype\";s:7:\"general\";}",
"eventname": "\\mod_forum\\event\\post_updated"
}
Loading

0 comments on commit 5009e2a

Please sign in to comment.