Commit 223b372d authored by Rebecca Blundell's avatar Rebecca Blundell
Browse files

Bug 1674850 - journal block tests

Just fixed merge conflict - other issues still to fix

New feature adding test for all 4 journal types to see they display correctly

Also includes new 'journals' background step to create journals
and new 'journalposts' background step to create journal entries

I called the one for journal entries 'journalposts' to keep it
consistent with noun plural being an 's'

Also updated an existing feature for taggged posts to use the new
'journalposts' step so that we have an examples of it's use with and
without using the 'journals' step

Change-Id: I0200e5a263359610c6ad49d38a9f2cc866f9af61
parent aa12e3be
......@@ -839,4 +839,117 @@ EOD;
$activity = new ActivityTypeMaharamessage($data, false);
$activity->notify_users();
}
/**
* A fixture to set up journals in bulk.
* Currently it only supports adding title / description / tags for a blog
*
* Example:
* Given the following "journals" exist:
* | owner | ownertype | title | description | tags |
* | userA | user | Blog One | This is my new blog | cats,dogs |
* | Group B | group | Group Blog | This is my group blog | |
* @param unknown $record
* @throws SystemException
*/
public function create_journal($record) {
$record['owner'] = trim($record['owner']);
$record['ownertype'] = trim($record['ownertype']);
$owner = null;
$ownertype = null;
if ($record['ownertype'] == 'group') {
$owner = get_field('group', 'id', 'name', $record['owner']);
$ownertype = 'group';
}
else if ($record['ownertype'] == 'institution') {
$owner = get_field('institution', 'name', 'displayname', $record['owner']);
$ownertype = 'institution';
}
else {
$owner = get_field('usr', 'id', 'username', $record['owner']);
$ownertype = 'owner';
}
if (!$owner) {
throw new SystemException("Invalid owner '" . $record['to'] . "'. The owner needs to be a username or group/institution display name");
}
$record['title'] = trim($record['title']);
if (!empty($record['title'])) {
// Check the blog does not already exist with that name
$blogid = get_field('artefact', 'id', 'artefacttype', 'blog', 'title', $record['title'], $ownertype, $owner);
if ($blogid) {
throw new SystemException("Invalid journal with '" . $record['title'] . "'. The blog already exists for this " . $record['owner'] . " " . $record['ownertype']);
}
}
else {
throw new systemException("The " . $record['title'] . " cannot be empty");
}
safe_require('artefact', 'blog');
$tags = array_map('trim', explode(',', $record['tags']));
$blogobj = new ArtefactTypeBlog(null, (object) array(
'title' => trim($record['title']),
'description' => trim($record['description']),
'tags' => (!empty($tags) ? $tags : null),
$ownertype => $owner,
));
$blogobj->commit();
}
/**
* A fixture to set up journal entries in bulk.
* Currently it only supports adding title / description / tags for a blog entry
*
* Example:
* Given the following "journalposts" exist:
* | owner | ownertype | title | entry | blog | tags | draft |
* | userA | user | Entry One | This is my entry | Blog 1 | cats,dogs | 0 |
* | Group B | group | GE 1 | This is my group entry | G Blog 2 | | 0 |
* | userB | user | Entry One | This is my entry | | | 1 | <-- No blog specified should default to default blog
* @param unknown $record
* @throws SystemException
*/
public function create_journalpost($record) {
$record['owner'] = trim($record['owner']);
$record['ownertype'] = trim($record['ownertype']);
$owner = null;
$ownertype = null;
if ($record['ownertype'] == 'group') {
$owner = get_field('group', 'id', 'name', $record['owner']);
$ownertype = 'group';
}
else if ($record['ownertype'] == 'institution') {
$owner = get_field('institution', 'name', 'displayname', $record['owner']);
$ownertype = 'institution';
}
else {
$owner = get_field('usr', 'id', 'username', $record['owner']);
$ownertype = 'owner';
}
if (!$owner) {
throw new SystemException("Invalid owner '" . $record['to'] . "'. The owner needs to be a username or group/institution display name");
}
$record['blog'] = trim($record['blog']);
if (!empty($record['blog'])) {
// Check the blog exists with that name
$blogid = get_field('artefact', 'id', 'artefacttype', 'blog', 'title', $record['blog'], $ownertype, $owner);
if (!$blogid) {
throw new SystemException("Invalid journal '" . $record['blog'] . "'. The " . $record['ownertype'] . " " . $record['owner'] . " does not have a blog called " . $record['blog']);
}
}
else {
$blogid = get_field_sql("SELECT id FROM {artefact} WHERE artefacttype = ? AND " . $ownertype . " = ? ORDER BY id LIMIT 1", array('blog', $owner));
if (!$blogid) {
throw new systemException("The " . $record['ownertype'] . " " . $record['owner'] . " does not have a blog to add blog entry to. Please create blog first");
}
}
safe_require('artefact', 'blog');
$postobj = new ArtefactTypeBlogPost(null, null);
$postobj->set('title', trim($record['title']));
$postobj->set('description', trim($record['entry']));
$tags = array_map('trim', explode(',', $record['tags']));
$postobj->set('tags', (!empty($tags) ? $tags : null));
$postobj->set('published', !$record['draft']);
$postobj->set($ownertype, $owner);
$postobj->set('parent', $blogid);
$postobj->commit();
}
}
......@@ -155,6 +155,30 @@ class BehatDataGenerators extends BehatBase {
),
'required' => array('emailtype', 'to', 'subject'),
),
'journals' => array(
'datagenerator' => 'journal',
'available' => array(
'owner' => 'text',
'ownertype' => 'text',
'title' => 'text',
'description' => 'text',
'tags' => 'text',
),
'required' => array('owner', 'ownertype', 'title'),
),
'journalposts' => array(
'datagenerator' => 'journalpost',
'available' => array(
'owner' => 'text',
'ownertype' => 'text',
'title' => 'text',
'entry' => 'text',
'blog' => 'text',
'tags' => 'text',
'draft' => 'bool',
),
'required' => array('owner', 'ownertype', 'title', 'entry'),
),
);
/**
......
......@@ -13,27 +13,14 @@ Feature: Mahara users can allow their tagged blogs tags to be copied
| title | description | ownertype | ownername |
| Page UserA_01 | Page 01 | user | UserA |
And the following "journalposts" exist:
| owner | ownertype | title | entry | blog | tags | draft |
| UserA | user | Entry one | This is journal entry one | | blog,one | 0 |
| UserA | user | Entry two | This is journal entry two | | blog,two | 0 |
| UserB | user | UserB entry | This is a journal entry for UserB | | blog,one | 0 |
Scenario: Create blogs
Given I log in as "UserA" with password "Kupuhipa1"
# Create tagged blog entries
When I choose "Journals" in "Content" from main menu
And I follow "New entry"
And I set the following fields to these values:
| Title | Entry one |
| Entry | This is journal entry one |
And I scroll to the base of id "editpost_tags_container"
And I fill in select2 input "editpost_tags" with "blog" and select "blog"
And I fill in select2 input "editpost_tags" with "one" and select "one"
And I press "Save entry"
And I follow "New entry"
And I set the following fields to these values:
| Title | Entry two |
| Entry | This is journal entry two |
And I scroll to the base of id "editpost_tags_container"
And I fill in select2 input "editpost_tags" with "blog" and select "blog"
And I fill in select2 input "editpost_tags" with "two" and select "two"
And I press "Save entry"
# Add a taggedblogs block to a page
And I choose "Pages and collections" in "Portfolio" from main menu
And I click on "Page UserA_01" panel menu
......@@ -64,16 +51,6 @@ Feature: Mahara users can allow their tagged blogs tags to be copied
# Copy the page as another user
And I log out
Given I log in as "UserB" with password "Kupuhipa1"
And I choose "Journals" in "Content" from main menu
And I follow "New entry"
And I set the following fields to these values:
| Title | UserB entry |
| Entry | This is a journal entry for UserB |
And I scroll to the base of id "editpost_tags_container"
And I fill in select2 input "editpost_tags" with "blog" and select "blog"
And I fill in select2 input "editpost_tags" with "one" and select "one"
And I press "Save entry"
And I go to the homepage
And I scroll to the id "view"
And I follow "Page UserA_01"
And I scroll to the base of id "copyview-button"
......
@javascript @core @blocktype @blocktype_journals
Feature: Add journal blocktypes to a page
In order to make sure they appear on the page
when added by a user
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| celeste | Kupuhipa1 | celeste@example.com | Celeste | Phobos | mahara | internal | member |
And the following "pages" exist:
| title | description| ownertype | ownername |
| Celeste's Page | All about me | user | celeste |
And the following "journals" exist:
| owner | ownertype | title | description | tags |
| celeste | user | Mars journal | Recording my Mars Mission | Mars |
And the following "journalposts" exist:
| owner | ownertype | title | entry | blog | tags | draft |
| celeste | user | I'm going to Mars! | I just passed my exam and am approved for a Mars Mission | Mars journal | Mars | 0 |
| celeste | user | Spacefood | Spacefood is kind of gross if you don't cook it right | Mars journal | Mars,food | 0 |
Given I log in as "celeste" with password "Kupuhipa1"
And I choose "Pages and collections" in "Portfolio" from main menu
And I click on "Celeste's Page" panel menu
And I click on "Edit" in "Celeste's Page" panel menu
And I expand "Journals" node in the "div#content-editor-foldable" "css_element"
Scenario: Add Journal block to the page
Given I follow "Journal" in the "div#blog" "css_element"
And I press "Add"
And I set the field "Mars journal" to "1"
And I press "Save"
And I display the page
Then I should see "Spacefood is kind of gross"
Scenario: Add specific Journal entry to the page
Given I follow "Journal entry" in the "div#blog" "css_element"
And I press "Add"
And I wait "1" seconds
And I set the field "I'm going to Mars!" to "1"
And I press "Save"
And I display the page
Then I should see "I just passed my exam"
And I should not see "Spacefood is kind of gross"
Scenario: Add a recent journal entries block to the page
Given I follow "Recent journal entries" in the "div#blog" "css_element"
And I press "Add"
And I set the field "Mars journal" to "1"
And I press "Save"
And I display the page
Then I should see "Spacefood"
Scenario: Add a tagged journal entry block to the page
Given I follow "Tagged journal entries" in the "div#blog" "css_element"
And I press "Add"
#And I set the field "Display entries tagged with" to "Mars"
And I fill in select2 input "instconf_tagselect" with "food" and select "food"
And I press "Save"
And I display the page
Then I should see "Journal entries with tag \"food\""
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