moodle-logstore_xapi icon indicating copy to clipboard operation
moodle-logstore_xapi copied to clipboard

correctly fetch a subchapters parent (#776) & refactor TestRepository::read_records() method

Open ScottVerbeek opened this issue 2 years ago • 1 comments

Description

  • The \mod_book\event\chapter_viewed event for module mod_book was fetching a parent chapter incorrectly. Before subchapter was used as a ID, which is actually a boolean value. Here is a representation of what it should look like, and should help understand the code.
 SELECT id, bookid, pagenum, subchapter, title FROM mdl_book_chapters ORDER BY pagenum;                  
 id | bookid | pagenum | subchapter |         title         
----+--------+---------+------------+-----------------------
  1 |      1 |       1 |          0 | Chapter 1
  2 |      1 |       2 |          1 | Chapter 1.1
  3 |      1 |       3 |          1 | Chapter 1.2
  4 |      1 |       4 |          1 | Chapter 1.3
  6 |      1 |       5 |          1 | Chapter 1.4 (was 2.1)
  5 |      1 |       6 |          0 | Chapter 2
(6 rows)
  • The TestRepository::read_records() method only worked properly when parameter array $query contained exactly one element.

Related Issues

  • #776
  • #850

PR Type

  • Fix

ScottVerbeek avatar Nov 28 '23 01:11 ScottVerbeek

Running the unit tests locally:

root@6134396f5f13:/var/www/site# vendor/bin/phpunit --testsuite logstore_xapi_testsuite --filter 'logstore_xapi\\mod_book' --testdox
Moodle 4.4dev (Build: 20231124), 6374475dc3cf3a94e22ec18c4655b89819a1b5d6
Php: 8.1.24, pgsql: 14.0 (Debian 14.0-1.pgdg110+1), OS: Linux 6.4.12-060412-generic x86_64
PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

existing_chapter_viewed_with_parent_test (logstore_xapi\mod_book\chapter_viewed\existing_chapter_viewed_with_parent\existing_chapter_viewed_with_parent_test)
 ✔ Init
 ✔ Create event

existing_chapter_viewed_without_parent_test (logstore_xapi\mod_book\chapter_viewed\existing_chapter_viewed_without_parent\existing_chapter_viewed_without_parent_test)
 ✔ Init
 ✔ Create event

existing_module_test (logstore_xapi\mod_book\course_module_viewed\existing_module\existing_module_test)
 ✔ Init
 ✔ Create event

Time: 00:00.217, Memory: 76.50 MB

OK (6 tests, 6 assertions)

ScottVerbeek avatar Nov 28 '23 02:11 ScottVerbeek