Skip to content
Snippets Groups Projects
Commit afd89234 authored by JohnCullen's avatar JohnCullen
Browse files

#3384913 setup testing automation

parent decdc07a
Branches
No related tags found
No related merge requests found
Showing with 167 additions and 1858 deletions
<?php
namespace Drupal\Tests\support_ticket\Functional;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
/**
* Minimal test case for the examples module.
*
* @group examples
*
* @ingroup examples
*/
class ExamplesTest extends ExamplesBrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Modules to install.
*
* @var array
*/
protected static $modules = ['examples', 'toolbar'];
/**
* Verify that the toolbar tab and tray are showing and functioning.
*/
public function testExampleToolbar() {
$assert = $this->assertSession();
// Log in a user who can see the toolbar and all the routes in it.
$this->drupalLogin($this->drupalCreateUser(['access content', 'access toolbar']));
// All this should be on the front page.
$this->drupalGet('');
$assert->statusCodeEquals(200);
// Assert that the toolbar tab registered by examples is present.
$assert->linkExists('Examples');
// Assert that the toolbar tab registered by examples is present.
$this->assertNotEmpty($this->xpath('//nav/div/a[@data-toolbar-tray="toolbar-item-examples-tray"]'));
// Assert that the toolbar tray registered by examples is present.
$this->assertNotEmpty($this->xpath('//nav/div/div[@data-toolbar-tray="toolbar-item-examples-tray"]'));
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = $this->container->get('module_installer');
// Loop through all the routes. Check that they are not present in the
// toolbar, enable the module, and then check that they are present in the
// toolbar.
foreach (_examples_toolbar_routes() as $module => $route) {
// Convert the module name to the HTML class.
$class = Html::getClass($module);
$xpath = "//li/a[@class=\"$class\"]";
// Assert that the toolbar link item isn't present.
$this->assertEmpty($this->xpath($xpath), 'Found li with this class: ' . $class);
// Install the module.
$module_installer->install([$module], TRUE);
$this->resetAll();
// Load the route.
$this->drupalGet(Url::fromRoute($route));
// Assert that the toolbar link is present.
$this->assertNotEmpty($this->xpath($xpath), 'Unable to find toolbar link for module: ' . $module);
// Handle some special cases where modules depend on each other so they
// might have already put the toolbar link in the toolbar.
if ($module == 'file_example') {
$module_installer->uninstall(['file_example', 'stream_wrapper_example']);
}
}
}
}
#!/bin/bash
set -e $DRUPAL_TI_DEBUG
# Increase the MySQL server timeout and packet size.
mysql -e "SET GLOBAL wait_timeout = 36000;"
mysql -e "SET GLOBAL max_allowed_packet = 33554432;"
# Ensure the right Drupal version is installed.
# Note: This function is re-entrant.
drupal_ti_ensure_drupal
# Add custom modules to drupal build.
cd "$DRUPAL_TI_DRUPAL_DIR"
# Ensure the module is linked into the codebase.
drupal_ti_ensure_module
# Enable main module and submodules.
drush en -y support support_ticket
# @file
# .travis.yml - Drupal for Travis CI Integration
#
# Template provided by https://github.com/LionsAd/drupal_ti.
#
# Based for simpletest upon:
# https://github.com/sonnym/travis-ci-drupal-module-example
language: php
sudo: false
php:
- 5.5
- 5.6
- 7
- hhvm
branches:
only:
- "8.x-1.x"
matrix:
fast_finish: true
allow_failures:
- php: 7
- php: hhvm
env:
global:
# add composer's global bin directory to the path
# see: https://github.com/drush-ops/drush#install---composer
- PATH="$PATH:$HOME/.composer/vendor/bin"
# Configuration variables.
- DRUPAL_TI_MODULE_NAME="support"
- DRUPAL_TI_SIMPLETEST_GROUP="support"
# Define runners and environment vars to include before and after the
# main runners / environment vars.
#- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"
#- DRUPAL_TI_SCRIPT_DIR_AFTER="./drupal_ti/after"
# The environment to use, supported are: drupal-7, drupal-8
- DRUPAL_TI_ENVIRONMENT="drupal-8"
# Drupal specific variables.
- DRUPAL_TI_DB="drupal_travis_db"
- DRUPAL_TI_DB_URL="mysql://root:@127.0.0.1/drupal_travis_db"
# Note: Do not add a trailing slash here.
- DRUPAL_TI_WEBSERVER_URL="http://127.0.0.1"
- DRUPAL_TI_WEBSERVER_PORT="8080"
# Simpletest specific commandline arguments, the DRUPAL_TI_SIMPLETEST_GROUP is appended at the end.
- DRUPAL_TI_SIMPLETEST_ARGS="--verbose --color --concurrency 4 --url $DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT"
# === Behat specific variables.
# This is relative to $TRAVIS_BUILD_DIR
- DRUPAL_TI_BEHAT_DIR="./tests/behat"
# These arguments are passed to the bin/behat command.
- DRUPAL_TI_BEHAT_ARGS=""
# Specify the filename of the behat.yml with the $DRUPAL_TI_DRUPAL_DIR variables.
- DRUPAL_TI_BEHAT_YML="behat.yml.dist"
# This is used to setup Xvfb.
- DRUPAL_TI_BEHAT_SCREENSIZE_COLOR="1280x1024x16"
# The version of selenium that should be used.
- DRUPAL_TI_BEHAT_SELENIUM_VERSION="2.44"
# Set DRUPAL_TI_BEHAT_DRIVER to "selenium" to use "firefox" or "chrome" here.
- DRUPAL_TI_BEHAT_DRIVER="phantomjs"
- DRUPAL_TI_BEHAT_BROWSER="firefox"
# PHPUnit specific commandline arguments.
- DRUPAL_TI_PHPUNIT_ARGS="--group support"
# Specifying the phpunit-core src/ directory is useful when e.g. a vendor/
# directory is present in the module directory, which phpunit would then
# try to find tests in. This option is relative to $TRAVIS_BUILD_DIR.
- DRUPAL_TI_PHPUNIT_CORE_SRC_DIRECTORY="./tests/src"
# Code coverage via coveralls.io
- DRUPAL_TI_COVERAGE="satooshi/php-coveralls:0.6.*"
# This needs to match your .coveralls.yml file.
- DRUPAL_TI_COVERAGE_FILE="build/logs/clover.xml"
# Debug options
#- DRUPAL_TI_DEBUG="-x -v"
# Set to "all" to output all files, set to e.g. "xvfb selenium" or "selenium",
# etc. to only output those channels.
#- DRUPAL_TI_DEBUG_FILE_OUTPUT="selenium xvfb webserver"
matrix:
# [[[ SELECT ANY OR MORE OPTIONS ]]]
#- DRUPAL_TI_RUNNERS="phpunit"
#- DRUPAL_TI_RUNNERS="simpletest"
#- DRUPAL_TI_RUNNERS="behat"
- DRUPAL_TI_RUNNERS="phpunit-core simpletest behat"
# Use phpunit-core to test modules with phpunit with Drupal 8 core.
#- DRUPAL_TI_RUNNERS="phpunit-core"
mysql:
database: drupal_travis_db
username: root
encoding: utf8
before_install:
- composer self-update
- composer global require "lionsad/drupal_ti:1.*"
- drupal-ti before_install
install:
- drupal-ti install
before_script:
- drupal-ti --include ".travis-before-script.sh"
- drupal-ti before_script
script:
- drupal-ti script
after_script:
- drupal-ti after_script
notifications:
email: false
#!/bin/bash
##
# This scripts increases the speed and granualar testing
# of the moduled.
#
# INSTALLATION.
# 1. The vendor directory will need to be above the docroot.
# 2. Phpunit needs to be installed
# (https://packagist.org/packages/drupal/core-dev),
# 3. Manaully copy phpunit.xml.dist to phpunit.xml in
# the Drupal directory.
#
# For tests to work run from this script using the `bash tests`
# command in the terminal.
##
echo Tests script!
##
# Access Drupal core directory.
##
CURRENT_DIR=${PWD};
cd $CURRENT_DIR"/../../../../core/"
echo "Moved to Drupal core: "${PWD}
echo "";
##
# Run support module tests.
##
../../vendor/bin/phpunit ../modules/custom/support/tests/src/Functional/SupportInstallationTests.php
##
# Returns to script directory
##
cd $CURRENT_DIR;
echo "";
echo "Returned to script directory: "${PWD};
default:
suites:
default:
contexts:
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\DrushContext
- Drupal\DrupalExtension\Context\MinkContext
extensions:
Behat\MinkExtension:
base_url: http://127.0.0.1/
goutte: ~
selenium2: ~
browser_name: firefox
Drupal\DrupalExtension:
blackbox: ~
api_driver: "drush"
drush_driver: "drush"
drush:
root: "/var/www/html"
default:
suites:
default:
contexts:
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\DrushContext
- Drupal\DrupalExtension\Context\MinkContext
extensions:
Behat\MinkExtension:
base_url: "$DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT/"
goutte: ~
selenium2: ~
browser_name: firefox
Drupal\DrupalExtension:
blackbox: ~
api_driver: "drush"
drush_driver: "drush"
drush:
root: "$DRUPAL_TI_DRUPAL_DIR"
{
"require": {
"drupal/drupal-extension": "~3.0"
}
}
This diff is collapsed.
@drushTest @drush
Feature: Drush-specific steps
In order to prove that the drush driver is working properly
As a developer
I need to be able to use the steps provided here
Scenario: drush command with text matching: drush output correct status
Given I run drush "st"
Then drush output should contain "Drupal version"
Then drush output should contain "Site URI"
Then drush output should contain "Database driver"
Then drush output should contain "Successful"
Then drush output should not contain "NonExistantWord"
Scenario: drush command with arguments: re-enable toolbar
Given I run drush "en" "toolbar -y"
And I run drush "en" "toolbar -y"
Then drush output should contain "toolbar is already enabled."
Feature: Test DrupalContext
In order to prove the Drupal context using the blackbox driver is working properly
As a developer
I need to use the step definitions of this context
Scenario: Test the ability to find a heading in a region
Given I am on the homepage
When I click "Site-Install"
Then I should see "Site-Install"
Scenario: Error messages
Given I am on "/user"
When I press "Log in"
Then I should see "Password field is required"
Feature: Test DrupalContext
In order to prove the Drupal context using the selenium driver is working properly
As a developer
I need to use the step definitions of this context
@javascript
Scenario: Test the ability to find a heading in a region
Given I am on the homepage
When I click "Site-Install"
Then I should see "Site-Install"
@javascript
Scenario: Error messages
Given I am on "/user"
When I press "Log in"
Then I should see "Password field is required"
#!/bin/bash
# @file
# Simple script to load composer and run behat tests.
set -e
DIR=$(dirname $0)
cd $DIR
cd ./behat
test -f "./vendor/bin/behat" || composer install --no-interaction --prefer-source
# Checking for Phantom JS or selenium (Linux only)
if ! { netstat -l -n | grep -q :4444; }
then
echo "Error: PhantomJS or selenium could not be found." 1>&2
echo "" 1>&2
echo "Start phantomjs with:" 1>&2
echo " phantomjs --webdriver=4444 &" 1>&2
exit 1
fi
./vendor/bin/behat "$@"
#!/bin/bash
# @file
# Simple script to run the unit tests.
set -e
export MODULE_DIR=$(cd $(dirname $0); cd ..; pwd)
(cd ../../../core; ../../vendor/bin/phpunit $MODULE_DIR/tests/src )
#!/bin/bash
# @file
# Simple script to run the tests.
set -e
# Goto current directory.
DIR=$(dirname $0)
cd $DIR
drush -y en simpletest support
export CORE_DIR=$(drush drupal-directory)
cd $CORE_DIR
{ php ./core/scripts/run-tests.sh --color --verbose --url 'http://127.0.0.1/' "support" || echo "1 fails"; } | tee /tmp/simpletest-result.txt
egrep -i "([1-9]+ fail)|(Fatal error)|([1-9]+ exception)" /tmp/simpletest-result.txt && exit 1
exit 0
#!/bin/bash
# @file
# Simple script to run all tests.
set -e
./tests/run-phpunit.sh
./tests/run-simpletest.sh
./tests/run-behat.sh
......@@ -2,7 +2,7 @@
namespace Drupal\support\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the basic support integration functionality.
......@@ -11,7 +11,14 @@ use Drupal\simpletest\WebTestBase;
*
* @codeCoverageIgnore
*/
class SupportBasicTest extends WebTestBase {
class SupportInstallationTests extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
}
/**
* Modules to enable.
......@@ -20,18 +27,17 @@ class SupportBasicTest extends WebTestBase {
*
* @var array
*/
public static $modules = ['support', 'node'];
protected static $modules = ['support'];
/**
* The basic functionality of the support module.
* {@inheritdoc}
*/
public function testBasicSupportFunctionality() {
// Test that the front page exists.
$this->drupalGet('<front>');
$this->assertResponse(200, 'Front page exists.');
$this->assertRaw('Drupal');
protected $defaultTheme = 'stark';
// Test that login works.
/**
* Testing to see if login works
*/
public function testDrupalLoginFunctionality() {
$admin_user = $this->drupalCreateUser(['access content']);
$this->drupalLogin($admin_user);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment