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

Add PHPunit Tests #8

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
8ce83e0
phpunit_release01
ThorbenLaprell Sep 28, 2021
682a006
test_seperate_docker
ThorbenLaprell Sep 29, 2021
1fbbbe5
test_seperate_docker
ThorbenLaprell Sep 29, 2021
2ed4863
test_seperate_docker
ThorbenLaprell Sep 29, 2021
6401c59
test_seperate_docker
ThorbenLaprell Sep 29, 2021
bae9060
change_testing
ThorbenLaprell Sep 29, 2021
b98ab53
test_add_mysql
ThorbenLaprell Sep 29, 2021
2fa4b1f
test_add_mysql
ThorbenLaprell Sep 29, 2021
a2a16da
test_add_mysql
ThorbenLaprell Sep 29, 2021
18118f9
test_add_mysqli
ThorbenLaprell Sep 29, 2021
95e6d9e
change_mysqli_ports
ThorbenLaprell Sep 29, 2021
19b6ef4
test_port
ThorbenLaprell Sep 29, 2021
3353e96
phpunit_release02
ThorbenLaprell Sep 29, 2021
93c20e5
phpunit_release
ThorbenLaprell Sep 29, 2021
52d5069
add_week_heatmap_branch
ThorbenLaprell Sep 30, 2021
8f46fd0
get_results
ThorbenLaprell Sep 30, 2021
af0911c
get_data02
ThorbenLaprell Sep 30, 2021
429d5fc
test_daylightsaving
ThorbenLaprell Sep 30, 2021
7f29fde
test_daylight_saving02
ThorbenLaprell Sep 30, 2021
331966e
test_daylight_saving03
ThorbenLaprell Sep 30, 2021
fa52f74
test_daylightsaving04
ThorbenLaprell Sep 30, 2021
cf628fe
test_timezone06
ThorbenLaprell Sep 30, 2021
b724e3c
test_buffer
ThorbenLaprell Sep 30, 2021
5607162
fix_dto
ThorbenLaprell Oct 4, 2021
8e041f7
fix_minor
ThorbenLaprell Oct 4, 2021
e68a1b3
test_dto01
ThorbenLaprell Oct 4, 2021
07dbb9e
test_dto02
ThorbenLaprell Oct 4, 2021
535958d
test_dto03
ThorbenLaprell Oct 4, 2021
f162e4d
test_dto04
ThorbenLaprell Oct 4, 2021
8e4f060
test_dto06
ThorbenLaprell Oct 4, 2021
00bd46a
test_dto06
ThorbenLaprell Oct 4, 2021
4e893ed
fix_dto_pgsql01_and_add_new_test
ThorbenLaprell Oct 4, 2021
73905b2
fix_bug01
ThorbenLaprell Oct 4, 2021
bfb9410
test_dto_f01
ThorbenLaprell Oct 4, 2021
c353c4c
test_dto_f02
ThorbenLaprell Oct 4, 2021
fb3a1d7
test_dto_f04
ThorbenLaprell Oct 4, 2021
28016cc
test_dto_f05
ThorbenLaprell Oct 4, 2021
3632f0d
test_dto_f7
ThorbenLaprell Oct 4, 2021
8f27118
test_start_time01
ThorbenLaprell Oct 5, 2021
a1b96f8
test_time02
ThorbenLaprell Oct 5, 2021
0039cfa
test_time03
ThorbenLaprell Oct 5, 2021
f4794b4
test_time04
ThorbenLaprell Oct 5, 2021
7650e62
test_time05
ThorbenLaprell Oct 5, 2021
ae97a25
test_time06
ThorbenLaprell Oct 5, 2021
197c1c9
test_preview_click_count
ThorbenLaprell Oct 5, 2021
1026985
test_preview_activity01
ThorbenLaprell Oct 5, 2021
79a2116
test_activities01
ThorbenLaprell Oct 5, 2021
3d80a40
test_localization
ThorbenLaprell Oct 5, 2021
a6760a6
test_localization
ThorbenLaprell Oct 5, 2021
0892f8d
test_preview_query_users01
ThorbenLaprell Oct 6, 2021
cb0363e
test_preview_query_users02
ThorbenLaprell Oct 6, 2021
1d86354
test_preview_query_users03
ThorbenLaprell Oct 6, 2021
46c1b77
test_preview_query_users05
ThorbenLaprell Oct 6, 2021
fa97a00
fake_use
ThorbenLaprell Oct 6, 2021
f419ecc
debug_quiz_test01
ThorbenLaprell Oct 10, 2021
41eae52
test_quiz02
ThorbenLaprell Oct 10, 2021
d2db8bf
debug_quiz03
ThorbenLaprell Oct 10, 2021
4c22411
debug_quiz06
ThorbenLaprell Oct 11, 2021
8b0bc3e
debug_quiz07
ThorbenLaprell Oct 11, 2021
c0e151d
debug_quiz08
ThorbenLaprell Oct 11, 2021
e20403f
debug_quiz09
ThorbenLaprell Oct 11, 2021
46a8d0f
debug_quiz10
ThorbenLaprell Oct 11, 2021
cdc523e
debug_quiz11
ThorbenLaprell Oct 11, 2021
549c591
debug_quiz13
ThorbenLaprell Oct 11, 2021
eb13bc3
debug_quiz14
ThorbenLaprell Oct 12, 2021
21c489d
debug_quiz15
ThorbenLaprell Oct 12, 2021
9db020e
debug_quiz16
ThorbenLaprell Oct 12, 2021
ddf5b20
debug_quiz17
ThorbenLaprell Oct 12, 2021
b9801f3
debug_quiz18
ThorbenLaprell Oct 12, 2021
2803f42
debug_quiz19
ThorbenLaprell Oct 12, 2021
8425d8f
debug_quiz20
ThorbenLaprell Oct 12, 2021
18cdd89
debug_quiz21
ThorbenLaprell Oct 12, 2021
59f4dc1
debug_quiz22
ThorbenLaprell Oct 12, 2021
f759cce
debug_quiz23
ThorbenLaprell Oct 12, 2021
3d50edd
debug_quiz24
ThorbenLaprell Oct 12, 2021
41fe5cf
debug_quiz25
ThorbenLaprell Oct 12, 2021
2dd1f83
debug_quiz26
ThorbenLaprell Oct 12, 2021
6a2c112
debug_quiz27
ThorbenLaprell Oct 12, 2021
e12738c
phpunit_release02
ThorbenLaprell Oct 12, 2021
a162d27
show
ThorbenLaprell Oct 12, 2021
85884a8
test_resease
ThorbenLaprell Oct 12, 2021
6a89383
test_release02
ThorbenLaprell Oct 12, 2021
2fda4f1
test_release03
ThorbenLaprell Oct 12, 2021
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
122 changes: 122 additions & 0 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Moodle Plugin CI

on: [push, pull_request]

#start pgsql test
jobs:
test_pgsql:
runs-on: ubuntu-18.04

services:
postgres:
image: postgres:10
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: ['7.4']
moodle-branch: ['MOODLE_311_STABLE']
database: [pgsql]

steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci add-plugin rwthanalytics/moodle-logstore_lanalytics
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: PHP Lint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit
#end pgsql test

#start moodle mariadb matrix tests
test_mariadb:
runs-on: ubuntu-18.04

services:
mariadb:
image: mariadb:10.5
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4']
moodle-branch: ['MOODLE_311_STABLE', 'MOODLE_310_STABLE', 'MOODLE_39_STABLE']
database: [mariadb]

steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci add-plugin rwthanalytics/moodle-logstore_lanalytics
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: PHP Lint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit
#end moodle mariadb matrix tests
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"homepage": "https://git.rwth-aachen.de/laixmo/moodle-local_learning_analytics",
"license": "GPL-3.0+",
"require": {
"composer/installers": "*"
"composer/installers": "*",
"nesbot/carbon": "^2.53"
},
"extra": {
"installer-name": "learning_analytics"
Expand All @@ -14,4 +15,4 @@
"issues": "https://git.rwth-aachen.de/laixmo/moodle-local_learning_analytics/issues",
"source": "https://git.rwth-aachen.de/laixmo/moodle-local_learning_analytics"
}
}
}
180 changes: 180 additions & 0 deletions reports/activities/tests/query_helper_advanced_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?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/>.

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

use lareport_activities\query_helper;
use PHPUnit\Framework\TestCase;
use local_learning_analytics\event\report_viewed;
use local_learning_analytics\report_list;
require_once(__DIR__ . '/../../../../../config.php');

//use: navigate in cmd to your moodle folder and enter vendor\bin\phpunit local_Learning_Analytics_reports_activities_testcase local\Learning_Analytics\reports\activities\tests\query_helper_advanced_test.php
class local_Learning_Analytics_reports_activities_testcase extends \advanced_testcase {

public function test_activities() {
global $DB, $PAGE;
$this->resetAfterTest(true);
$this->setAdminUser();

$datagenerator = $this->getDataGenerator();
$activitygenerator = $this->getDataGenerator()->get_plugin_generator('mod_forum');

$this->preventResetByRollback();
set_config('enabled_stores', 'logstore_lanalytics', 'tool_log');
set_config('buffersize', 0, 'logstore_lanalytics');

$user = $datagenerator->create_user();
$category = $datagenerator->create_category();
$course = $datagenerator->create_course(array('name'=>'testcourse', 'category'=>$category->id));
$datagenerator->enrol_user($user->id, $course->id);

$forum = $activitygenerator->create_instance(array('course' => $course->id));

$instancequery = <<<SQL
SELECT
id
FROM {course_modules} AS cm
WHERE instance = ?
SQL;

$contextquery = <<<SQL
SELECT
id
FROM {context} AS c
WHERE instanceid = ?
SQL;

$logmanager = get_log_manager(true);
$contextinstance = $DB->get_record_sql($instancequery, [$forum->id]);
$instanceid = $contextinstance->id;
$context = $DB->get_record_sql($contextquery, [$instanceid]);
$contextid = $context->id;

for($i=0; $i<16; $i++) {
$event = report_viewed::create(array(
'contextid' => $contextid,
'objectid' => NULL
));
$event->add_record_snapshot('forum', $forum);
$event->trigger();
}

$testresult1 = query_helper::query_activities($course->id,"" , []);

$this->assertEquals(17, $testresult1[$instanceid]->hits);

//second tests
$activitygenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
$quiz = $activitygenerator->create_instance(array('course' => $course->id));

$contextinstance2 = $DB->get_record_sql($instancequery, [$quiz->id]);
$instanceid2 = $contextinstance2->id;
$context2 = $DB->get_record_sql($contextquery, [$instanceid2]);
$contextid2 = $context2->id;

for($i=0; $i<10; $i++) {
$event = report_viewed::create(array(
'contextid' => $contextid2,
'objectid' => NULL
));
$event->add_record_snapshot('quiz', $quiz);
$event->trigger();
}

$testresult2 = query_helper::query_activities($course->id,"" , []);

$this->assertEquals(11, $testresult2[$instanceid2]->hits);
}

public function test_preview_query_most_clicked_activity() {
global $DB, $PAGE;
$this->resetAfterTest(true);
$this->setAdminUser();

$datagenerator = $this->getDataGenerator();
$activitygenerator = $this->getDataGenerator()->get_plugin_generator('mod_forum');

$this->preventResetByRollback();
set_config('enabled_stores', 'logstore_lanalytics', 'tool_log');
set_config('buffersize', 0, 'logstore_lanalytics');

$user = $datagenerator->create_user();
$category = $datagenerator->create_category();
$course = $datagenerator->create_course(array('name'=>'testcourse', 'category'=>$category->id));
$datagenerator->enrol_user($user->id, $course->id);

$forum = $activitygenerator->create_instance(array('course' => $course->id));

$instancequery = <<<SQL
SELECT
id
FROM {course_modules} AS cm
WHERE instance = ?
SQL;

$contextquery = <<<SQL
SELECT
id
FROM {context} AS c
WHERE instanceid = ?
SQL;

$logmanager = get_log_manager(true);
$contextinstance = $DB->get_record_sql($instancequery, [$forum->id]);
$instanceid = $contextinstance->id;
$context = $DB->get_record_sql($contextquery, [$instanceid]);
$contextid = $context->id;

$date = new \DateTime();
$date->setTime(23, 59, 59); // Include today.
$date->modify('-1 week');
$oneweekago = $date->getTimestamp();
$timestampBefore = $oneweekago - 40000;
$timestampAfter = $oneweekago + 40000;

$counterAfter = 0;
$counterBefore = 0;
for($i=0; $i<99; $i++) {
$counterAfter++;
$entry = [
'id' => $counterAfter,
'eventid' => 30,
'timecreated' => $timestampAfter,
'courseid' => $course->id,
'contextid' => $contextid,
'device' => 3611
];
$DB->insert_record('logstore_lanalytics_log', $entry, false, false, true);
if($i%3==0) {
$counterBefore++;
$entry = [
'id' => $counterBefore,
'eventid' => 30,
'timecreated' => $counterBefore,
'courseid' => $course->id,
'contextid' => $contextid,
'device' => 3611
];
$DB->insert_record('logstore_lanalytics_log', $entry, false, false, true);
}
}

$testresult1 = query_helper::preview_query_most_clicked_activity($course->id, 1);

$this->assertEquals(100, $testresult1[$instanceid]->hits);
}
}
73 changes: 73 additions & 0 deletions reports/coursedashboard/tests/query_helper_advanced_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/>.

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

use lareport_coursedashboard\query_helper;
use PHPUnit\Framework\TestCase;
use local_learning_analytics\event\report_viewed;
use local_learning_analytics\report_list;
require_once(__DIR__ . '/../../../../../config.php');

//use: navigate in cmd to your moodle folder and enter vendor\bin\phpunit local_Learning_Analytics_reports_coursedashboard_testcase local\Learning_Analytics\reports\coursedashboard\tests\query_helper_advanced_test.php
class local_Learning_Analytics_reports_coursedashboard_testcase extends \advanced_testcase {

public function test_weekly_activity() {
global $DB, $PAGE;
$this->resetAfterTest(true);
$this->setAdminUser();

$datagenerator = $this->getDataGenerator();

$this->preventResetByRollback();
set_config('enabled_stores', 'logstore_lanalytics_log', 'tool_log');
set_config('buffersize', 0, 'logstore_lanalytics_log');

$category = $datagenerator->create_category();
$course = $datagenerator->create_course(array('name'=>'testcourse', 'category'=>$category->id));
$user = $datagenerator->create_user();
$datagenerator->enrol_user($user->id, $course->id);

$date = time() - (7 * 24 * 60 * 60);
$tooearlydate = time() - (7 * 24 * 60 * 60 * 2);

$entry1 = [
'id' => 1,
'eventid' => 30,
'timecreated' => $tooearlydate,
'courseid' => $course->id,
'contextid' => 46,
'device' => 3611
];
$entry2 = [
'id' => 2,
'eventid' => 30,
'timecreated' => $date,
'courseid' => $course->id,
'contextid' => 46,
'device' => 3611
];

$DB->insert_record('logstore_lanalytics_log', $entry1, false, false, true);
$DB->insert_record('logstore_lanalytics_log', $entry2, false, false, true);

$testweekresult = query_helper::query_weekly_activity($course->id);
$testweek = end($testweekresult);
$testweekclicks = $testweek->clicks;

$this->assertEquals(1, $testweekclicks);
}
}
Loading