diff --git a/classes/helper.php b/classes/helper.php index 7d69675..18244d2 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -24,8 +24,6 @@ namespace tool_rssfeeds; -defined('MOODLE_INTERNAL') || die(); - /** * Helper functions for tool_rssfeeds. * @@ -42,7 +40,7 @@ public static function delete_feed($feedid) { global $DB; $feed = self::get_feed($feedid); - $DB->delete_records('block_rss_client', array('id' => $feedid)); + $DB->delete_records('block_rss_client', ['id' => $feedid]); // Reprocess block configdata. if (empty($feed[$feedid]->instances)) { @@ -50,7 +48,7 @@ public static function delete_feed($feedid) { } foreach ($feed[$feedid]->instances as $instance) { - $block = $DB->get_record('block_instances', array('id' => $instance)); + $block = $DB->get_record('block_instances', ['id' => $instance]); $configdata = unserialize(base64_decode($block->configdata)); if (is_array($configdata->rssid) && ($key = array_search($feedid, $configdata->rssid)) !== false) { unset($configdata->rssid[$key]); @@ -70,7 +68,7 @@ public static function delete_feed($feedid) { public static function get_feed($feedid) { global $DB; - $rssfeed = $DB->get_records('block_rss_client', array('id' => $feedid)); + $rssfeed = $DB->get_records('block_rss_client', ['id' => $feedid]); return self::get_block_instances($rssfeed); } @@ -103,8 +101,8 @@ private static function get_block_instances($feeds) { // Prep the items in the feeds array. We need to store course ids and block instance ids. foreach ($feeds as $id => $feed) { - $feeds[$id]->courses = array(); - $feeds[$id]->instances = array(); + $feeds[$id]->courses = []; + $feeds[$id]->instances = []; } // Get all the block instances. @@ -112,7 +110,7 @@ private static function get_block_instances($feeds) { FROM {course} c INNER JOIN {context} ctx ON c.id=ctx.instanceid INNER JOIN {block_instances} bi ON ctx.id=bi.parentcontextid WHERE ctx.contextlevel=50 AND bi.blockname=?"; - $blocks = $DB->get_records_sql($blocksql, array('rss_client')); + $blocks = $DB->get_records_sql($blocksql, ['rss_client']); foreach ($blocks as $block) { $configdata = unserialize(base64_decode($block->configdata)); @@ -142,21 +140,21 @@ public static function display($feeds) { global $OUTPUT; $table = new \html_table(); - $table->head = array( + $table->head = [ get_string('feedurl', 'block_rss_client'), get_string('feedowner', 'tool_rssfeeds'), get_string('courses'), - get_string('actions') - ); + get_string('actions'), + ]; foreach ($feeds as $feed) { $feedurl = \html_writer::link( new \moodle_url($feed->url), $feed->url ); - $courses = array(); + $courses = []; foreach ($feed->courses as $id => $fullname) { $courses[] = \html_writer::link( - new \moodle_url('/course/view.php', array('id' => $id)), + new \moodle_url('/course/view.php', ['id' => $id]), $fullname ); } @@ -170,7 +168,7 @@ public static function display($feeds) { $deleteaction = $OUTPUT->action_icon( $deleteurl, $deleteicon, new \confirm_action(get_string('deletefeedconfirm', 'tool_rssfeeds'))); - $table->data[] = array($feedurl, \html_writer::link($userprofile, fullname($user)), $coursedisplay, $deleteaction); + $table->data[] = [$feedurl, \html_writer::link($userprofile, fullname($user)), $coursedisplay, $deleteaction]; } return $table; } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 682b4cd..7c78982 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -24,8 +24,6 @@ namespace tool_rssfeeds\privacy; -defined('MOODLE_INTERNAL') || die(); - /** * Privacy subsystem for tool_rssfeeds implementing null_provider. * diff --git a/tests/rss_manager_test.php b/tests/rss_manager_test.php index 2572781..8220044 100644 --- a/tests/rss_manager_test.php +++ b/tests/rss_manager_test.php @@ -22,6 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace tool_rssfeeds; + +use stdClass; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -36,7 +40,7 @@ * @copyright 2018 Lafayette College ITS * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class tool_rssfeeds_rss_manager_test extends advanced_testcase { +final class rss_manager_test extends \advanced_testcase { /** @var int The id for feed1 */ private $guestfeedid; @@ -53,55 +57,57 @@ class tool_rssfeeds_rss_manager_test extends advanced_testcase { * General setup for PHPUnit testing */ protected function setUp(): void { + parent::setUp(); + global $DB; $this->resetAfterTest(true); // Create a test user. - $this->enduser = $this->getDataGenerator()->create_user(array( + $this->enduser = $this->getDataGenerator()->create_user([ 'username' => 'enduser', 'firstname' => 'End', 'lastname' => 'User', - 'email' => 'enduser@example.com' - )); + 'email' => 'enduser@example.com', + ]); // Create an RSS feed for the guest user. - $record = (object) array( + $record = (object) [ 'userid' => 1, 'title' => 'Feed 1', 'preferredtitle' => '', 'description' => 'Feed 1 belongs to the guest user.', 'shared' => 0, 'url' => 'http://example.com/feed', - ); + ]; $this->guestfeedid = $DB->insert_record('block_rss_client', $record); // Create an RSS feed for enduser. - $record = (object) array( + $record = (object) [ 'userid' => $this->enduser->id, 'title' => 'Enduser Feed', 'preferredtitle' => '', 'description' => 'End User owns this feed.', 'shared' => 0, 'url' => 'http://example.com/atom', - ); + ]; $this->enduserfeedid = $DB->insert_record('block_rss_client', $record); // Create a couple courses. - $this->firstcourse = $this->getDataGenerator()->create_course(array( + $this->firstcourse = $this->getDataGenerator()->create_course([ 'fullname' => "A first course", 'shortname' => "first", - )); - $this->secondcourse = $this->getDataGenerator()->create_course(array( + ]); + $this->secondcourse = $this->getDataGenerator()->create_course([ 'fullname' => "A second course", 'shortname' => "second", - )); + ]); // Add a couple RSS blocks. $configdata = new stdClass; $configdata->displaydescription = 0; $configdata->shownumentries = 2; - $configdata->rssid = array($this->enduserfeedid); + $configdata->rssid = [$this->enduserfeedid]; $configdata->title = ''; $configdata->block_rss_client_show_channel_link = 0; $configdata->block_rss_client_show_channel_image = 0; @@ -137,9 +143,9 @@ protected function setUp(): void { /** * Test the get_feed helper function. */ - public function test_get_feed() { + public function test_get_feed(): void { // Confirm that we can get just the feed we want. - $feed = \tool_rssfeeds\helper::get_feed($this->guestfeedid); + $feed = helper::get_feed($this->guestfeedid); $this->assertEquals(1, count($feed)); $this->assertEquals(1, $feed[$this->guestfeedid]->userid); $this->assertEquals('Feed 1', $feed[$this->guestfeedid]->title); @@ -149,9 +155,9 @@ public function test_get_feed() { /** * Test the get_feeds helper function. */ - public function test_get_feeds() { + public function test_get_feeds(): void { // Confirm that we can get all feeds. - $feeds = \tool_rssfeeds\helper::get_feeds(); + $feeds = helper::get_feeds(); $this->assertEquals(2, count($feeds)); $this->assertEquals('http://example.com/atom', $feeds[$this->enduserfeedid]->url); } @@ -159,9 +165,9 @@ public function test_get_feeds() { /** * Test the display helper function. */ - public function test_display() { - $feeds = \tool_rssfeeds\helper::get_feeds(); - $table = \tool_rssfeeds\helper::display($feeds); + public function test_display(): void { + $feeds = helper::get_feeds(); + $table = helper::display($feeds); $this->assertInstanceOf('html_table', $table); $this->assertEquals(2, count($table->data)); $this->assertEquals('Not used in any courses', $table->data[0][2]); @@ -173,13 +179,13 @@ public function test_display() { /** * Test the delete_feed helper function. */ - public function test_delete_feed() { + public function test_delete_feed(): void { global $DB; - \tool_rssfeeds\helper::delete_feed($this->enduserfeedid); + helper::delete_feed($this->enduserfeedid); $this->assertEquals(1, $DB->count_records('block_rss_client')); - $feeds = \tool_rssfeeds\helper::get_feeds(); - $table = \tool_rssfeeds\helper::display($feeds); + $feeds = helper::get_feeds(); + $table = helper::display($feeds); $this->assertEquals(1, count($table->data)); } }