Skip to content

Commit

Permalink
Merge pull request #254 from creative-commoners/pulls/3.0/fix-tests
Browse files Browse the repository at this point in the history
Replace some unit tests with behat tests and make required_extensions explicit in tests
  • Loading branch information
NightJar authored Jul 12, 2018
2 parents 2a60407 + 5c72f0a commit 87eb5f8
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,package.json,*.scss,*.js}]
[*.{yml,scss,js,feature}]
indent_size = 2

# The indent size used in the package.json file cannot be changed:
Expand Down
23 changes: 22 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
language: php

before_install:
- sudo apt-get update
- sudo apt-get install chromium-chromedriver

env:
global:
- COMPOSER_ROOT_VERSION=3.0.x-dev
- DISPLAY=":99"
- XVFBARGS=":99 -ac -screen 0 1024x768x16"
- SS_BASE_URL="http://localhost:8080/"
- SS_ENVIRONMENT_TYPE="dev"

matrix:
include:
Expand All @@ -14,24 +22,37 @@ matrix:
env: DB=MYSQL RECIPE_VERSION=1.2.x-dev PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL RECIPE_VERSION=4.2.x-dev PHPUNIT_COVERAGE_TEST=1
- php: 7.2
env: DB=MYSQL RECIPE_VERSION=4.2.x-dev BEHAT_TEST=1
- php: 7.2
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1

before_script:
# Extra $PATH
- export PATH=/usr/lib/chromium-browser/:$PATH

# Init PHP
- phpenv rehash
- phpenv config-rm xdebug.ini

# Install composer dependencies
- composer validate
- composer require silverstripe/recipe-cms $RECIPE_VERSION --no-update
- composer require silverstripe/recipe-cms:$RECIPE_VERSION silverstripe/recipe-testing:^1 --no-update
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --no-update; fi
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile

# Behat bootstrapping
- if [[ $BEHAT_TEST ]]; then mkdir artifacts; fi
- if [[ $BEHAT_TEST ]]; then cp composer.lock artifacts/; fi
- if [[ $BEHAT_TEST ]]; then sh -e /etc/init.d/xvfb start; sleep 3; fi
- if [[ $BEHAT_TEST ]]; then (chromedriver > artifacts/chromedriver.log 2>&1 &); fi
- if [[ $BEHAT_TEST ]]; then (vendor/bin/serve --bootstrap-file vendor/silverstripe/cms/tests/behat/serve-bootstrap.php &> artifacts/serve.log &); fi

script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ ; fi
- if [[ $BEHAT_TEST ]]; then vendor/bin/behat @silverstripe-elemental; fi

after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
32 changes: 32 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Run silverstripe-elemental behat tests with this command
# Note that silverstripe-elemental behat tests require CMS module
# ========================================================================= #
# chromedriver
# vendor/bin/behat @silverstripe-elemental
# ========================================================================= #
default:
suites:
silverstripe-elemental:
paths:
- %paths.modules.silverstripe-elemental%/tests/Behat/features
contexts:
- SilverStripe\Framework\Tests\Behaviour\FeatureContext
- SilverStripe\Framework\Tests\Behaviour\CmsFormsContext
- SilverStripe\Framework\Tests\Behaviour\CmsUiContext
- SilverStripe\BehatExtension\Context\BasicContext
- SilverStripe\BehatExtension\Context\LoginContext
-
SilverStripe\BehatExtension\Context\FixtureContext:
- %paths.modules.silverstripe-elemental%/tests/Behat/files/
extensions:
SilverStripe\BehatExtension\MinkExtension:
default_session: facebook_web_driver
javascript_session: facebook_web_driver
facebook_web_driver:
browser: chrome
wd_host: "http://127.0.0.1:9515" #chromedriver port
browser_name: chrome
SilverStripe\BehatExtension\Extension:
bootstrap_file: vendor/silverstripe/cms/tests/behat/serve-bootstrap.php
screenshot_path: %paths.base%/artifacts/screenshots
retry_seconds: 4 # default is 2
8 changes: 3 additions & 5 deletions tests/BaseElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace DNADesign\Elemental\Tests;

use function class_exists;
use DNADesign\Elemental\Controllers\ElementController;
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Models\BaseElement;
Expand All @@ -13,7 +12,6 @@
use Page;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\VersionedAdmin\Forms\HistoryViewerField;

class BaseElementTest extends FunctionalTest
Expand All @@ -23,12 +21,12 @@ class BaseElementTest extends FunctionalTest
protected static $required_extensions = [
Page::class => [
ElementalPageExtension::class,
]
],
];

protected static $extra_dataobjects = [
TestPage::class,
TestElement::class
TestElement::class,
];

public function testSimpleClassName()
Expand Down Expand Up @@ -124,7 +122,7 @@ public function testGetHistoryViewerField()

/** @var ElementContent $element */
$element = $this->objFromFixture(ElementContent::class, 'content1');

$history = $element->getCMSFields()->dataFieldByName('ElementHistory');
$this->assertInstanceOf(HistoryViewerField::class, $history);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Behat/features/block-types-report.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: View types of elements in a report
As a CMS user
I want to view a report of element types in the CMS
So that I can see which elements I have available and how many are used

@javascript
Scenario: I can view the types of elements used
Given I am logged in with "ADMIN" permissions
And I go to "/admin/reports"
Then I should see text matching "Content block types"

When I go to "/admin/reports/show/DNADesign-Elemental-Reports-ElementTypeReport"
Then I should see text matching "Content block types"
# See: Content element, bundled by default with elemental
And I should see text matching "HTML text block"
# Ensure BaseElement is ignored
And I should not see text matching "Base element class"
7 changes: 6 additions & 1 deletion tests/Controllers/ElementSiteTreeFilterSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Tests\Src\TestPage;
use Page;
use SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search;
use SilverStripe\Dev\SapphireTest;

class ElementSiteTreeFilterSearchTest extends SapphireTest
{
protected static $fixture_file = 'ElementSiteTreeFilterSearchTest.yml';

protected static $required_extensions = [
TestPage::class => [
ElementalPageExtension::class,
],
];

protected static $extra_dataobjects = [
TestPage::class,
];
Expand Down
18 changes: 9 additions & 9 deletions tests/ElementControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

namespace DNADesign\Elemental\Tests;

use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\TextField;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Tests\Src\TestElement;
use DNADesign\Elemental\Tests\Src\TestPage;
use DNADesign\Elemental\Tests\Src\TestElementController;
use DNADesign\Elemental\Tests\Src\TestPage;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Versioned\Versioned;

class ElementControllerTest extends FunctionalTest
Expand All @@ -21,6 +15,12 @@ class ElementControllerTest extends FunctionalTest

protected static $use_draft_site = true;

protected static $required_extensions = [
TestPage::class => [
ElementalPageExtension::class,
],
];

protected static $extra_dataobjects = [
TestPage::class,
TestElement::class
Expand Down
3 changes: 1 addition & 2 deletions tests/ElementalEditorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace DNADesign\Elemental\Tests;

use DNADesign\Elemental\ElementalEditor;
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Models\ElementContent;
use DNADesign\Elemental\ElementalEditor;
use Page;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\GridField\GridField;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
Expand Down
55 changes: 0 additions & 55 deletions tests/Reports/ElementTypeReportTest.php

This file was deleted.

7 changes: 7 additions & 0 deletions tests/Reports/ElementsInUseReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DNADesign\Elemental\Tests\Reports;

use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Reports\ElementsInUseReport;
use DNADesign\Elemental\Tests\Src\TestElement;
use DNADesign\Elemental\Tests\Src\TestPage;
Expand All @@ -13,6 +14,12 @@ class ElementsInUseReportTest extends FunctionalTest
{
protected static $fixture_file = 'ElementsInUseReportTest.yml';

protected static $required_extensions = [
TestPage::class => [
ElementalPageExtension::class,
],
];

protected static $extra_dataobjects = [
TestElement::class,
TestPage::class,
Expand Down
5 changes: 0 additions & 5 deletions tests/Src/TestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

namespace DNADesign\Elemental\Tests\Src;

use DNADesign\Elemental\Extensions\ElementalPageExtension;
use Page;
use SilverStripe\Dev\TestOnly;

class TestPage extends Page implements TestOnly
{
private static $table_name = 'TestElementalPage';

private static $extensions = [
ElementalPageExtension::class
];
}

0 comments on commit 87eb5f8

Please sign in to comment.