Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Behat local environment added. #44

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
726f00f
Add initial Behat environment and new scenario
brown-a2 Nov 27, 2018
c7a7798
Finished homepage landing test
brown-a2 Nov 27, 2018
f2e97b9
Populate Wordpress with dummy content
brown-a2 Nov 27, 2018
3e62d0e
Add further Behat senarios
brown-a2 Nov 30, 2018
7ef6805
Merge branch 'master' into behat
brown-a2 Dec 2, 2018
a5857a2
Modified config
brown-a2 Dec 2, 2018
419cf39
Comment out tests yet to be written
brown-a2 Dec 2, 2018
0381bb8
Git depth config change in .travis
brown-a2 Dec 2, 2018
b8132f5
Remove step
brown-a2 Dec 3, 2018
8b241ab
Testing
brown-a2 Dec 3, 2018
c4ccf8b
Curl fix
brown-a2 Dec 3, 2018
ef467a7
Remove error curl
brown-a2 Dec 3, 2018
9ef833a
Mod curl
brown-a2 Dec 3, 2018
da72dad
Reordered install cmd
brown-a2 Dec 3, 2018
9364b44
Add in further tests
brown-a2 Dec 3, 2018
618de3d
New mod to dory
brown-a2 Dec 3, 2018
599efb8
Top mod
brown-a2 Dec 3, 2018
28036f4
Get Dory working :{
brown-a2 Dec 3, 2018
333cede
iDory
brown-a2 Dec 3, 2018
5b6cddf
Add chrome addon
brown-a2 Dec 4, 2018
773a9da
Fix
brown-a2 Dec 4, 2018
6465eb6
Fix
brown-a2 Dec 4, 2018
d80d844
Dory changes
brown-a2 Dec 4, 2018
2bf38be
Add Dory file
brown-a2 Dec 4, 2018
318e6e9
Fine removed version
brown-a2 Dec 4, 2018
fe298c3
Building sh for Dory conf
brown-a2 Dec 4, 2018
9721ff2
Change make cmd
brown-a2 Dec 4, 2018
56c9ffe
Add home
brown-a2 Dec 4, 2018
fc7b629
Force mkdir
brown-a2 Dec 4, 2018
1176c15
Remove invalid charactor
brown-a2 Dec 4, 2018
fb73f2b
Add sudo
brown-a2 Dec 4, 2018
a6009d0
Update local BeHat testing
brown-a2 Dec 5, 2018
b5d7a0e
Merge branch 'master' into behat
brown-a2 Dec 5, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ php:
services:
- docker

git:
depth: false

addons:
hosts:
- hmctskm.docker

before_install:
- composer install
- cd web/app/themes/hmcts-km
Expand All @@ -19,7 +26,11 @@ before_install:

install:
- docker-compose -f docker-compose-travis.yml up -d
- docker-compose exec wordpress features/seed-database.sh
- gem install dory
- make travis
- dory up
- dory status
- docker-compose -f docker-compose-travis.yml exec wordpress features/seed-database.sh -d

script:
- vendor/bin/behat
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ bash:
test:
composer test

behat:
vendor/bin/behat

down:
dory down
docker-compose down
Expand Down
1 change: 1 addition & 0 deletions docker-compose-travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
VIRTUAL_HOST: ${SERVER_NAME}
volumes:
- database:/var/lib/mysql

Expand Down
26 changes: 0 additions & 26 deletions features/dashboard-access.feature

This file was deleted.

19 changes: 19 additions & 0 deletions features/homepage.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Check the major homepage elements exist
In order to have a consistent homepage interface
As a HMCTS staff member (not logged in)
I can see the homepage and everything is there I expect

Scenario: I can see homepage knowlege articles/posts
Given I go to the homepage
When I should see "Hello world!"
And I should see "Knowledge article post"

#Scenario: I can use the search
#Given I go to the homepage
#When I enter a search term
#Then the search results load

#Scenario: I can see tags
#Given I go to the homepage
#When I click on a tag
#Then the tag search results load
13 changes: 10 additions & 3 deletions features/seed-database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
alias wp="wp --allow-root"

wp db reset --yes

wp core install --url=hmctskm.docker --title="HMCTS KM" --admin_user=admin --admin_password=password [email protected] --skip-email
wp user create subscriber [email protected] --role=subscriber --user_pass=password
wp option update timezone_string "Europe/London"
wp rewrite structure "/%year%/%monthnum%/%postname%/"
wp rewrite structure "/%postname%/"
wp plugin activate --all
PAGE_ID=$(wp post create --post_type=page --post_title="Change My Password" --post_name="change-password" --post_status=publish --porcelain)
wp post meta update $PAGE_ID "_wp_page_template" "change-password.php"

PAGE_ID=$(wp post create --post_type=page --post_title="Knowledge article page" --post_name="knowledge-article-page" --post_status=publish --post_content="Page dummy content" --porcelain)
PAGE2_ID=$(wp post create --post_type=page --post_title="Knowledge article page two" --post_name="knowledge-article-page-two" --post_status=publish --porcelain)
wp post create --post_type=post --post_title="Knowledge article post" --post_name="knowledge-article-post" --post_status=publish --post_content="Post dummy content."
wp menu create "Lefthand main menu"
wp menu location assign "Lefthand main menu" primary_navigation
wp menu item add-post "Lefthand main menu" $PAGE_ID
wp menu item add-post "Lefthand main menu" $PAGE2_ID
35 changes: 34 additions & 1 deletion features/src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,37 @@ public function iShouldNotSeeTheAdminToolbar()
$this->getSession()->getDriver()
);
}
}

/**
* @When I enter a search term
*/
public function iEnterASearchTerm()
{
throw new PendingException();
}

/**
* @Then the search results load
*/
public function theSearchResultsLoad()
{
throw new PendingException();
}

/**
* @When I click on a tag
*/
public function iClickOnATag()
{
throw new PendingException();
}

/**
* @Then the tag search results load
*/
public function theTagSearchResultsLoad()
{
throw new PendingException();
}

}
12 changes: 6 additions & 6 deletions web/app/themes/hmcts-km/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@

];

foreach ( $sage_includes as $file ) {
if ( ! $filepath = locate_template( $file ) ) {
trigger_error( sprintf( __( 'Error locating %s for inclusion', 'sage' ), $file ), E_USER_ERROR );
}
foreach ($sage_includes as $file) {
if (! $filepath = locate_template($file)) {
trigger_error(sprintf(__('Error locating %s for inclusion', 'sage'), $file), E_USER_ERROR);
}

require_once $filepath;
require_once $filepath;
}
unset( $file, $filepath );
unset($file, $filepath);
2 changes: 0 additions & 2 deletions web/app/themes/hmcts-km/lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,3 @@ function setup()
add_editor_style(Assets\asset_path('styles/editor-style.css'));
}
add_action('after_setup_theme', __NAMESPACE__ . '\\setup');


132 changes: 67 additions & 65 deletions web/app/themes/hmcts-km/lib/public-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,94 @@
* Register a meta box using a class.
*/

class Custom_Public_Meta_Box {
class Custom_Public_Meta_Box
{

/**
* Constructor.
*/
public function __construct() {
if ( is_admin() ) {
add_action( 'load-post.php', array( $this, 'init' ) );
add_action( 'load-post-new.php', array( $this, 'init' ) );
public function __construct()
{
if (is_admin()) {
add_action('load-post.php', array( $this, 'init' ));
add_action('load-post-new.php', array( $this, 'init' ));
}
}
}

/**
* Meta box initialization.
*/
public function init(){
add_action( 'add_meta_boxes', array($this, 'add') );
add_action( 'save_post', array($this, 'save') );
}
public function init()
{
add_action('add_meta_boxes', array($this, 'add'));
add_action('save_post', array($this, 'save'));
}

// this function add's the meta box
public function add(){
add_meta_box(
'public-box',
__( 'Public Text', 'textdomain' ),
array( $this, 'display' ),
['post','page'],
'advanced',
'default'
);

}
public function add()
{
add_meta_box(
'public-box',
__('Public Text', 'textdomain'),
array( $this, 'display' ),
['post','page'],
'advanced',
'default'
);
}

// this renders the metabox to display on screen
public function display($post){


$values = get_post_custom( $post->ID );
// Add nonce for security and authentication.
wp_nonce_field( 'custom_nonce_action', 'custom_nonce' );
public function display($post)
{

$public_value = get_post_meta( $post->ID, '_public_editor', false );

if (!empty( $public_value ) || !empty( $welsh_value )){
$public_text = $public_value[0];
}else{
$public_text = '';
}

wp_editor( $public_text, '_public_editor' );
$values = get_post_custom($post->ID);
// Add nonce for security and authentication.
wp_nonce_field('custom_nonce_action', 'custom_nonce');

}
$public_value = get_post_meta($post->ID, '_public_editor', false);

// this saves the data inputted by the user
public function save($post_id){
// Add nonce for security and authentication.
$nonce_name = isset( $_POST['custom_nonce'] ) ? $_POST['custom_nonce'] : '';
$nonce_action = 'custom_nonce_action';

// Check if nonce is valid.
if ( ! wp_verify_nonce( $nonce_name, $nonce_action ) ) {
return;
}
if (!empty($public_value) || !empty($welsh_value)) {
$public_text = $public_value[0];
} else {
$public_text = '';
}

// Check if user has permissions to save data.
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
wp_editor($public_text, '_public_editor');
}

// Check if not an autosave.
if ( wp_is_post_autosave( $post_id ) ) {
return;
}

// Check if not a revision.
if ( wp_is_post_revision( $post_id ) ) {
return;
}

// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_public_editor'] ) ) {
update_post_meta( $post_id, '_public_editor', $_POST['_public_editor'] );
// this saves the data inputted by the user
public function save($post_id)
{
// Add nonce for security and authentication.
$nonce_name = isset($_POST['custom_nonce']) ? $_POST['custom_nonce'] : '';
$nonce_action = 'custom_nonce_action';

// Check if nonce is valid.
if (! wp_verify_nonce($nonce_name, $nonce_action)) {
return;
}

// Check if user has permissions to save data.
if (! current_user_can('edit_post', $post_id)) {
return;
}

// Check if not an autosave.
if (wp_is_post_autosave($post_id)) {
return;
}

// Check if not a revision.
if (wp_is_post_revision($post_id)) {
return;
}

// OK, we're authenticated: we need to find and save the data
if (isset($_POST['_public_editor'])) {
update_post_meta($post_id, '_public_editor', $_POST['_public_editor']);
}
}

}

}

new Custom_Public_Meta_Box();
12 changes: 6 additions & 6 deletions web/app/themes/hmcts-km/lib/security.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
<?php

# Restrict access to particular paths. Block /?author= access allowing the attacker to get usernames.

add_action( 'template_redirect', 'author_page_redirect' );
add_action('template_redirect', 'author_page_redirect');

function author_page_redirect() {
if ( is_author() ) {
wp_redirect( home_url() );
function author_page_redirect()
{
if (is_author()) {
wp_redirect(home_url());
}
}

27 changes: 14 additions & 13 deletions web/app/themes/hmcts-km/lib/users/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
* Call the function when your plugin/theme is activated.
*/

function author_set_capabilities() {
// Get the role object.
$author = get_role( 'author' );
// A list of capabilities to remove from editors.
$caps = array(
'publish_posts',
'publish_pages',
);
function author_set_capabilities()
{
// Get the role object.
$author = get_role('author');
// A list of capabilities to remove from editors.
$caps = array(
'publish_posts',
'publish_pages',
);

foreach ( $caps as $cap ) {
// Remove the capability.
$author->remove_cap( $cap );
}
foreach ($caps as $cap) {
// Remove the capability.
$author->remove_cap($cap);
}
}
add_action( 'init', 'author_set_capabilities' );
add_action('init', 'author_set_capabilities');
Loading