diff --git a/.travis.yml b/.travis.yml index 67b25e1737..4328ae7645 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 diff --git a/tests/discussions_test.php b/tests/discussions_test.php new file mode 100644 index 0000000000..d1beffc45a --- /dev/null +++ b/tests/discussions_test.php @@ -0,0 +1,86 @@ +. + +/** + * PHPUnit Tests for testing discussion retrieval + * + * @package mod_moodleoverflow + * @copyright 2020 Jan Dageförde + * @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 + * @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)); + } +} \ No newline at end of file