Skip to content

Commit 3803194

Browse files
author
Matthias Opitz
committed
added Behat test if news are shown
1 parent 42dba87 commit 3803194

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

block_news.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function specialization() {
4848
*
4949
* @return stdClass - the block content.
5050
*/
51-
public function get_content() : stdClass {
51+
public function get_content(): stdClass {
5252
global $OUTPUT;
5353

5454
if ($this->content !== null) {
@@ -82,7 +82,7 @@ public function get_content() : stdClass {
8282
*
8383
* @return array news items.
8484
*/
85-
public function fetch_news() : array {
85+
public function fetch_news(): array {
8686
// Template data for mustache.
8787
$template = new stdClass();
8888

@@ -144,7 +144,7 @@ public function fetch_news() : array {
144144
*
145145
* @return array of the pages where the block can be added.
146146
*/
147-
public function applicable_formats() : array {
147+
public function applicable_formats(): array {
148148
return [
149149
'admin' => false,
150150
'site-index' => true,
@@ -159,7 +159,7 @@ public function applicable_formats() : array {
159159
*
160160
* @return bool.
161161
*/
162-
public function instance_allow_multiple() : bool {
162+
public function instance_allow_multiple(): bool {
163163
return false;
164164
}
165165

@@ -168,7 +168,7 @@ public function instance_allow_multiple() : bool {
168168
*
169169
* @return bool.
170170
*/
171-
public function has_config() : bool {
171+
public function has_config(): bool {
172172
return true;
173173
}
174174
}

tests/behat/show_news.feature

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@block @block_news @javascript
2+
Feature: Show news
3+
In order to be informed about news
4+
As a user
5+
I need to be able to see the news block on my dashboard but not on my course page.
6+
7+
Background:
8+
Given the following "courses" exist:
9+
| fullname | shortname | category |
10+
| Course 1 | C1 | 0 |
11+
And the following "users" exist:
12+
| username |
13+
| teacher1 |
14+
| student1 |
15+
And the following "course enrolments" exist:
16+
| user | course | role |
17+
| teacher1 | C1 | editingteacher |
18+
| student1 | C1 | student |
19+
And the following "blocks" exist:
20+
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
21+
| news | System | 1 | my-index | full-b |
22+
And the following config values are set as admin:
23+
| config | value | plugin |
24+
| title1 | News Title One | block_news |
25+
| description1 | News Description One | block_news |
26+
| link1 | https://apple.com | block_news |
27+
| title2 | News Title Two | block_news |
28+
| description2 | News Description Two | block_news |
29+
| link2 | https://google.com | block_news |
30+
| title3 | News Title Three | block_news |
31+
| description3 | News Description Three | block_news |
32+
| link3 | https://ucl.ac.uk | block_news |
33+
34+
Scenario: See news on my dashboard page as admin.
35+
When I log in as "admin"
36+
Then I should see "News"
37+
And I should see "News Title One"
38+
And I should see "News Title Two"
39+
And I should see "News Title Three"
40+
41+
Scenario: See no news on the course home page as admin.
42+
When I am on the "Course 1" course page logged in as admin
43+
Then I should not see "News"
44+
And I should not see "News Title One"
45+
And I should not see "News Title Two"
46+
And I should not see "News Title Three"
47+
48+
Scenario: See news on my dashboard page as teacher.
49+
When I log in as "teacher1"
50+
Then I should see "News"
51+
And I should see "News Title One"
52+
And I should see "News Title Two"
53+
And I should see "News Title Three"
54+
55+
Scenario: See no news on the course home page as teacher.
56+
When I am on the "Course 1" course page logged in as teacher1
57+
Then I should not see "News"
58+
And I should not see "News Title One"
59+
And I should not see "News Title Two"
60+
And I should not see "News Title Three"
61+
62+
Scenario: See news on my dashboard page as student.
63+
When I log in as "student1"
64+
Then I should see "News"
65+
And I should see "News Title One"
66+
And I should see "News Title Two"
67+
And I should see "News Title Three"
68+
69+
Scenario: See no news on the course home page as student.
70+
When I am on the "Course 1" course page logged in as student1
71+
Then I should not see "News"
72+
And I should not see "News Title One"
73+
And I should not see "News Title Two"
74+
And I should not see "News Title Three"

0 commit comments

Comments
 (0)