Skip to content

Commit

Permalink
Merge branch 'MDL-73785_311' of https://github.com/stronk7/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_311_STABLE
  • Loading branch information
junpataleta committed Mar 4, 2022
2 parents 95430c1 + eb0c520 commit 0cdd0b3
Show file tree
Hide file tree
Showing 86 changed files with 1,294 additions and 1,697 deletions.
Expand Up @@ -14,27 +14,21 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Tests for scheduled tasks.
*
* @package tool_dataprivacy
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();
require_once('data_privacy_testcase.php');
namespace tool_dataprivacy\task;

use tool_dataprivacy\api;

defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../data_privacy_testcase.php');

/**
* Tests for scheduled tasks.
*
* @package tool_dataprivacy
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_dataprivacy_task_testcase extends data_privacy_testcase {
class task_test extends \data_privacy_testcase {

/**
* Test tearDown.
Expand Down
47 changes: 24 additions & 23 deletions admin/tool/log/store/database/tests/store_test.php
Expand Up @@ -14,20 +14,21 @@
// 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_database;

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

require_once(__DIR__ . '/fixtures/event.php');
require_once(__DIR__ . '/fixtures/store.php');

/**
* External database log store tests.
*
* @package logstore_database
* @copyright 2014 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

require_once(__DIR__ . '/fixtures/event.php');
require_once(__DIR__ . '/fixtures/store.php');

class logstore_database_store_testcase extends advanced_testcase {
class store_test extends \advanced_testcase {
/**
* Tests log writing.
*
Expand Down Expand Up @@ -120,7 +121,7 @@ public function test_log_writing(bool $jsonformat) {

$this->setUser(0);
$event1 = \logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)));
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)));
$event1->trigger();

$logs = $DB->get_records('logstore_standard_log', array(), 'id ASC');
Expand All @@ -141,11 +142,11 @@ public function test_log_writing(bool $jsonformat) {
$this->assertEquals($data, $log1);

$this->setAdminUser();
\core\session\manager::loginas($user1->id, context_system::instance());
\core\session\manager::loginas($user1->id, \context_system::instance());
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));

$event2 = \logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9)));
array('context' => \context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9)));
$event2->trigger();

\core\session\manager::init_empty_session();
Expand Down Expand Up @@ -190,30 +191,30 @@ public function test_log_writing(bool $jsonformat) {
$DB->delete_records('logstore_standard_log');

\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));
$store->flush();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(5, $DB->count_records('logstore_standard_log'));
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(8, $DB->count_records('logstore_standard_log'));

// Test guest logging setting.
Expand All @@ -225,22 +226,22 @@ public function test_log_writing(bool $jsonformat) {

$this->setUser(null);
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));

$this->setGuestUser();
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(0, $DB->count_records('logstore_standard_log'));

$this->setUser($user1);
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(1, $DB->count_records('logstore_standard_log'));

$this->setUser($user2);
\logstore_database\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
$this->assertEquals(2, $DB->count_records('logstore_standard_log'));

set_config('enabled_stores', '', 'tool_log');
Expand Down Expand Up @@ -270,7 +271,7 @@ public function test_is_event_ignored() {
set_config('logguests', 0, 'logstore_database');
$this->setGuestUser();
$event = \logstore_database\event\unittest_executed::create(
array('context' => context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10)));
array('context' => \context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10)));
$logmanager = get_log_manager();
$store = new \logstore_database\test\store($logmanager);
$this->assertTrue($store->is_event_ignored($event));
Expand Down
19 changes: 10 additions & 9 deletions admin/tool/log/store/legacy/tests/store_test.php
Expand Up @@ -14,20 +14,21 @@
// 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_legacy;

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

require_once(__DIR__ . '/fixtures/event.php');
require_once(__DIR__ . '/fixtures/store.php');

/**
* Legacy log store tests.
*
* @package logstore_legacy
* @copyright 2014 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

require_once(__DIR__ . '/fixtures/event.php');
require_once(__DIR__ . '/fixtures/store.php');

class logstore_legacy_store_testcase extends advanced_testcase {
class store_test extends \advanced_testcase {
public function test_log_writing() {
global $DB;
$this->resetAfterTest();
Expand Down Expand Up @@ -58,12 +59,12 @@ public function test_log_writing() {

$this->setUser(0);
$event1 = \logstore_legacy\event\unittest_executed::create(
array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)));
array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)));
$event1->trigger();

$this->setUser($user1);
$event2 = \logstore_legacy\event\unittest_executed::create(
array('context' => context_course::instance($course2->id), 'other' => array('sample' => 6, 'xx' => 11)));
array('context' => \context_course::instance($course2->id), 'other' => array('sample' => 6, 'xx' => 11)));
$event2->trigger();

$logs = $DB->get_records('log', array(), 'id ASC');
Expand Down

0 comments on commit 0cdd0b3

Please sign in to comment.