-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from openeuropa/EWPP-1577
EWPP-1577: Update to D9 and convert behat tests to phpunit
- Loading branch information
Showing
13 changed files
with
194 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |