diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..117bb3a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,111 @@ +name: Moodle Plugin CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-22.04 + + services: + postgres: + image: postgres:12 + 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 + mariadb: + image: mariadb:10 + env: + MYSQL_USER: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + MYSQL_CHARACTER_SET_SERVER: "utf8mb4" + MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" + + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + + strategy: + fail-fast: false + matrix: + php: [ '7.4', '8.0' ] + moodle-branch: [ 'MOODLE_311_STABLE','MOODLE_400_STABLE' ] + database: [ pgsql, 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 + # none to use phpdbg fallback. Specify pcov (Moodle 3.10 and up) or xdebug to use them instead. + 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 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: PHP Copy/Paste Detector + continue-on-error: true # This step will show errors but will not fail + if: ${{ always() }} + run: moodle-plugin-ci phpcpd + + - name: PHP Mess Detector + continue-on-error: true # This step will show errors but will not fail + if: ${{ always() }} + run: moodle-plugin-ci phpmd + + - name: Moodle Code Checker + if: ${{ always() }} + run: moodle-plugin-ci codechecker --max-warnings 0 + + - name: Moodle PHPDoc Checker + if: ${{ always() }} + run: moodle-plugin-ci phpdoc + + - name: Validating + if: ${{ always() }} + run: moodle-plugin-ci validate + + - name: Check upgrade savepoints + if: ${{ always() }} + run: moodle-plugin-ci savepoints + + - name: Mustache Lint + if: ${{ always() }} + run: moodle-plugin-ci mustache + + - name: Grunt + if: ${{ always() }} + run: moodle-plugin-ci grunt --max-lint-warnings 0 + + - name: PHPUnit tests + if: ${{ always() }} + run: moodle-plugin-ci phpunit --fail-on-warning + + - name: Behat features + if: ${{ always() }} + run: moodle-plugin-ci behat --profile chrome diff --git a/amd/src/config.js b/amd/src/config.js index 646d8d2..4e7970c 100644 --- a/amd/src/config.js +++ b/amd/src/config.js @@ -1,11 +1,10 @@ /** * RSS Thumbnails block * - * @package block_rss_thumbnails * @copyright 2020 - CALL Learning - Laurent David * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['core/config'], function (cfg) { +define(['core/config'], function(cfg) { window.requirejs.config({ paths: { "glide": diff --git a/amd/src/glide.js b/amd/src/glide.js index b0c7b91..a7fe35e 100644 --- a/amd/src/glide.js +++ b/amd/src/glide.js @@ -1,13 +1,12 @@ /** * RSS Thumbnails block * - * @package block_rss_thumbnails * @copyright 2020 - CALL Learning - Laurent David * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define([ 'jquery', 'block_rss_thumbnails/config'], function ($) { - return function (locator, config) { - require(['glide'], function (Glide) { +define(['jquery', 'block_rss_thumbnails/config'], function($) { + return function(locator, config) { + require(['glide'], function(Glide) { // Show the slider now we are initialised. $(locator).removeClass('d-none'); new Glide(locator, config).mount(); diff --git a/block_rss_thumbnails.php b/block_rss_thumbnails.php index 402c6d9..cf8bb1c 100644 --- a/block_rss_thumbnails.php +++ b/block_rss_thumbnails.php @@ -22,7 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use block_rss_client\output\channel_image; +use block_rss_client\output\feed; use block_rss_thumbnails\output\block; +use block_rss_thumbnails\output\item; defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -37,6 +40,7 @@ */ class block_rss_thumbnails extends block_rss_client { + /** @var int The default caroussel speed */ const DEFAULT_CAROUSSEL_SPEED = 4000; /** @var bool track whether any of the output feeds have recorded failures */ @@ -54,7 +58,7 @@ public function init() { /** * Content for the block * - * @return \stdClass|string|null + * @return stdClass|string|null * @throws coding_exception */ public function get_content() { @@ -67,7 +71,7 @@ public function get_content() { return $this->content; } - // initalise block content object + // Initialise block content object. $this->content = new stdClass; $this->content->text = ''; $this->content->footer = ''; @@ -78,7 +82,7 @@ public function get_content() { if (!isset($this->config)) { // The block has yet to be configured - just display configure message in - // the block if user has permission to configure it + // the block if user has permission to configure it. if (has_capability('block/rss_client:manageanyfeeds', $this->context)) { $this->content->text = get_string('feedsconfigurenewinstance2', 'block_rss_client'); @@ -138,7 +142,7 @@ public function get_content() { * @param array $feedrecords The feed records from the database. * @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed. */ - protected function get_footer($feedrecords) { + protected function get_footer($feedrecords) : ?block_rss_client\output\footer { $footer = null; if (!empty($this->config->show_channel_link)) { @@ -171,12 +175,12 @@ protected function get_footer($feedrecords) { /** * Returns the html of a feed to be displaed in the block * - * @param mixed feedrecord The feed record from the database - * @param int maxentries The maximum number of entries to be displayed - * @param boolean showtitle Should the feed title be displayed in html + * @param mixed $feedrecord The feed record from the database + * @param int $maxentries The maximum number of entries to be displayed + * @param boolean $showtitle Should the feed title be displayed in html * @return block_rss_client\output\feed|null The renderable feed or null of there is an error */ - public function get_feed($feedrecord, $maxentries, $showtitle) { + public function get_feed($feedrecord, $maxentries, $showtitle) : ?feed { global $CFG; require_once($CFG->libdir . '/simplepie/moodle_simplepie.php'); @@ -186,7 +190,15 @@ public function get_feed($feedrecord, $maxentries, $showtitle) { return null; } - $simplepiefeed = new moodle_simplepie($feedrecord->url); + if (!empty($feedrecord->url)) { + $simplepiefeed = new moodle_simplepie($feedrecord->url); + } else { + $simplepiefeed = new moodle_simplepie(); + $simplepiefeed->set_file($feedrecord->fileurl); + $simplepiefeed->enable_cache(false); + $simplepiefeed->init(); + + } if (isset($CFG->block_rss_client_timeout)) { $simplepiefeed->set_cache_duration($CFG->block_rss_client_timeout * 60); @@ -209,12 +221,12 @@ public function get_feed($feedrecord, $maxentries, $showtitle) { } if (empty($this->config->title)) { - //NOTE: this means the 'last feed' displayed wins the block title - but - //this is exiting behaviour.. + // NOTE: this means the 'last feed' displayed wins the block title - but + // this is exiting behaviour.. $this->title = strip_tags($feedtitle); } - $feed = new \block_rss_client\output\feed($feedtitle, $showtitle, false); + $feed = new feed($feedtitle, $showtitle, false); if ($simplepieitems = $simplepiefeed->get_items(0, $maxentries)) { foreach ($simplepieitems as $simplepieitem) { @@ -231,7 +243,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) { return $cat->term; }, $simplepieitem->get_categories()); - $item = new \block_rss_thumbnails\output\item( + $item = new item( $simplepieitem->get_id(), new moodle_url($simplepieitem->get_link()), $simplepieitem->get_title(), @@ -247,7 +259,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) { } catch (moodle_exception $e) { // If there is an error with the RSS item, we don't // want to crash the page. Specifically, moodle_url can - // throw an exception of the param is an extremely + // throw an exception if the param is an extremely // malformed url. debugging($e->getMessage()); } @@ -257,7 +269,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) { // Feed image. if ($imageurl = $simplepiefeed->get_image_url()) { try { - $image = new \block_rss_client\output\channel_image( + $image = new channel_image( new moodle_url($imageurl), $simplepiefeed->get_image_title(), new moodle_url($simplepiefeed->get_image_link()) @@ -265,7 +277,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) { $feed->set_image($image); } catch (moodle_exception $e) { - // If there is an error with the RSS image, we don'twant to + // If there is an error with the RSS image, we don't want to // crash the page. Specifically, moodle_url can throw an // exception if the param is an extremely malformed url. debugging($e->getMessage()); diff --git a/classes/output/block.php b/classes/output/block.php index 574c9d0..227e553 100644 --- a/classes/output/block.php +++ b/classes/output/block.php @@ -23,7 +23,8 @@ */ namespace block_rss_thumbnails\output; -defined('MOODLE_INTERNAL') || die(); + +use renderer_base; /** * Class to help display an RSS Feeds block @@ -32,26 +33,28 @@ * @copyright 2020 - CALL Learning - Laurent David * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class block extends \block_rss_client\output\block { +class block extends \block_rss_client\output\block { - protected $carousselspeed = 0; + /** @var int The delay between two slides */ + protected int $carousselspeed = 0; /** * Contruct * + * @param int $carousselspeed the caroussel speed of the block * @param array $feeds An array of renderable feeds */ public function __construct($carousselspeed, array $feeds = array()) { - $this->feeds = $feeds; + parent::__construct($feeds); $this->carousselspeed = $carousselspeed; } /** * Prepare data for use in a template * - * @param \renderer_base $output + * @param renderer_base $output * @return array */ - public function export_for_template(\renderer_base $output) { + public function export_for_template(renderer_base $output): array { $data = parent::export_for_template($output); $data['carousselspeed'] = $this->carousselspeed; return $data; diff --git a/classes/output/item.php b/classes/output/item.php index abfa08e..53806f0 100644 --- a/classes/output/item.php +++ b/classes/output/item.php @@ -23,9 +23,9 @@ */ namespace block_rss_thumbnails\output; +use core_text; use moodle_url; - -defined('MOODLE_INTERNAL') || die(); +use renderer_base; /** * Class to help display an RSS Item @@ -35,35 +35,34 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class item extends \block_rss_client\output\item { + /** @var ?string The url of the RSS item's image */ protected $imageurl = null; + + /** @var ?array The categories of the RSS item*/ protected $categories = null; /** * Contructor * * @param string $id The id of the RSS item - * @param \moodle_url $link The URL of the RSS item + * @param moodle_url $link The URL of the RSS item * @param string $title The title pf the RSS item * @param string $description The description of the RSS item - * @param \moodle_url $permalink The permalink of the RSS item + * @param moodle_url $permalink The permalink of the RSS item * @param int $timestamp The Unix timestamp that represents the published date - * @param boolean $showdescription Whether or not to show the description + * @param boolean $showdescription Whether to show the description + * @param string $imageurl the image's url of the item + * @param array $categories the categories of the item */ - public function __construct($id, \moodle_url $link, + public function __construct($id, moodle_url $link, $title, $description, - \moodle_url $permalink, + moodle_url $permalink, $timestamp, $showdescription = true, $imageurl = null, $categories ) { - $this->id = $id; - $this->link = $link; - $this->title = $title; - $this->description = $description; - $this->permalink = $permalink; - $this->timestamp = $timestamp; - $this->showdescription = $showdescription; + parent::__construct($id, $link, $title, $description, $permalink, $timestamp, $showdescription); $this->imageurl = $imageurl; $this->categories = $categories; } @@ -75,7 +74,7 @@ public function __construct($id, \moodle_url $link, * @return array * @see templatable::export_for_template() */ - public function export_for_template(\renderer_base $output) { + public function export_for_template(renderer_base $output) : array { $data = array( 'id' => $this->id, 'permalink' => clean_param($this->permalink, PARAM_URL), @@ -89,7 +88,7 @@ public function export_for_template(\renderer_base $output) { $title = $this->title; if (!$title) { $title = strip_tags($this->description); - $title = \core_text::substr($title, 0, 20) . '...'; + $title = core_text::substr($title, 0, 20) . '...'; } // Allow the renderer to format the title and description. diff --git a/classes/output/renderer.php b/classes/output/renderer.php index cdfbb25..fa78cea 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -24,7 +24,8 @@ namespace block_rss_thumbnails\output; -defined('MOODLE_INTERNAL') || die(); + +use templatable; /** * Renderer for RSS Client block @@ -37,10 +38,10 @@ class renderer extends \block_rss_client\output\renderer { /** * Render an RSS feeds block * - * @param \templatable $block + * @param templatable $block * @return string|boolean */ - public function render_block(\templatable $block) { + public function render_block(templatable $block) { $data = $block->export_for_template($this); return $this->render_from_template('block_rss_thumbnails/block', $data); diff --git a/edit_form.php b/edit_form.php index a861281..dcbadf0 100644 --- a/edit_form.php +++ b/edit_form.php @@ -35,8 +35,11 @@ */ class block_rss_thumbnails_edit_form extends block_rss_client_edit_form { /** + * Creates a form to define caroussel's parameteters + * * @param HTML_QuickForm $mform * @throws coding_exception + * @return void */ protected function specific_definition($mform) { parent::specific_definition($mform); @@ -51,7 +54,11 @@ protected function specific_definition($mform) { $mform->setDefault('config_show_channel_link', false); $mform->setType('config_show_channel_link', PARAM_BOOL); - $mform->addElement('selectyesno', 'config_remove_image_size_suffix', get_string('removeimagesizesuffix', 'block_rss_thumbnails')); + $mform->addElement( + 'selectyesno', + 'config_remove_image_size_suffix', + get_string('removeimagesizesuffix', 'block_rss_thumbnails') + ); $mform->setDefault('config_remove_image_size_suffix', false); $mform->setType('config_remove_image_size_suffix', PARAM_BOOL); } diff --git a/lang/en/block_rss_thumbnails.php b/lang/en/block_rss_thumbnails.php index db08cdf..c5ce2d6 100644 --- a/lang/en/block_rss_thumbnails.php +++ b/lang/en/block_rss_thumbnails.php @@ -27,4 +27,4 @@ $string['pluginname'] = 'RSS Thumnail'; $string['title'] = 'RSS Thumnail'; $string['carousselspeed'] = 'Caroussel speed'; -$string['removeimagesizesuffix'] = 'Remove image size suffix (wordpress RSS).'; \ No newline at end of file +$string['removeimagesizesuffix'] = 'Remove image size suffix (wordpress RSS).'; diff --git a/settings.php b/settings.php deleted file mode 100644 index f3bbd1e..0000000 --- a/settings.php +++ /dev/null @@ -1,25 +0,0 @@ -. - -/** - * Vetagro news block caps. - * - * @package block_rss_thumbnails - * @copyright 2020 - CALL Learning - Laurent David - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); diff --git a/templates/block.mustache b/templates/block.mustache index c118f73..a9bcc35 100644 --- a/templates/block.mustache +++ b/templates/block.mustache @@ -30,6 +30,7 @@ Example context (json): { + "carousselspeed": 1, "feeds": [ { "title": "News from around my living room", @@ -98,7 +99,7 @@
  • {{#imageurl}} - + Item image {{/imageurl}}
    {{ title }}
    @@ -126,6 +127,7 @@ gap: 20, autoplay: {{ carousselspeed }} } - ); + ); }); -{{/js}} \ No newline at end of file +{{/js}} +
    \ No newline at end of file diff --git a/tests/block_rss_thumbnails_test.php b/tests/block_rss_thumbnails_test.php index ce7b2d8..64f0dfc 100644 --- a/tests/block_rss_thumbnails_test.php +++ b/tests/block_rss_thumbnails_test.php @@ -18,19 +18,25 @@ * Base class for unit tests for block_rss_thumbnails. * * @package block_rss_thumbnails - * @copyright 2020 - CALL Learning - Laurent David + * @copyright 2022 - CALL Learning - Martin CORNU-MANSUY * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace block_rss_thumbnails; -use block_thumblinks_action\output\thumblinks_action; -use block_rss_thumbnails\feed_manager; - -defined('MOODLE_INTERNAL') || die(); +use advanced_testcase; +use block_base; +use block_rss_client\task\refreshfeeds; +use context_system; +use dml_exception; +use moodle_page; +use moodle_simplepie; +use SimplePie_File; +use stdClass; /** - * Unit tests for block_rss_thumbnails + * Unit tests for block_rss_thumbnails. * - * @copyright 2020 - CALL Learning - Laurent David + * @copyright 2022 - CALL Learning - Martin CORNU-MANSUY * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class block_rss_thumbnails_test extends advanced_testcase { @@ -39,55 +45,53 @@ class block_rss_thumbnails_test extends advanced_testcase { * Expected config data. */ const EXPECTED_CONFIG = '[{"imageurl":"http:\/\/mysite.fr\/wp-content\/uploads\/2020\/11\/DSC_0009-2-480x519.jpg",' - .'"linkurl":"http:\/\/mysite.fr\/la-sante-globale-fil-conducteur-de-la-strategie-detablissement\/",' - .'"categories":[{"text":"One Health"}],"date":"1604419500","title":"La sant\u00e9 globale, fil conducteur de la strat\u00e9gie' - .' d\u2019\u00e9tablissement"},{"imageurl":"http:\/\/mysite.fr\/wp-content\/uploads\/2020\/10\/Rentree-VETO-2020-1024x504.jpg"' - .',"linkurl":"http:\/\/mysite.fr\/les-chiffres-cles-de-la-rentree-2020-de-vetagro-sup\/","categories":[{"text":"Etudiants"}' - .',{"text":"Formations"}],"date":"1603116642","title":"Les chiffres cl\u00e9s de la rentr\u00e9e 2020 de VetAgro Sup"}]'; + . '"linkurl":"http:\/\/mysite.fr\/la-sante-globale-fil-conducteur-de-la-strategie-detablissement\/",' + . '"categories":[{"text":"One Health"}],"date":"1604419500","title":"La sant\u00e9 globale, fil conducteur de la strat\u00e9gie' + . ' d\u2019\u00e9tablissement"},{"imageurl":"http:\/\/mysite.fr\/wp-content\/uploads\/2020\/10\/Rentree-VETO-2020-1024x504.jpg"' + . ',"linkurl":"http:\/\/mysite.fr\/les-chiffres-cles-de-la-rentree-2020-de-vetagro-sup\/","categories":[{"text":"Etudiants"}' + . ',{"text":"Formations"}],"date":"1603116642","title":"Les chiffres cl\u00e9s de la rentr\u00e9e 2020 de VetAgro Sup"}]'; /** - * Current block - * - * @var block_base|false|null + * @var block_base|false|null Current block */ protected $block = null; /** - * Current user - * - * @var stdClass|null + * @var stdClass|null Current user */ protected $user = null; + /** @var array|object Feed record */ + private $record; + /** * Basic setup for these tests. */ - public function setUp() { - global $DB; - $this->resetAfterTest(true); + public function setUp(): void { + global $DB, $CFG; + $this->resetAfterTest(); // Insert a new RSS Feed. - require_once("{$CFG->libdir}/simplepie/moodle_simplepie.php"); + require_once("$CFG->libdir/simplepie/moodle_simplepie.php"); - $time = time(); // A record that has failed before. - $record = (object) [ + $this->record = (object) [ 'userid' => 1, 'title' => 'Skip test feed', 'preferredtitle' => '', 'description' => 'A feed to test the skip time.', 'shared' => 0, - 'url' => 'http://example.com/rss', + 'url' => '', 'skiptime' => 0, 'skipuntil' => 0, ]; - $record->id = $DB->insert_record('block_rss_client', $record); + $this->record->id = $DB->insert_record('block_rss_client', $this->record); // Run the scheduled task and have it fail. - $task = $this->getMockBuilder(\block_rss_client\task\refreshfeeds::class) + $task = $this->getMockBuilder(refreshfeeds::class) ->setMethods(['fetch_feed']) ->getMock(); - $piemock = $this->getMockBuilder(\moodle_simplepie::class) + $piemock = $this->getMockBuilder(moodle_simplepie::class) ->setMethods(['error']) ->getMock(); @@ -97,7 +101,6 @@ public function setUp() { $task->method('fetch_feed') ->willReturn($piemock); - $this->user = $this->getDataGenerator()->create_user(); $this->setUser($this->user); $page = new moodle_page(); @@ -121,81 +124,153 @@ public function setUp() { $blocks = $page->blocks->get_blocks_for_region($page->blocks->get_default_region()); $block = end($blocks); $block = block_instance($blockname, $block->instance); + $configdata = ['display_description' => true]; + $block->instance_config_save((object) $configdata); $this->block = $block; $block = block_instance_by_id($this->block->instance->id); - $configdata = (object) feed_manager::DEFAULT_VALUES; - $block->instance_config_save((object) $configdata); $this->block = $block; } /** - * Test that we can retrieve an article from a feedd + * Tests if the feed returned by {@see \block_rss_thumbnails::get_feed()} method is valid. + * + * @return void + * @covers \block_rss_thumbnails::get_feeds */ - public function test_get_articles_from_page() { + public function test_get_feed() { global $CFG; - // We need to reload the block so config is there. - $block = block_instance_by_id($this->block->instance->id); - $feedmanager = new mock_feed_manager($block); - $content = file_get_contents($CFG->dirroot.'/blocks/rss_thumbnails/tests/fixtures/sample-feed.txt'); - $settings = $feedmanager->get_articles_from_page($content); - $this->assertEquals(json_decode(self::EXPECTED_CONFIG), $settings); + + $rssfeed = (object) [ + 'skipuntil' => 0, + 'fileurl' => new SimplePie_File($CFG->dirroot . '/blocks/rss_thumbnails/tests/fixtures/sample-feed.xml') + ]; + + $feed = $this->block->get_feed($rssfeed, 5, true); + $exporteddata = $feed->export_for_template( + $this->block->page->get_renderer('block_rss_thumbnails') + ); + $this->assertEquals("IMT", $exporteddata['title']); + $this->assertNull($exporteddata['image']); } + /** + * Tests if the items of the feed returned by the {@see \block_rss_thumbnails::get_feed()} method are valid. + * + * @return void + * @covers \block_rss_thumbnails::get_feed + */ + public function test_get_feed_items() { + global $CFG; + $rssfeed = (object) [ + 'skipuntil' => 0, + 'fileurl' => new SimplePie_File($CFG->dirroot . '/blocks/rss_thumbnails/tests/fixtures/sample-feed.xml') + ]; + + $feed = $this->block->get_feed($rssfeed, 5, true); + $exporteddata = $feed->export_for_template( + $this->block->page->get_renderer('block_rss_thumbnails') + ); + $expecteditems = self::get_expected_items(); + $items = $exporteddata["items"]; + for ($index = 0; $index < count($expecteditems); $index++) { + self::assertEquals($expecteditems[$index], $items[$index]); + } + + } /** - * Test that output is as expected. This also test file loading into the plugin. + * Get expected items to be returned by the get_feed. + * + * @return array[] */ - public function test_simple_content() { - // We need to reload the block so config is there. - $block = block_instance_by_id($this->block->instance->id); - $block->config->articles = json_decode(self::EXPECTED_CONFIG); - $block->instance_config_save($block->config); - $content = $block->get_content(); - $this->assertNotNull($content->text); - - $expected = '
    '; - $text = preg_replace('/ id="block-vetagro-news([^"]+)"/i', '', $content->text); - $this->assertEquals($expected, $text); + final private static function get_expected_items() { + return [ + [ + "id" => "https://www.imt.fr/?p=89572", + "permalink" => "https://www.imt.fr/odyssea-les-personnels-de-linstitut-mines-telecom-mobilises-pour". + "-la-lutte-contre-le-cancer-du-sein/", + "timestamp" => strtotime("Wed, 19 Oct 2022 13:57:11 +0000"), + "link" => "https://www.imt.fr/odyssea-les-personnels-de-linstitut-mines-telecom-mobilises-pour". + "-la-lutte-contre-le-cancer-du-sein/", + "imageurl" => "https://www.imt.fr/wp-content/uploads/2022/10/Odyssea2022_montage-groupes-80x80.png", + "categories" => [ + "À la une", + "Actualités", + "course", + "Odyssea" + ], + "title" => "Odyssea : les personnels de l’Institut Mines-Télécom mobilisés pour la lutte contre le cancer du sein", + "description" => "Dimanche 2 octobre s'est tenu la course Odyssea où l'Institut Mines-Télécom s'est mobilisé ". + "pour soutenir la lutte contre le cancer du sein." + ], [ + "id" => "https://www.imt.fr/?p=89556", + "permalink" => "https://www.imt.fr/nouvelles-start-up-beneficiaires-des-fonds-de-pret-dhonneur". + "-imt-numerique-et-industrie-et-energie-4-0/", + "timestamp" => strtotime("Tue, 18 Oct 2022 14:34:00 +0000"), + "link" => "https://www.imt.fr/nouvelles-start-up-beneficiaires-des-fonds-de-pret-dhonneur". + "-imt-numerique-et-industrie-et-energie-4-0/", + "imageurl" => "https://www.imt.fr/wp-content/uploads/2022/10/start-up-80x80.jpg", + "categories" => [ + "À la une", + "Actualités", + "prêts d'honneur", + "start-up" + ], + "title" => "Nouvelles start-up bénéficiaires des fonds de prêt d’honneur IMT « Numérique » ". + "et « Industrie et Energie 4.0 »", + "description" => "Le comité du Fonds IMT Numérique et du Fonds Industrie et Energie 4.0 et se sont réunis". + " le 20 septembre et 11 octobre pour attribuer des prêts d'honneurs à de nouvelles start-up." + ], [ + "id" => "https://www.imt.fr/?p=89147", + "permalink" => "https://www.imt.fr/suivez-les-lives-imt-pour-lindustrie-du-futur/", + "timestamp" => strtotime("Wed, 05 Oct 2022 12:59:57 +0000"), + "link" => "https://www.imt.fr/suivez-les-lives-imt-pour-lindustrie-du-futur/", + "imageurl" => "https://www.imt.fr/wp-content/uploads/2022/05/les-lives_IMT-industrie-du-futur_archer-80x80.png", + "categories" => [ + "À la une", + "Actualités", + "Live IMT industrie", + "Live" + ], + "title" => "Suivez les Lives IMT pour l’industrie du futur ! Rendez-vous le 20 octobre à 18h30", + "description" => "L’Observatoire des métiers et des compétences de l’Institut Mines-Télécom propose," . + " depuis mai, une nouvelle série de rendez-vous mensuels consacrés à l’industrie, portés par les " . + "étudiantes et étudiants de ses écoles  : les Lives IMT pour l’industrie du futur !" + ], [ + "id" => "https://www.imt.fr/?p=89403", + "permalink" => "https://www.imt.fr/2e-campagne-de-recrutement-2022-rejoignez-limt/", + "timestamp" => strtotime("Mon, 03 Oct 2022 10:40:07 +0000"), + "link" => "https://www.imt.fr/2e-campagne-de-recrutement-2022-rejoignez-limt/", + "imageurl" => "https://www.imt.fr/wp-content/uploads/2020/03/rejoindre_IMT-80x80.png", + "categories" => [ + "À la une", + "Actualités", + "CDD", + "CDI", + "emploi", + "offre d'emploi", + "recrutment" + ], + "title" => "2e campagne de recrutement 2022 : rejoignez l’IMT", + "description" => "Plus de 60 offres d’emploi en CDD ou CDI de droit public à pourvoir." + ], [ + "id" => "https://www.imt.fr/?p=89382", + "permalink" => "https://www.imt.fr/le-fonds-imt-numerique-et-igeu-fetent-leurs-10-ans/", + "timestamp" => strtotime("Fri, 30 Sep 2022 14:00:40 +0000"), + "link" => "https://www.imt.fr/le-fonds-imt-numerique-et-igeu-fetent-leurs-10-ans/", + "imageurl" => "https://www.imt.fr/wp-content/uploads/2022/09/10_ans_fonds_honneur-80x80.jpg", + "categories" => [ + "À la une", + "Actualités", + "Communiqués de presse", + "10 ans", + "Fonds IMT Numérique" + ], + "title" => "Le Fonds IMT Numérique et IGEU fêtent leurs 10 ans", + "description" => "Il y a 10 ans, l’Institut Mines Télécom (IMT), la Fondation Mines-Télécom et la Caisse des" . + " dépôts créaient Initiative Grandes Ecoles et Université (IGEU) et le Fonds IMT Numérique pour répondre au" . + " besoin de financement de jeunes projets d’entreprise." + ], + ]; } } - diff --git a/tests/fixtures/sample-feed.txt b/tests/fixtures/sample-feed.txt deleted file mode 100644 index 9727432..0000000 --- a/tests/fixtures/sample-feed.txt +++ /dev/null @@ -1,76 +0,0 @@ - - - - SAMPLE - - https://www.sample.fr - Premier groupe de grandes écoles d'ingénieurs et managers en France - Thu, 21 Jan 2021 12:39:44 +0000 - fr-FR - - hourly - - 1 - https://wordpress.org/?v=5.6 - - La Chaire « Valeurs et Politiques des Informations Personnelles » lance un cycle de conférences sur les identités numériques de confiance - https://www.sample.fr/la-chaire-valeurs-et-politiques-des-informations-personnelles-lance-un-cycle-de-conferences-sur-les-identites-numeriques-de-confiance/ - - - Wed, 20 Jan 2021 15:18:38 +0000 - - https://www.sample.fr/?p=76781 - - - - - - - - - Renouvellement de la charte Erasmus+ jusqu’en 2027 pour l’Sample org - https://www.sample.fr/renouvellement-de-la-charte-erasmus-jusquen-2027-pour-linstitut-mines-telecom/ - - - Wed, 20 Jan 2021 12:36:14 +0000 - - - - - - - - - https://www.sample.fr/?p=76765 - - - - - - - - - L’Sample org et elm.leblanc disruptent l’industrie du chauffage avec la Chaire industrielle CORENSTOCK - https://www.sample.fr/linstitut-mines-telecom-et-elm-leblanc-disruptent-lindustrie-du-chauffage-avec-la-chaire-industrielle-corenstock/ - - - Tue, 19 Jan 2021 13:43:39 +0000 - - - - https://www.sample.fr/?p=76705 - - - - - - - - diff --git a/tests/fixtures/sample-feed.xml b/tests/fixtures/sample-feed.xml new file mode 100644 index 0000000..4813aec --- /dev/null +++ b/tests/fixtures/sample-feed.xml @@ -0,0 +1,211 @@ + + + + IMT + + https://www.imt.fr/imt-accueil/ + Premier groupe de grandes écoles d'ingénieurs et managers en France + Wed, 19 Oct 2022 13:57:11 +0000 + fr-FR + + hourly + + 1 + https://wordpress.org/?v=6.0.3 + + Odyssea : les personnels de l’Institut Mines-Télécom mobilisés pour la lutte contre le cancer du sein + https://www.imt.fr/odyssea-les-personnels-de-linstitut-mines-telecom-mobilises-pour-la-lutte-contre-le-cancer-du-sein/ + + + Wed, 19 Oct 2022 13:57:11 +0000 + + + + + https://www.imt.fr/?p=89572 + + + + + + + + + Nouvelles start-up bénéficiaires des fonds de prêt d’honneur IMT « Numérique » et « Industrie et Energie 4.0 » + https://www.imt.fr/nouvelles-start-up-beneficiaires-des-fonds-de-pret-dhonneur-imt-numerique-et-industrie-et-energie-4-0/ + + + Tue, 18 Oct 2022 14:34:00 +0000 + + + + + https://www.imt.fr/?p=89556 + + + + + + + + + Suivez les Lives IMT pour l’industrie du futur ! Rendez-vous le 20 octobre à 18h30 + https://www.imt.fr/suivez-les-lives-imt-pour-lindustrie-du-futur/ + + + Wed, 05 Oct 2022 12:59:57 +0000 + + + + + https://www.imt.fr/?p=89147 + + + + + + + + + 2e campagne de recrutement 2022 : rejoignez l’IMT + https://www.imt.fr/2e-campagne-de-recrutement-2022-rejoignez-limt/ + + + Mon, 03 Oct 2022 10:40:07 +0000 + + + + + + + + https://www.imt.fr/?p=89403 + + + + + + + + + Le Fonds IMT Numérique et IGEU fêtent leurs 10 ans + https://www.imt.fr/le-fonds-imt-numerique-et-igeu-fetent-leurs-10-ans/ + + + Fri, 30 Sep 2022 14:00:40 +0000 + + + + + + https://www.imt.fr/?p=89382 + + + + + + + + + L’IMT intègre PariSanté Campus + https://www.imt.fr/limt-integre-parisante-campus/ + + + Wed, 14 Sep 2022 14:04:17 +0000 + + + + + + https://www.imt.fr/?p=89176 + + + + + + + + + L’IMT organise des webinaires Orientation vers les métiers de l’industrie du futur + https://www.imt.fr/limt-organise-des-webinaires-orientation-vers-les-metiers-de-lindustrie-du-futur/ + + + Fri, 09 Sep 2022 12:56:57 +0000 + + + + + + + + https://www.imt.fr/?p=89152 + + + + + + + + + Lancement de la 13e édition du Trophée Start-up Numérique + https://www.imt.fr/lancement-de-la-13e-edition-du-trophee-start-up-numerique/ + + + Thu, 08 Sep 2022 13:08:22 +0000 + + + + + https://www.imt.fr/?p=89185 + + + + + + + + + L’IMT consolide son partenariat avec Singapour dans le domaine de la santé digitale + https://www.imt.fr/limt-consolide-son-partenariat-avec-singapour-dans-le-domaine-de-la-sante-digitale/ + + + Fri, 02 Sep 2022 13:11:44 +0000 + + + + + https://www.imt.fr/?p=89033 + + + + + + + + + Campus Cyber : inauguration des locaux de l’IMT + https://www.imt.fr/campus-cyber-inauguration-des-locaux-de-limt/ + + + Wed, 31 Aug 2022 15:23:01 +0000 + + + + + https://www.imt.fr/?p=89013 + + + + + + + + + diff --git a/version.php b/version.php index 79c2cc2..fb72513 100644 --- a/version.php +++ b/version.php @@ -24,9 +24,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2021012200; // The current plugin version (Date: YYYYMMDDXX). -$plugin->requires = 2012112900; // Requires this Moodle version. -$plugin->component = 'block_rss_thumbnails'; // Full name of the plugin (used for diagnostics). -$plugin->dependencies = array( +$plugin->version = 2022101701; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2012112900; // Requires this Moodle version. +$plugin->component = 'block_rss_thumbnails'; // Full name of the plugin (used for diagnostics). +$plugin->dependencies = array( 'block_rss_client' => ANY_VERSION -); \ No newline at end of file +);