Commit 03dd1c61 authored by Robert Lyon's avatar Robert Lyon Committed by Rebecca Blundell

Bug 1677408: A quick tool to help find places where behat steps are used

So as to help slim down repetitive stuff and / or replace obsolete
steps

behatnotneeded - this is only a helper script and not part of normal
functionality

To use, check out the patch and go to
http://mahara/testing/frameworks/behat/behat_steps_used.php

Change-Id: I67abb4f6c7a762587252fe0bae2d3ef9edad7164
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent bcf844ea
......@@ -1310,3 +1310,11 @@ $string['cli_lang_branch'] = 'Mahara series version to fetch langpacks for serie
$string['withselectedcontentexport'] = 'Re-queue items into the export queue';
$string['withselectedcontentdelete'] = 'Delete selected items from the export queue';
$string['allothers'] = 'All others';
// Behat variables script
$string['behatvariables'] = 'Behat steps';
$string['behatvariablesdesc'] = 'Quick tool to help find the available Behat steps.';
$string['nobehatfeaturefiles'] = 'No behat feature files found';
$string['behatmatchingrows'] = '%s in ';
$string['behatnocore'] = 'Unable to read core behat steps from behat.yml file';
$string['behatstepnotused'] = 'This behat step is not currently used';
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Behat steps</h3>
<p>You can have a quick overview of the available Behat steps and where they are used in the tests. All tests are located in the /test/behat/features directory in the codebase.</p>
<p>Variables that are found in feature lines are represented by "?" to group these lines more easily. The actual lines do show the correct variables.</p>
<?php
/**
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
//define('MENUITEM', 'configsite/behatsteps');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'behatsteps');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('behatvariables', 'admin'));
$dirpath = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/test/behat/features';
function read_dir_files(&$output, $dirpath) {
$dir = new DirectoryIterator($dirpath);
foreach ($dir as $file) {
if ($file == '.' || $file == '..') {
continue;
}
if (is_dir($dirpath . '/' . $file)) {
read_dir_files($output, $dirpath . '/' . $file);
}
$gitroot = dirname(get_config('docroot'));
$filename = str_replace($gitroot, '', str_replace('.', '_', $file->getPathname()));
$filename = preg_replace('#/test/behat/features#', '', $filename); // trim of initial path
$filename = preg_replace('/_feature$/', '', $filename); // trim off _feature
$content = file_get_contents($file->getPathname());
if (preg_match_all('/(Given|When|And|Then) I.*/', $content, $matches, PREG_OFFSET_CAPTURE) !== false) {
if (!empty($matches[0])) {
foreach ($matches[0] as $origmatch) {
$match = preg_replace('/\\\"/', "'", $origmatch[0]);
$match = preg_replace('/"[^"]+"/', '"?"', $match);
// make them all start with 'And' as that will be the most used
// so we don't have different rows in array for 'Given' vs 'And'
$match = preg_replace('/(Given|When|And|Then) /', 'And ', $match);
// Basic way to guess the line the match is on
$line_number = 1 + substr_count($content, "\n", 0, $origmatch[1]);
$output[$match][$filename][$line_number] = $origmatch[0];
}
}
}
}
return $output;
}
$data = false;
if (file_exists($dirpath)) {
read_dir_files($data, $dirpath);
ksort($data);
}
$coredata = array();
$hascore = false;
// Get the core features
if (get_config('behat_dataroot')) {
// Find the behat.yml file
require_once(get_config('docroot') . 'testing/frameworks/behat/classes/util.php');
$behatyml = BehatTestingUtil::get_behat_config_path();
if (is_readable($behatyml)) {
$hascore = true;
// Run the behat config command to get list of core features
$behatconfig = 'export BEHAT_PARAMS=\'{"gherkin" : {"cache" : null}}\' && php ' . dirname(get_config('docroot')) . '/external/vendor/behat/behat/bin/behat --config ' . $behatyml . ' -dl 2>&1';
$corefeatures = shell_exec($behatconfig);
$corefeatures = explode(PHP_EOL, trim($corefeatures));
if (!empty($corefeatures)) {
// Need to merge the core features with the used features
foreach ($corefeatures as $feature) {
if (preg_match('/\^(.*?)\$/', $feature, $match)) {
$submatch = preg_replace('/^\(\?\:\|I \)/', 'And I ', $match[1]);
$submatch = preg_replace('/\(\?\:.*?\)/', '', $submatch);
$submatch = preg_replace('/\(.*?\)\"/', '?"', $submatch);
$submatch = preg_replace('/\(\?P.*?\)/', '"?"', $submatch);
$submatch = preg_replace('/\(the \)\?/', '', $submatch);
$submatch = preg_replace('/\:/', ' "?"', $submatch);
$submatch = preg_replace('/^I/', 'And I', $submatch);
$coredata[$submatch] = true;
}
}
}
}
if (!empty($coredata)) {
foreach ($coredata as $k => $v) {
if (!array_key_exists($k, $data)) {
$data[$k] = 'notused';
}
}
ksort($data);
}
}
$smarty = smarty(array());
setpageicon($smarty, 'icon-cogs');
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('data', $data);
$smarty->assign('hascore', $hascore);
$smarty->display('testing/behatvariables.tpl');
{include file="header.tpl"}
<p>{str tag=behatvariablesdesc section=admin}</p>
{if !$hascore}
<div class="alert alert-warning">{str tag=behatnocore section=admin}</div>
{/if}
{if $data}
{assign var="prevkey" value=''}
{foreach from=$data key=k item=v name=data}
{if $prevkey !== $k}
<fieldset id="fs_{$dwoo.foreach.data.index}" class="pieform-fieldset collapsible {if $dwoo.foreach.data.last} last{/if}">
<legend>
<h4>
<a id="link_{$dwoo.foreach.data.index}" class="collapsed" href="#behatfield-{$dwoo.foreach.data.index}" data-toggle="collapse" aria-expanded="false" aria-controls="#behatfield-{$dwoo.foreach.data.index}">
{$k}
<span class="icon icon-chevron-down collapse-indicator right pull-right"></span>
</a>
</h4>
</legend>
<div id="behatfield-{$dwoo.foreach.data.index}" class="fieldset-body collapse list-group">
{/if}
{if $v == 'notused'}
{str tag="behatstepnotused" section="admin"}
{else}
{foreach from=$v key=sk item=sv name=subdata}
<div id="fs_{$dwoo.foreach.data.index}_{$dwoo.foreach.subdata.index}" class="pieform-fieldset collapsible {if $dwoo.foreach.v.last} last{/if}">
<div><a id="link_{$dwoo.foreach.data.index}_{$dwoo.foreach.subdata.index}" class="collapsed" href="#behatfield-{$dwoo.foreach.data.index}-{$dwoo.foreach.subdata.index}" data-toggle="collapse" aria-expanded="false" aria-controls="#behatfield-{$dwoo.foreach.data.index}-{$dwoo.foreach.subdata.index}">{str tag=behatmatchingrows section=admin arg1=count($sv)} {$sk}.feature</a></div>
<div id="behatfield-{$dwoo.foreach.data.index}-{$dwoo.foreach.subdata.index}" class="fieldset-body collapse list-group">
{foreach $sv key=row item=value}
<div>line {$row}: {$value} </div>
{/foreach}
</div>
</div>
{/foreach}
{/if}
{if $prevkey !== $k}
</div>
</fieldset>
{$prevkey = $k}
{/if}
{/foreach}
{else}
{str tag=nobehatfeaturefiles section=admin}
{/if}
{include file="footer.tpl"}
\ No newline at end of file
{include file="header.tpl"}
<p>{str tag=behatvariablesdesc section=admin}</p>
{if !$hascore}
<div class="alert alert-warning">{str tag=behatnocore section=admin}</div>
{/if}
{if $data}
{assign var="prevkey" value=''}
{foreach from=$data key=k item=v name=data}
{if $prevkey !== $k}
<fieldset id="fs_{$dwoo.foreach.data.index}" class="pieform-fieldset collapsible {if $dwoo.foreach.data.last} last{/if}">
<legend>
<h4>
<a id="link_{$dwoo.foreach.data.index}" class="collapsed" href="#behatfield-{$dwoo.foreach.data.index}" data-toggle="collapse" aria-expanded="false" aria-controls="#behatfield-{$dwoo.foreach.data.index}">
{$k}
<span class="icon icon-chevron-down collapse-indicator right pull-right"></span>
</a>
</h4>
</legend>
<div id="behatfield-{$dwoo.foreach.data.index}" class="fieldset-body collapse list-group">
{/if}
{if $v == 'notused'}
{str tag="behatstepnotused" section="admin"}
{else}
{foreach from=$v key=sk item=sv name=subdata}
<div id="fs_{$dwoo.foreach.data.index}_{$dwoo.foreach.subdata.index}" class="pieform-fieldset collapsible {if $dwoo.foreach.v.last} last{/if}">
<div><a id="link_{$dwoo.foreach.data.index}_{$dwoo.foreach.subdata.index}" class="collapsed" href="#behatfield-{$dwoo.foreach.data.index}-{$dwoo.foreach.subdata.index}" data-toggle="collapse" aria-expanded="false" aria-controls="#behatfield-{$dwoo.foreach.data.index}-{$dwoo.foreach.subdata.index}">{str tag=behatmatchingrows section=admin arg1=count($sv)} {$sk}.feature</a></div>
<div id="behatfield-{$dwoo.foreach.data.index}-{$dwoo.foreach.subdata.index}" class="fieldset-body collapse list-group">
{foreach $sv key=row item=value}
<div>line {$row}: {$value} </div>
{/foreach}
</div>
</div>
{/foreach}
{/if}
{if $prevkey !== $k}
</div>
</fieldset>
{$prevkey = $k}
{/if}
{/foreach}
{else}
{str tag=nobehatfeaturefiles section=admin}
{/if}
{include file="footer.tpl"}
\ No newline at end of file
......@@ -47,8 +47,6 @@ Scenario: Clicking randomly around Mahara (Bug: 1426983)
And I choose "Institution membership" in "Groups" from main menu
And I choose "Topics" in "Groups" from main menu
# Checking messages
# And I click on "Show user menu" # problem with chrome driver clicking on user icon instead
# And I follow "mail"
And I choose "mail" from user menu by id
And I follow "Inbox" in the "Arrow-bar nav" property
And I follow "Sent"
......
......@@ -80,9 +80,8 @@ Scenario: Clicking on the journal sub menu headings and adding first journal (Bu
And I press "Save entry"
Then I should see "Journal entry 1"
And I should see "Journal entry 2"
# And I click on "Delete"
# And I accept the currently displayed dialog (waiting on fix for bug 1415252 to be able to do this step)
# Then I should not see "Journal entry 1"
And I delete the "Journal entry 1" row
Then I should not see "Journal entry 1"
Scenario: Newly created user can get a copy of the journal (Bug 1472467)
Given I log in as "admin" with password "Kupuhipa1"
......
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