diff --git a/block_news.php b/block_news.php index 901effb..ba9686f 100644 --- a/block_news.php +++ b/block_news.php @@ -48,7 +48,7 @@ public function specialization() { * * @return stdClass - the block content. */ - public function get_content() : stdClass { + public function get_content(): stdClass { global $OUTPUT; if ($this->content !== null) { @@ -82,7 +82,7 @@ public function get_content() : stdClass { * * @return array news items. */ - public function fetch_news() : array { + public function fetch_news(): array { // Template data for mustache. $template = new stdClass(); @@ -144,7 +144,7 @@ public function fetch_news() : array { * * @return array of the pages where the block can be added. */ - public function applicable_formats() : array { + public function applicable_formats(): array { return [ 'admin' => false, 'site-index' => true, @@ -159,7 +159,7 @@ public function applicable_formats() : array { * * @return bool. */ - public function instance_allow_multiple() : bool { + public function instance_allow_multiple(): bool { return false; } @@ -168,7 +168,7 @@ public function instance_allow_multiple() : bool { * * @return bool. */ - public function has_config() : bool { + public function has_config(): bool { return true; } } diff --git a/tests/behat/show_news.feature b/tests/behat/show_news.feature new file mode 100644 index 0000000..1d21ff4 --- /dev/null +++ b/tests/behat/show_news.feature @@ -0,0 +1,74 @@ +@block @block_news @javascript +Feature: Show news + In order to be informed about news + As a user + I need to be able to see the news block on my dashboard but not on my course page. + + Background: + Given the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exist: + | username | + | teacher1 | + | student1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | news | System | 1 | my-index | full-b | + And the following config values are set as admin: + | config | value | plugin | + | title1 | News Title One | block_news | + | description1 | News Description One | block_news | + | link1 | https://apple.com | block_news | + | title2 | News Title Two | block_news | + | description2 | News Description Two | block_news | + | link2 | https://google.com | block_news | + | title3 | News Title Three | block_news | + | description3 | News Description Three | block_news | + | link3 | https://ucl.ac.uk | block_news | + + Scenario: See news on my dashboard page as admin. + When I log in as "admin" + Then I should see "News" + And I should see "News Title One" + And I should see "News Title Two" + And I should see "News Title Three" + + Scenario: See no news on the course home page as admin. + When I am on the "Course 1" course page logged in as admin + Then I should not see "News" + And I should not see "News Title One" + And I should not see "News Title Two" + And I should not see "News Title Three" + + Scenario: See news on my dashboard page as teacher. + When I log in as "teacher1" + Then I should see "News" + And I should see "News Title One" + And I should see "News Title Two" + And I should see "News Title Three" + + Scenario: See no news on the course home page as teacher. + When I am on the "Course 1" course page logged in as teacher1 + Then I should not see "News" + And I should not see "News Title One" + And I should not see "News Title Two" + And I should not see "News Title Three" + + Scenario: See news on my dashboard page as student. + When I log in as "student1" + Then I should see "News" + And I should see "News Title One" + And I should see "News Title Two" + And I should see "News Title Three" + + Scenario: See no news on the course home page as student. + When I am on the "Course 1" course page logged in as student1 + Then I should not see "News" + And I should not see "News Title One" + And I should not see "News Title Two" + And I should not see "News Title Three"