From 5c72f0a0ddcf3ccabb1df388e82ad1fa48ac77cf Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 12 Jul 2018 12:04:13 +1200 Subject: [PATCH] Move element type report unit tests to behat test --- .editorconfig | 2 +- .travis.yml | 23 ++++++- behat.yml | 32 +++++++++ .../Behat/features/block-types-report.feature | 17 +++++ tests/Reports/ElementTypeReportTest.php | 67 ------------------- 5 files changed, 72 insertions(+), 69 deletions(-) create mode 100644 behat.yml create mode 100644 tests/Behat/features/block-types-report.feature delete mode 100644 tests/Reports/ElementTypeReportTest.php diff --git a/.editorconfig b/.editorconfig index f2b28c1b..6056f314 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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: diff --git a/.travis.yml b/.travis.yml index 3e1121d9..9808b19f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: @@ -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 diff --git a/behat.yml b/behat.yml new file mode 100644 index 00000000..cd87a340 --- /dev/null +++ b/behat.yml @@ -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 diff --git a/tests/Behat/features/block-types-report.feature b/tests/Behat/features/block-types-report.feature new file mode 100644 index 00000000..e4adac19 --- /dev/null +++ b/tests/Behat/features/block-types-report.feature @@ -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" diff --git a/tests/Reports/ElementTypeReportTest.php b/tests/Reports/ElementTypeReportTest.php deleted file mode 100644 index de83be47..00000000 --- a/tests/Reports/ElementTypeReportTest.php +++ /dev/null @@ -1,67 +0,0 @@ - [ - ElementalPageExtension::class, - ], - ]; - - protected static $extra_dataobjects = [ - TestElement::class, - TestPage::class, - TestUnusedElement::class, - ]; - - public function testReportShowsBlockTypes() - { - $this->markTestSkipped('@todo replace this with a behat test'); - - $this->logInWithPermission('ADMIN'); - - $result = (string) $this->get('admin/reports/show/DNADesign-Elemental-Reports-ElementTypeReport')->getBody(); - - $this->assertContains('Content Type', $result, 'Table has headings'); - - $this->assertContains('Unused Element', $result, 'Unused elements are still shown in the report'); - - $this->assertContains( - 'data-class="DNADesign-Elemental-Models-ElementContent"', - $result, - 'Report contains content element (bundled with elemental)' - ); - } - - public function testSourceRecords() - { - $this->markTestSkipped('@todo replace this with a behat test'); - - $records = (new ElementTypeReport)->sourceRecords(); - - $this->assertInstanceOf(ArrayList::class, $records); - $this->assertNotContains(BaseElement::class, $records->toArray(), 'BaseElement is excluded'); - - $this->assertContainsOnlyInstancesOf(ArrayData::class, $records); - - foreach ($records as $record) { - $this->assertNotNull($record->Icon); - $this->assertNotNull($record->Type); - $this->assertInternalType('int', $record->Total); - } - } -}