MDL-58424 core_calendar: removed unused get_action_events_* functions
authorMark Nelson <markn@moodle.com>
Thu, 30 Mar 2017 05:57:33 +0000 (13:57 +0800)
committerDan Poltawski <dan@moodle.com>
Tue, 4 Apr 2017 10:01:53 +0000 (11:01 +0100)
Also moved associated unit tests to another location and changed
them so that they were testing local_api instead.

Part of MDL-55611 epic.

calendar/classes/api.php
calendar/tests/local_api_test.php [moved from calendar/tests/api_test.php with 84% similarity]

index 18d33f2..4d55577 100644 (file)
@@ -86,89 +86,4 @@ class api {
             return $carry + [$event->get_id() => $mapper->from_event_to_stdclass($event)];
         }, []);
     }
-
-    /**
-     * Get a list of action events for the logged in user by the given
-     * timesort values.
-     *
-     * @param int|null $timesortfrom The start timesort value (inclusive)
-     * @param int|null $timesortto The end timesort value (inclusive)
-     * @param int|null $aftereventid Only return events after this one
-     * @param int $limitnum Limit results to this amount (between 1 and 50)
-     * @return array A list of event type objects
-     */
-    public static function get_action_events_by_timesort(
-        $timesortfrom = null,
-        $timesortto = null,
-        $aftereventid = null,
-        $limitnum = 20
-    ) {
-        $mapper = \core_calendar\local\event\core_container::get_event_mapper();
-        $events = local_api::get_action_events_by_timesort($timesortfrom, $timesortto, $aftereventid, $limitnum);
-
-        return array_map(function($event) use ($mapper) {
-            return $mapper->from_event_to_legacy_event($event);
-        }, $events);
-    }
-
-    /**
-     * Get a list of action events for the logged in user by the given
-     * course and timesort values.
-     *
-     * @param \stdClass $course The course the events must belong to
-     * @param int|null $timesortfrom The start timesort value (inclusive)
-     * @param int|null $timesortto The end timesort value (inclusive)
-     * @param int|null $aftereventid Only return events after this one
-     * @param int $limitnum Limit results to this amount (between 1 and 50)
-     * @return array A list of action_event_interface objects
-     */
-    public static function get_action_events_by_course(
-        $course,
-        $timesortfrom = null,
-        $timesortto = null,
-        $aftereventid = null,
-        $limitnum = 20
-    ) {
-        $mapper = \core_calendar\local\event\core_container::get_event_mapper();
-        $events = local_api::get_action_events_by_course(
-            $course, $timesortfrom, $timesortto, $aftereventid, $limitnum);
-
-        return array_map(function($event) use ($mapper) {
-            return $mapper->from_event_to_legacy_event($event);
-        }, $events);
-    }
-
-    /**
-     * Get a list of action events for the logged in user by the given
-     * courses and timesort values.
-     *
-     * The limit number applies per course, not for the result set as a whole.
-     * E.g. Requesting 3 courses with a limit of 10 will result in up to 30
-     * events being returned (up to 10 per course).
-     *
-     * @param array $courses The courses the events must belong to
-     * @param int|null $timesortfrom The start timesort value (inclusive)
-     * @param int|null $timesortto The end timesort value (inclusive)
-     * @param int $limitnum Limit results per course to this amount (between 1 and 50)
-     * @return array A list of event objects indexed by course id
-     */
-    public static function get_action_events_by_courses(
-        $courses = [],
-        $timesortfrom = null,
-        $timesortto = null,
-        $limitnum = 20
-    ) {
-        $return = [];
-        $mapper = \core_calendar\local\event\core_container::get_event_mapper();
-        $eventsbycourses = local_api::get_action_events_by_courses(
-            $courses, $timesortfrom, $timesortto, $limitnum);
-
-        foreach (array_keys($eventsbycourses) as $courseid) {
-            $return[$courseid] = array_map(function($event) use ($mapper) {
-                return $mapper->from_event_to_legacy_event($event);
-            }, $eventsbycourses[$courseid]);
-        }
-
-        return $return;
-    }
 }
similarity index 84%
rename from calendar/tests/api_test.php
rename to calendar/tests/local_api_test.php
index aaa3631..1bf3cac 100644 (file)
@@ -15,7 +15,7 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
- * Contains the class containing unit tests for the calendar API.
+ * Contains the class containing unit tests for the calendar local API.
  *
  * @package    core_calendar
  * @copyright  2017 Mark Nelson <markn@moodle.com>
@@ -26,16 +26,14 @@ defined('MOODLE_INTERNAL') || die();
 
 require_once(__DIR__ . '/helpers.php');
 
-use \core_calendar\api;
-
 /**
- * Class contaning unit tests for the calendar API.
+ * Class contaning unit tests for the calendar local API.
  *
  * @package    core_calendar
  * @copyright  2017 Mark Nelson <markn@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class core_calendar_api_testcase extends advanced_testcase {
+class core_calendar_local_api_testcase extends advanced_testcase {
 
     /**
      * Tests set up
@@ -83,15 +81,15 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 8]));
 
         $this->setUser($user);
-        $result = api::get_action_events_by_timesort(5);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(5);
 
         $this->assertCount(4, $result);
-        $this->assertEquals('Event 5', $result[0]->name);
-        $this->assertEquals('Event 6', $result[1]->name);
-        $this->assertEquals('Event 7', $result[2]->name);
-        $this->assertEquals('Event 8', $result[3]->name);
+        $this->assertEquals('Event 5', $result[0]->get_name());
+        $this->assertEquals('Event 6', $result[1]->get_name());
+        $this->assertEquals('Event 7', $result[2]->get_name());
+        $this->assertEquals('Event 8', $result[3]->get_name());
 
-        $result = api::get_action_events_by_timesort(9);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(9);
 
         $this->assertEmpty($result);
     }
@@ -135,15 +133,15 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 9]));
 
         $this->setUser($user);
-        $result = api::get_action_events_by_timesort(null, 5);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(null, 5);
 
         $this->assertCount(4, $result);
-        $this->assertEquals('Event 1', $result[0]->name);
-        $this->assertEquals('Event 2', $result[1]->name);
-        $this->assertEquals('Event 3', $result[2]->name);
-        $this->assertEquals('Event 4', $result[3]->name);
+        $this->assertEquals('Event 1', $result[0]->get_name());
+        $this->assertEquals('Event 2', $result[1]->get_name());
+        $this->assertEquals('Event 3', $result[2]->get_name());
+        $this->assertEquals('Event 4', $result[3]->get_name());
 
-        $result = api::get_action_events_by_timesort(null, 1);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(null, 1);
 
         $this->assertEmpty($result);
     }
@@ -186,15 +184,15 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 8]));
 
         $this->setUser($user);
-        $result = api::get_action_events_by_timesort(3, 6);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(3, 6);
 
         $this->assertCount(4, $result);
-        $this->assertEquals('Event 3', $result[0]->name);
-        $this->assertEquals('Event 4', $result[1]->name);
-        $this->assertEquals('Event 5', $result[2]->name);
-        $this->assertEquals('Event 6', $result[3]->name);
+        $this->assertEquals('Event 3', $result[0]->get_name());
+        $this->assertEquals('Event 4', $result[1]->get_name());
+        $this->assertEquals('Event 5', $result[2]->get_name());
+        $this->assertEquals('Event 6', $result[3]->get_name());
 
-        $result = api::get_action_events_by_timesort(10, 15);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(10, 15);
 
         $this->assertEmpty($result);
     }
@@ -238,19 +236,19 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 8]));
 
         $this->setUser($user);
-        $result = api::get_action_events_by_timesort(2, 7, $event3->id, 2);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(2, 7, $event3->id, 2);
 
         $this->assertCount(2, $result);
-        $this->assertEquals('Event 4', $result[0]->name);
-        $this->assertEquals('Event 5', $result[1]->name);
+        $this->assertEquals('Event 4', $result[0]->get_name());
+        $this->assertEquals('Event 5', $result[1]->get_name());
 
-        $result = api::get_action_events_by_timesort(2, 7, $event5->id, 2);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(2, 7, $event5->id, 2);
 
         $this->assertCount(2, $result);
-        $this->assertEquals('Event 6', $result[0]->name);
-        $this->assertEquals('Event 7', $result[1]->name);
+        $this->assertEquals('Event 6', $result[0]->get_name());
+        $this->assertEquals('Event 7', $result[1]->get_name());
 
-        $result = api::get_action_events_by_timesort(2, 7, $event7->id, 2);
+        $result = \core_calendar\local\api::get_action_events_by_timesort(2, 7, $event7->id, 2);
 
         $this->assertEmpty($result);
     }
@@ -307,15 +305,15 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event15 = create_event(array_merge($params, ['name' => 'Event 15', 'timesort' => 7]));
         $event16 = create_event(array_merge($params, ['name' => 'Event 16', 'timesort' => 8]));
 
-        $result = api::get_action_events_by_course($course1, 5);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, 5);
 
         $this->assertCount(4, $result);
-        $this->assertEquals('Event 5', $result[0]->name);
-        $this->assertEquals('Event 6', $result[1]->name);
-        $this->assertEquals('Event 7', $result[2]->name);
-        $this->assertEquals('Event 8', $result[3]->name);
+        $this->assertEquals('Event 5', $result[0]->get_name());
+        $this->assertEquals('Event 6', $result[1]->get_name());
+        $this->assertEquals('Event 7', $result[2]->get_name());
+        $this->assertEquals('Event 8', $result[3]->get_name());
 
-        $result = api::get_action_events_by_course($course1, 9);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, 9);
 
         $this->assertEmpty($result);
     }
@@ -372,15 +370,15 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event15 = create_event(array_merge($params, ['name' => 'Event 15', 'timesort' => 8]));
         $event16 = create_event(array_merge($params, ['name' => 'Event 16', 'timesort' => 9]));
 
-        $result = api::get_action_events_by_course($course1, null, 5);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, null, 5);
 
         $this->assertCount(4, $result);
-        $this->assertEquals('Event 1', $result[0]->name);
-        $this->assertEquals('Event 2', $result[1]->name);
-        $this->assertEquals('Event 3', $result[2]->name);
-        $this->assertEquals('Event 4', $result[3]->name);
+        $this->assertEquals('Event 1', $result[0]->get_name());
+        $this->assertEquals('Event 2', $result[1]->get_name());
+        $this->assertEquals('Event 3', $result[2]->get_name());
+        $this->assertEquals('Event 4', $result[3]->get_name());
 
-        $result = api::get_action_events_by_course($course1, null, 1);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, null, 1);
 
         $this->assertEmpty($result);
     }
@@ -437,15 +435,15 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event15 = create_event(array_merge($params, ['name' => 'Event 15', 'timesort' => 7]));
         $event16 = create_event(array_merge($params, ['name' => 'Event 16', 'timesort' => 8]));
 
-        $result = api::get_action_events_by_course($course1, 3, 6);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, 3, 6);
 
         $this->assertCount(4, $result);
-        $this->assertEquals('Event 3', $result[0]->name);
-        $this->assertEquals('Event 4', $result[1]->name);
-        $this->assertEquals('Event 5', $result[2]->name);
-        $this->assertEquals('Event 6', $result[3]->name);
+        $this->assertEquals('Event 3', $result[0]->get_name());
+        $this->assertEquals('Event 4', $result[1]->get_name());
+        $this->assertEquals('Event 5', $result[2]->get_name());
+        $this->assertEquals('Event 6', $result[3]->get_name());
 
-        $result = api::get_action_events_by_course($course1, 10, 15);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, 10, 15);
 
         $this->assertEmpty($result);
     }
@@ -503,19 +501,19 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event15 = create_event(array_merge($params, ['name' => 'Event 15', 'timesort' => 7]));
         $event16 = create_event(array_merge($params, ['name' => 'Event 16', 'timesort' => 8]));
 
-        $result = api::get_action_events_by_course($course1, 2, 7, $event3->id, 2);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, 2, 7, $event3->id, 2);
 
         $this->assertCount(2, $result);
-        $this->assertEquals('Event 4', $result[0]->name);
-        $this->assertEquals('Event 5', $result[1]->name);
+        $this->assertEquals('Event 4', $result[0]->get_name());
+        $this->assertEquals('Event 5', $result[1]->get_name());
 
-        $result = api::get_action_events_by_course($course1, 2, 7, $event5->id, 2);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, 2, 7, $event5->id, 2);
 
         $this->assertCount(2, $result);
-        $this->assertEquals('Event 6', $result[0]->name);
-        $this->assertEquals('Event 7', $result[1]->name);
+        $this->assertEquals('Event 6', $result[0]->get_name());
+        $this->assertEquals('Event 7', $result[1]->get_name());
 
-        $result = api::get_action_events_by_course($course1, 2, 7, $event7->id, 2);
+        $result = \core_calendar\local\api::get_action_events_by_course($course1, 2, 7, $event7->id, 2);
 
         $this->assertEmpty($result);
     }
@@ -567,45 +565,45 @@ class core_calendar_api_testcase extends advanced_testcase {
         $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 8]));
         $event9 = create_event(array_merge($params, ['name' => 'Event 9', 'timesort' => 9]));
 
-        $result = api::get_action_events_by_courses([], 1);
+        $result = \core_calendar\local\api::get_action_events_by_courses([], 1);
 
         $this->assertEmpty($result);
 
-        $result = api::get_action_events_by_courses([$course1], 3);
+        $result = \core_calendar\local\api::get_action_events_by_courses([$course1], 3);
 
         $this->assertEmpty($result[$course1->id]);
 
-        $result = api::get_action_events_by_courses([$course1], 1);
+        $result = \core_calendar\local\api::get_action_events_by_courses([$course1], 1);
 
         $this->assertCount(2, $result[$course1->id]);
-        $this->assertEquals('Event 1', $result[$course1->id][0]->name);
-        $this->assertEquals('Event 2', $result[$course1->id][1]->name);
+        $this->assertEquals('Event 1', $result[$course1->id][0]->get_name());
+        $this->assertEquals('Event 2', $result[$course1->id][1]->get_name());
 
-        $result = api::get_action_events_by_courses([$course1, $course2], 1);
+        $result = \core_calendar\local\api::get_action_events_by_courses([$course1, $course2], 1);
 
         $this->assertCount(2, $result[$course1->id]);
-        $this->assertEquals('Event 1', $result[$course1->id][0]->name);
-        $this->assertEquals('Event 2', $result[$course1->id][1]->name);
+        $this->assertEquals('Event 1', $result[$course1->id][0]->get_name());
+        $this->assertEquals('Event 2', $result[$course1->id][1]->get_name());
         $this->assertCount(3, $result[$course2->id]);
-        $this->assertEquals('Event 3', $result[$course2->id][0]->name);
-        $this->assertEquals('Event 4', $result[$course2->id][1]->name);
-        $this->assertEquals('Event 5', $result[$course2->id][2]->name);
+        $this->assertEquals('Event 3', $result[$course2->id][0]->get_name());
+        $this->assertEquals('Event 4', $result[$course2->id][1]->get_name());
+        $this->assertEquals('Event 5', $result[$course2->id][2]->get_name());
 
-        $result = api::get_action_events_by_courses([$course1, $course2], 2, 4);
+        $result = \core_calendar\local\api::get_action_events_by_courses([$course1, $course2], 2, 4);
 
         $this->assertCount(1, $result[$course1->id]);
-        $this->assertEquals('Event 2', $result[$course1->id][0]->name);
+        $this->assertEquals('Event 2', $result[$course1->id][0]->get_name());
         $this->assertCount(2, $result[$course2->id]);
-        $this->assertEquals('Event 3', $result[$course2->id][0]->name);
-        $this->assertEquals('Event 4', $result[$course2->id][1]->name);
+        $this->assertEquals('Event 3', $result[$course2->id][0]->get_name());
+        $this->assertEquals('Event 4', $result[$course2->id][1]->get_name());
 
-        $result = api::get_action_events_by_courses([$course1, $course2, $course3], 1, null, 1);
+        $result = \core_calendar\local\api::get_action_events_by_courses([$course1, $course2, $course3], 1, null, 1);
 
         $this->assertCount(1, $result[$course1->id]);
-        $this->assertEquals('Event 1', $result[$course1->id][0]->name);
+        $this->assertEquals('Event 1', $result[$course1->id][0]->get_name());
         $this->assertCount(1, $result[$course2->id]);
-        $this->assertEquals('Event 3', $result[$course2->id][0]->name);
+        $this->assertEquals('Event 3', $result[$course2->id][0]->get_name());
         $this->assertCount(1, $result[$course3->id]);
-        $this->assertEquals('Event 6', $result[$course3->id][0]->name);
+        $this->assertEquals('Event 6', $result[$course3->id][0]->get_name());
     }
 }