Skip to content

Commit

Permalink
added Behat test if news are shown
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Opitz committed Mar 15, 2024
1 parent 42dba87 commit 3803194
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
10 changes: 5 additions & 5 deletions block_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -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;
}

Expand All @@ -168,7 +168,7 @@ public function instance_allow_multiple() : bool {
*
* @return bool.
*/
public function has_config() : bool {
public function has_config(): bool {
return true;
}
}
74 changes: 74 additions & 0 deletions tests/behat/show_news.feature
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3803194

Please sign in to comment.