Commit b012c751 authored by Robert Lyon's avatar Robert Lyon

Bug 1496207: Use the get_link() to set the more link for inbox

Added a 'And the following "messages" exist:' behat step

Change-Id: I2d65a455a2eadf662105bf409ecf70fccdadc887
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 6dadf5d5
......@@ -104,7 +104,7 @@ class PluginBlocktypeInbox extends SystemBlocktype {
$smarty = smarty_core();
if ($showmore) {
$smarty->assign('desiredtypes', implode(',', $desiredtypes));
$smarty->assign('morelink', self::get_link($instance) . '?type=' . implode(',', $desiredtypes));
}
$smarty->assign('blockid', 'blockinstance_' . $instance->get('id'));
$smarty->assign('items', $records);
......
......@@ -738,4 +738,72 @@ EOD;
require_once('view.php');
View::update_view_access($viewconfig, $viewids);
}
/**
* A fixture to set up messages in bulk.
* Currently it only supports setting friend request / accept internal notifications
* @TODO allow for other types of messages
*
* Example:
* Given the following "messages" exist:
* | emailtype | to | from | subject | messagebody | read | url | urltext |
* | friendrequest | userA | userB | New friend request | This is a friend request | 1 | user/view.php?id=[from] | Requests |
* | friendaccept | userB | userA | Friend request accepted | This is a friend request acceptance | 1 | user/view.php?id=[to] | |
* @param unknown $record
* @throws SystemException
*/
public function create_message($record) {
$record['to'] = trim($record['to']);
$to = get_records_sql_array('SELECT id FROM {usr} WHERE LOWER(TRIM(username)) = ?', array(strtolower($record['to'])));
if (!$to || count($to) > 1) {
throw new SystemException("Invalid user '" . $record['to'] . "'. The username does not exist or duplicated");
}
$to = $to[0]->id;
$from = null;
if (strtolower($record['from']) != 'system') {
$from = get_records_sql_array('SELECT id FROM {usr} WHERE LOWER(TRIM(username)) = ?', array(strtolower($record['from'])));
if (!$from || count($from) > 1) {
throw new SystemException("Invalid user '" . $record['from'] . "'. The username does not exist or duplicated");
}
$from = $from[0]->id;
}
$emailtype = strtolower(trim($record['emailtype']));
if (!in_array($emailtype, array('friendrequest', 'friendaccept'))) {
throw new SystemException("Invalid emailtype '" . $emailtype . "'. The email type does not exist or is not yet set up");
}
$subject = !empty(trim($record['subject'])) ? trim($record['subject']) : 'Message subject';
$messagebody= !empty(trim($record['messagebody'])) ? trim($record['messagebody']) : 'Message body';
$read = !empty($record['read']) ? 1 : 0;
$url = null;
if (!empty(trim($record['url']))) {
$url = trim($record['url']);
// See if the url needs to have a correct id added to it. This works in the following way:
// the behat writer specifies the url and places the id var in [ ] and indicates where to
// get the id, eg 'view/user.php?id=[to]' means to fetch the id for the user specified in
// the 'to' column, which will be set above as variable $to
if (preg_match_all('/\[(?P<id>\w+)\]/', $url, $matches)) {
// replace the matched ids with their id number and set up replacement patterns
foreach ($matches['id'] as $k => $v) {
if (in_array($v, array('from', 'to'))) {
$matches['id'][$k] = $$v;
$matches[1][$k] = '/\[' . $v . '\]/';
}
}
$url = preg_replace($matches[1], $matches['id'], $url);
}
}
$urltext = !empty(trim($record['urltext'])) ? trim($record['urltext']) : null;
$users = array($to);
$data = new stdClass();
$data->url = $url;
$data->users = $users;
$data->fromuser = $from;
$data->strings = (object) array('urltext' => (object) array('key' => $urltext));
$data->subject = $subject;
$data->message = $messagebody;
$activity = new ActivityTypeMaharamessage($data, false);
$activity->notify_users();
}
}
\ No newline at end of file
......@@ -139,6 +139,20 @@ class BehatDataGenerators extends BehatBase {
'datagenerator' => 'institution_membership',
'required' => array('username', 'institutionname', 'role')
),
'messages' => array(
'datagenerator' => 'message',
'available' => array(
'emailtype' => 'text',
'to' => 'text',
'from' => 'text',
'subject' => 'text',
'messagebody' => 'text',
'read' => 'bool',
'url' => 'text',
'urltext' => 'text',
),
'required' => array('emailtype', 'to', 'subject'),
),
);
/**
......
......@@ -28,8 +28,8 @@
</tr>
{/foreach}
</table>
{if $desiredtypes}
<div class="morelinkwrap"><a class="morelink" href="{$WWWROOT}account/activity/index.php?type={$desiredtypes}">{str tag=More section=blocktype.inbox} &raquo;</a></div>
{if $morelink}
<div class="morelinkwrap"><a class="morelink" href="{$morelink}">{str tag=More section=blocktype.inbox} &raquo;</a></div>
<div class="cb"></div>
{/if}
<script type="application/javascript">
......
......@@ -52,9 +52,9 @@
</div>
{/foreach}
</div>
{if $desiredtypes}
{if $morelink}
<div class="artefact-detail-link">
<a class="link-blocktype last" href="{$WWWROOT}account/activity/index.php?type={$desiredtypes}">
<a class="link-blocktype last" href="{$morelink}">
<span class="icon icon-arrow-circle-right"></span>
{str tag=More section=blocktype.inbox}</a>
</div>
......
@javascript @core @core_messages
Feature: Clicking on Inbox
In order to click on the mailbox
In order to click on the Inbox block's 'More' link
As a student user
So I can send messages to other students
So I can see more of my messages
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| userA | Kupuhipa1 | test01@example.com | Pete | Mc | mahara | internal | member |
| userA | Kupuhipa1 | test01@example.com | Andrea | Andrews | mahara | internal | member |
| userB | Kupuhipa1 | test02@example.com | Barry | Bishop | mahara | internal | member |
| userC | Kupuhipa1 | test03@example.com | Catriona | Carson | mahara | internal | member |
| userD | Kupuhipa1 | test04@example.com | Doug | Davies | mahara | internal | member |
| userE | Kupuhipa1 | test05@example.com | Elise | Edwards | mahara | internal | member |
| userF | Kupuhipa1 | test06@example.com | Fred | Flintstone | mahara | internal | member |
| userG | Kupuhipa1 | test07@example.com | Gillian | Granger | mahara | internal | member |
And the following "messages" exist:
| emailtype | to | from | subject | messagebody | read | url | urltext |
| friendrequest | userA | userB | New friend request | Friend request from Barry | 1 | user/view.php?id=[from] | Requests |
| friendrequest | userA | userC | New friend request | Friend request from Catriona | 1 | user/view.php?id=[from] | Requests |
| friendrequest | userA | userD | New friend request | Friend request from Doug | 1 | user/view.php?id=[from] | Requests |
| friendrequest | userA | userE | New friend request | Friend request from Elise | 1 | user/view.php?id=[from] | Requests |
| friendrequest | userA | userF | New friend request | Friend request from Fred | 1 | user/view.php?id=[from] | Requests |
| friendrequest | userA | userG | New friend request | Friend request from Gillian | 1 | user/view.php?id=[from] | Requests |
| friendaccept | userG | userA | Friend request accepted | Friend request accepted from Andrea | 1 | user/view.php?id=[to] | |
Scenario: Clicking on the Inbox link on the right menu (Bug 1427019)
# Log in as users
Given I log in as "userA" with password "Kupuhipa1"
# Navigating to the Inbox to check the new ID tag works
And I click on "mail"
# Navigating to the Inbox via the 'more' link in the Inbox block
And I follow "More"
# Verifying that you do not see a page full of error messages
And I should not see "Call stack"
And I should see "Notifications"
And I should see "Compose"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment