Skip to content

Commit

Permalink
Merge pull request #51 from openeuropa/EWPP-1577
Browse files Browse the repository at this point in the history
EWPP-1577: Update to D9 and convert behat tests to phpunit
  • Loading branch information
upchuk authored Sep 30, 2021
2 parents 16b482f + 3d3768e commit 93bc233
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 79 deletions.
7 changes: 0 additions & 7 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,9 @@ pipeline:
commands:
- ./vendor/bin/phpunit

behat:
group: test
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
commands:
- ./vendor/bin/behat --strict

matrix:
COMPOSER_BOUNDARY:
- lowest
- highest
PHP_VERSION:
- 7.2
- 7.3
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ It will also perform token substitution in development configuration files such
./vendor/bin/run drupal:site-install
```

The development site web root should be available in the `build` directory.
Your test site will be available at [http://localhost:8080/build](http://localhost:8080/build).

**Please note:** project files and directories are symlinked within the test site by using the
[OpenEuropa Task Runner's Drupal project symlink](https://github.com/openeuropa/task-runner-drupal-project-symlink) command.

If you add a new file or directory in the root of the project, you need to re-run `drupal:site-setup` in order to make
sure they are be correctly symlinked.

If you don't want to re-run a full site setup for that, you can simply run:

```
$ ./vendor/bin/run drupal:symlink-project
```

### Using Docker Compose

Expand Down
25 changes: 0 additions & 25 deletions behat.yml.dist

This file was deleted.

27 changes: 12 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"drupal/core": "^8.7",
"php": ">=7.2"
"php": ">=7.3",
"drupal/core": "^8.9 || ^9.1"
},
"require-dev": {
"composer/installers": "~1.5",
"drupal/core-composer-scaffold": "^8.8",
"drupal/config_devel": "~1.2",
"drupal/drupal-extension": "~4.0",
"drush/drush": "~9.0",
"guzzlehttp/guzzle": "~6.3",
"openeuropa/behat-transformation-context" : "~0.1",
"openeuropa/code-review": "~1.0@beta",
"openeuropa/drupal-core-require-dev": "^8.7",
"openeuropa/task-runner": "~1.0@beta",
"openeuropa/oe_multilingual": "^1.1",
"phpunit/phpunit": "~6.0"
"composer/installers": "^1.5",
"drupal/core-composer-scaffold": "^8.9 || ^9.1",
"drupal/config_devel": "^1.2",
"drush/drush": "^10.3",
"openeuropa/code-review": "^1.7",
"openeuropa/drupal-core-require-dev": "^8.9 || ^9.1",
"openeuropa/oe_multilingual": "^1.5",
"openeuropa/task-runner-drupal-project-symlink": "^1.0",
"phpspec/prophecy-phpunit": "^1 || ^2"
},
"scripts": {
"post-install-cmd": "./vendor/bin/run drupal:site-setup",
Expand All @@ -40,7 +37,7 @@
},
"autoload-dev": {
"psr-4": {
"Drupal\\Tests\\oe_search\\": "./tests/"
"Drupal\\Tests\\oe_search\\": "./tests/src/"
}
},
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion modules/oe_search_demo/oe_search_demo.info.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: OpenEuropa Search Demo
core: 8.x
core_version_requirement: ^8.9 || ^9.1
type: module
2 changes: 1 addition & 1 deletion oe_search.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Search features for the OpenEuropa project.
package: OpenEuropa

type: module
core: 8.x
core_version_requirement: ^8.9 || ^9.1

'interface translation project': oe_search
# The path to the actual translations is defined in
Expand Down
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="${drupal.root}/core/tests/bootstrap.php" backupGlobals="true" colors="true" >
<phpunit bootstrap="${drupal.root}/core/tests/bootstrap.php" backupGlobals="true" colors="true" cacheResult="false">
<php>
<ini name="error_reporting" value="32767"/>
<ini name="memory_limit" value="-1"/>
Expand All @@ -8,8 +8,8 @@
<env name="SIMPLETEST_DB" value="mysql://${drupal.database.user}:${drupal.database.password}@${drupal.database.host}:${drupal.database.port}/${drupal.database.name}"/>
</php>
<testsuites>
<testsuite>
<directory>./tests/</directory>
<testsuite name="OpenEuropa Search tests">
<directory>./tests/src/</directory>
</testsuite>
</testsuites>
</phpunit>
5 changes: 1 addition & 4 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ drupal:

commands:
drupal:site-setup:
- { task: "symlink", from: "../../..", to: "${drupal.root}/modules/custom/oe_search" }
- { task: "run", command: "drupal:symlink-project" }
- { task: "run", command: "drupal:drush-setup" }
- { task: "run", command: "drupal:settings-setup" }
- { task: "run", command: "setup:phpunit" }
- { task: "run", command: "setup:behat" }
setup:phpunit:
- { task: "process", source: "phpunit.xml.dist", destination: "phpunit.xml" }
setup:behat:
- { task: "process", source: "behat.yml.dist", destination: "behat.yml" }
2 changes: 1 addition & 1 deletion src/Plugin/Block/SearchFormBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SearchFormBlock extends BlockBase implements ContainerFactoryPluginInterfa
protected $formBuilder;

/**
* Constructs an Search block object.
* Constructs a Search block object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
Expand Down
21 changes: 0 additions & 21 deletions tests/features/search-block.feature

This file was deleted.

File renamed without changes.
89 changes: 89 additions & 0 deletions tests/src/Functional/SearchBlockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types = 1);

namespace Drupal\Tests\oe_search\Functional;

use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;

/**
* Tests the search block.
*/
class SearchBlockTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'language',
'oe_search',
];

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();

$this->drupalPlaceBlock('oe_search', [
'id' => 'oe-search',
]);

ConfigurableLanguage::createFromLangcode('fr')->save();
// Rebuild container to make sure that the language path processor is
// picked up.
// @see \Drupal\language\LanguageServiceProvider::register()
$this->rebuildContainer();
}

/**
* Tests the block itself.
*/
public function testBlock(): void {
$assert_session = $this->assertSession();

// A user without the "access content" permission doesn't have access to the
// block.
$this->drupalLogin($this->createUser());
$this->drupalGet('<front>');
$assert_session->elementNotExists('css', '#block-oe-search');

$this->drupalLogin($this->createUser(['access content']));
$this->drupalGet('<front>');
$block = $assert_session->elementExists('css', '#block-oe-search');

// Disable redirects to avoid loading web pages outside the test
// environment.
$this->getSession()->getDriver()->getClient()->followRedirects(FALSE);

// Launch a search.
$block->fillField('Search', 'European Commission');
$block->pressButton('Search');
// Verify that the user would be redirected to the ec.europa.eu search page
// with English as language.
$headers = $this->getSession()->getResponseHeaders();
$this->assertNotEmpty($headers['Location']);
$this->assertEquals('https://ec.europa.eu/search/?QueryText=European%20Commission&swlang=en', $headers['Location'][0]);

// Test that the correct language is passed to the search redirect url.
$this->getSession()->getDriver()->getClient()->followRedirects(TRUE);
$this->drupalGet('<front>', [
'language' => \Drupal::languageManager()->getLanguage('fr'),
]);
$block = $assert_session->elementExists('css', '#block-oe-search');
$block->fillField('Search', 'European Commission');
$this->getSession()->getDriver()->getClient()->followRedirects(FALSE);
$block->pressButton('Search');
$headers = $this->getSession()->getResponseHeaders();
$this->assertNotEmpty($headers['Location']);
$this->assertEquals('https://ec.europa.eu/search/?QueryText=European%20Commission&swlang=fr', $headers['Location'][0]);
}

}
73 changes: 73 additions & 0 deletions tests/src/Functional/SearchBlockTranslationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types = 1);

namespace Drupal\Tests\oe_search\Functional;

use Drupal\Tests\BrowserTestBase;

/**
* Tests the search block translations.
*/
class SearchBlockTranslationTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'language',
'oe_multilingual',
'oe_search',
];

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();

$this->drupalPlaceBlock('oe_search', [
'id' => 'oe-search',
]);

// Import the translations for 3 test languages.
\Drupal::service('oe_multilingual.local_translations_batcher')->createBatch([
'en',
'fr',
'it',
]);
// Force the batch to execute.
$batch =& batch_get();
$batch['progressive'] = FALSE;
batch_process();
}

/**
* Tests that translations are provided for the search block button.
*/
public function testTranslations(): void {
$assert_session = $this->assertSession();

$this->drupalLogin($this->createUser(['access content']));
$this->drupalGet('<front>');
$block = $assert_session->elementExists('css', '#block-oe-search');
$assert_session->buttonExists('Search', $block);
// Check that the block button is translated in French.
$this->drupalGet('<front>', [
'language' => \Drupal::languageManager()->getLanguage('fr'),
]);
$assert_session->buttonExists('Rechercher', $block);
// And in Italian.
$this->drupalGet('<front>', [
'language' => \Drupal::languageManager()->getLanguage('it'),
]);
$assert_session->buttonExists('Cerca', $block);
}

}

0 comments on commit 93bc233

Please sign in to comment.