Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit test für Discussion #71

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
php: 7.4
env: DB=mysqli MOODLE_BRANCH=MOODLE_310_STABLE
install:
- moodle-plugin-ci install --no-init
- moodle-plugin-ci install
script:
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
Expand All @@ -60,6 +60,8 @@ jobs:
- moodle-plugin-ci savepoints
- moodle-plugin-ci mustache
- moodle-plugin-ci grunt
- moodle-plugin-ci phpunit --coverage-clover
- moodle-plugin-ci behat
# Smaller build matrix for development builds
- stage: develop
php: 7.4
Expand Down
86 changes: 86 additions & 0 deletions tests/discussions_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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/>.

/**
* PHPUnit Tests for testing discussion retrieval
*
* @package mod_moodleoverflow
* @copyright 2020 Jan Dageförde <jan@dagefor.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

global $CFG;
require_once($CFG->dirroot . '/mod/moodleoverflow/locallib.php');

/**
* PHPUnit Tests for testing discussion retrieval
*
* @package mod_moodleoverflow
* @copyright 2020 Jan Dageförde <jan@dagefor.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

//basic_testcase --> no database changes or edits
//advanced_testcase --> with database changes and edits

//class is a testcase, meaning a collection of usecases in a certain category
class mod_moodleoverflow_discussions_testcase extends advanced_testcase {


//function represents a usecase in the category
/*
public function test_a_fresh_forum_has_an_empty_discussion_list() {

//assert determains value that must be true
// can a dicussion be found? here it searches for empty
$this->assertEquals(count($discussions), 0);
}
*/

public function test_a_discussion_can_be_retrieved() {
$this->resetAfterTest();

$user = $this->getDataGenerator()->create_user();

$course = $this->getDataGenerator()->create_course();
$moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', ['course' => $course->id]);

// todo: discussion erzeugen
// todo: add plugin DataGenerator from mooodleoverflow
$plugindatagernator = $this->getDataGenerator()->get_plugin_generator('mod_moodleoverflow');
$plugindatagernator -> create_discussion(['course' => $course->id, 'moodleoverflow' => $moodleoverflow->id, 'userid' => $user->id], $moodleoverflow);

$coursemodule = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id);
$discussions = moodleoverflow_get_discussions($coursemodule);

// can a dicussion be found? here it searches for an entry
$this->assertEquals(1, count($discussions));
}

public function test_new_forum_is_empty() {
$this->resetAfterTest();

$course = $this->getDataGenerator()->create_course();
$moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', ['course' => $course->id]);

$coursemodule = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id);
$discussions = moodleoverflow_get_discussions($coursemodule);

$this->assertEquals(0, count($discussions));
}
}