From 7ec39bbb570fb02f7ccf42e15df98e913f856908 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 23 Jan 2015 19:42:47 +0100 Subject: [PATCH 01/10] Allow to create languages in tests. --- .../DrupalExtension/Context/DrupalContext.php | 20 +++++++++++ .../Context/RawDrupalContext.php | 36 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/Drupal/DrupalExtension/Context/DrupalContext.php b/src/Drupal/DrupalExtension/Context/DrupalContext.php index 8cc6d9d6..8415673f 100644 --- a/src/Drupal/DrupalExtension/Context/DrupalContext.php +++ b/src/Drupal/DrupalExtension/Context/DrupalContext.php @@ -374,6 +374,26 @@ public function createTerms($vocabulary, TableNode $termsTable) { } } + /** + * Creates one or more languages. + * + * @Given the/these (following )languages are available: + * + * Provide language data in the following format: + * + * | langcode | + * | en | + * | fr | + * + * @param TableNode $langcodesTable + * The table listing languages by their ISO code. + */ + public function createLanguages(TableNode $langcodesTable) { + foreach ($langcodesTable->getHash() as $langcode) { + $this->languageCreate((object) $langcode); + } + } + /** * Pauses the scenario until the user presses a key. Useful when debugging a scenario. * diff --git a/src/Drupal/DrupalExtension/Context/RawDrupalContext.php b/src/Drupal/DrupalExtension/Context/RawDrupalContext.php index 24208599..c78dcb04 100644 --- a/src/Drupal/DrupalExtension/Context/RawDrupalContext.php +++ b/src/Drupal/DrupalExtension/Context/RawDrupalContext.php @@ -7,10 +7,12 @@ use Drupal\DrupalDriverManager; +use Drupal\DrupalExtension\Hook\Scope\AfterLanguageEnableScope; use Drupal\DrupalExtension\Hook\Scope\AfterNodeCreateScope; use Drupal\DrupalExtension\Hook\Scope\AfterTermCreateScope; use Drupal\DrupalExtension\Hook\Scope\AfterUserCreateScope; use Drupal\DrupalExtension\Hook\Scope\BaseEntityScope; +use Drupal\DrupalExtension\Hook\Scope\BeforeLanguageEnableScope; use Drupal\DrupalExtension\Hook\Scope\BeforeNodeCreateScope; use Drupal\DrupalExtension\Hook\Scope\BeforeUserCreateScope; use Drupal\DrupalExtension\Hook\Scope\BeforeTermCreateScope; @@ -79,6 +81,13 @@ class RawDrupalContext extends RawMinkContext implements DrupalAwareInterface { */ protected $roles = array(); + /** + * Keep track of any languages that are created so they can easily be removed. + * + * @var array + */ + protected $languages = array(); + /** * {@inheritDoc} */ @@ -205,6 +214,19 @@ public function cleanRoles() { $this->roles = array(); } + /** + * Remove any created languages. + * + * @AfterScenario + */ + public function cleanLanguages() { + // Delete any languages that were created. + foreach ($this->languages as $language) { + $this->getDriver()->languageDelete($language); + unset($this->languages[$language->langcode]); + } + } + /** * Dispatch scope hooks. * @@ -294,6 +316,20 @@ public function termCreate($term) { return $saved; } + /** + * Creates a language. + * + * @param \stdClass $language + * An object with the following properties: + * - langcode: the langcode of the language to create. + */ + public function languageCreate(\stdClass $language) { + $this->dispatchHooks('BeforeLanguageCreateScope', $language); + $this->getDriver()->languageCreate($language); + $this->dispatchHooks('AfterLanguageCreateScope', $language); + $this->languages[$language->langcode] = $language; + } + /** * Log-in the current user. */ From 9e33087d85a996e1faf567b0920f3d2bc1ed721f Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Mon, 26 Jan 2015 16:19:33 +0100 Subject: [PATCH 02/10] Add language hook scopes. --- .../Hook/Scope/AfterLanguageCreateScope.php | 23 +++++++++++++++++++ .../Hook/Scope/BeforeLanguageCreateScope.php | 23 +++++++++++++++++++ .../Hook/Scope/LanguageScope.php | 17 ++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/Drupal/DrupalExtension/Hook/Scope/AfterLanguageCreateScope.php create mode 100644 src/Drupal/DrupalExtension/Hook/Scope/BeforeLanguageCreateScope.php create mode 100644 src/Drupal/DrupalExtension/Hook/Scope/LanguageScope.php diff --git a/src/Drupal/DrupalExtension/Hook/Scope/AfterLanguageCreateScope.php b/src/Drupal/DrupalExtension/Hook/Scope/AfterLanguageCreateScope.php new file mode 100644 index 00000000..ab2ba6fe --- /dev/null +++ b/src/Drupal/DrupalExtension/Hook/Scope/AfterLanguageCreateScope.php @@ -0,0 +1,23 @@ + Date: Mon, 26 Jan 2015 17:11:52 +0100 Subject: [PATCH 03/10] Convert TableNode hash into a Drupal language mock object --- src/Drupal/DrupalExtension/Context/DrupalContext.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Drupal/DrupalExtension/Context/DrupalContext.php b/src/Drupal/DrupalExtension/Context/DrupalContext.php index 8415673f..95553443 100644 --- a/src/Drupal/DrupalExtension/Context/DrupalContext.php +++ b/src/Drupal/DrupalExtension/Context/DrupalContext.php @@ -389,8 +389,11 @@ public function createTerms($vocabulary, TableNode $termsTable) { * The table listing languages by their ISO code. */ public function createLanguages(TableNode $langcodesTable) { - foreach ($langcodesTable->getHash() as $langcode) { - $this->languageCreate((object) $langcode); + foreach ($langcodesTable->getHash() as $row) { + $language = (object) array( + 'langcode' => $row['languages'], + ); + $this->languageCreate($language); } } From dcaf4066d606c86b1e4c3f65030fb6e0d526183c Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Mon, 2 Feb 2015 18:26:16 +0100 Subject: [PATCH 04/10] Return the language that was created. --- .../DrupalExtension/Context/RawDrupalContext.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Drupal/DrupalExtension/Context/RawDrupalContext.php b/src/Drupal/DrupalExtension/Context/RawDrupalContext.php index c78dcb04..ea1536c4 100644 --- a/src/Drupal/DrupalExtension/Context/RawDrupalContext.php +++ b/src/Drupal/DrupalExtension/Context/RawDrupalContext.php @@ -322,12 +322,18 @@ public function termCreate($term) { * @param \stdClass $language * An object with the following properties: * - langcode: the langcode of the language to create. + * + * @return object|FALSE + * The created language, or FALSE if the language was already created. */ public function languageCreate(\stdClass $language) { $this->dispatchHooks('BeforeLanguageCreateScope', $language); - $this->getDriver()->languageCreate($language); - $this->dispatchHooks('AfterLanguageCreateScope', $language); - $this->languages[$language->langcode] = $language; + $language = $this->getDriver()->languageCreate($language); + if ($language) { + $this->dispatchHooks('AfterLanguageCreateScope', $language); + $this->languages[$language->langcode] = $language; + } + return $language; } /** From 55f03a4f3aca56d2afec40131f6d802327bcfbfa Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 18 Jun 2015 18:17:46 +0200 Subject: [PATCH 05/10] Temporarily use the sister branch for DrupalDriver. --- composer.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 17e61ff6..fd3890fe 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "behat/mink-selenium2-driver": "~1.1", "behat/behat": "~3.0,>=3.0.5", "behat/mink-extension": "~2.0", - "drupal/drupal-driver": "~1.0@dev" + "drupal/drupal-driver": "dev-language" }, "require-dev": { "phpspec/phpspec": "~2.0", @@ -31,6 +31,12 @@ "Drupal\\DrupalExtension": "src/" } }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/pfrenssen/DrupalDriver" + } + ], "extra": { "branch-alias": { "dev-master": "3.0.x-dev" From b7d48a8139fde2097e586f22ed6df6bce394a4f5 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 26 Jun 2015 15:22:41 +0200 Subject: [PATCH 06/10] Test enabling of languages on Drupal 7. --- features/language.feature | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 features/language.feature diff --git a/features/language.feature b/features/language.feature new file mode 100644 index 00000000..9498521f --- /dev/null +++ b/features/language.feature @@ -0,0 +1,21 @@ +@api @d7 +Feature: Language support + In order to demonstrate the language integration + As a developer for the Behat Extension + I need to provide test cases for the language support + + # These test scenarios assume to have a clean installation of the "standard" + # profile and that the "behat_test" module from the "fixtures/" folder is + # enabled on the site. + + Scenario: Enable multiple languages + Given the following languages are available: + | languages | + | en | + | fr | + | de | + And I am logged in as a user with the 'administrator' role + When I go to "admin/config/regional/language" + Then I should see "English" + And I should see "French" + And I should see "German" From 2185681fd87f946cf5f9675e49a3c3f02da4bedb Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 26 Jun 2015 15:23:07 +0200 Subject: [PATCH 07/10] Enable the Locale module in the Drupal 7 test feature so we can test languages. --- fixtures/drupal7/modules/behat_test/behat_test.info | 1 + 1 file changed, 1 insertion(+) diff --git a/fixtures/drupal7/modules/behat_test/behat_test.info b/fixtures/drupal7/modules/behat_test/behat_test.info index 25425a50..9d70d5b4 100644 --- a/fixtures/drupal7/modules/behat_test/behat_test.info +++ b/fixtures/drupal7/modules/behat_test/behat_test.info @@ -7,6 +7,7 @@ dependencies[] = entityreference dependencies[] = features dependencies[] = link dependencies[] = list +dependencies[] = locale dependencies[] = node dependencies[] = options dependencies[] = taxonomy From 168066253290c6c2eecd50b6852f58c1147635f5 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 26 Jun 2015 16:37:43 +0200 Subject: [PATCH 08/10] Test language support on Drupal 8. --- features/language.feature | 2 +- fixtures/drupal8/modules/behat_test/behat_test.info.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/features/language.feature b/features/language.feature index 9498521f..8bfb73af 100644 --- a/features/language.feature +++ b/features/language.feature @@ -1,4 +1,4 @@ -@api @d7 +@api @d7 @d8 Feature: Language support In order to demonstrate the language integration As a developer for the Behat Extension diff --git a/fixtures/drupal8/modules/behat_test/behat_test.info.yml b/fixtures/drupal8/modules/behat_test/behat_test.info.yml index 9f114c98..989a97b1 100644 --- a/fixtures/drupal8/modules/behat_test/behat_test.info.yml +++ b/fixtures/drupal8/modules/behat_test/behat_test.info.yml @@ -5,3 +5,5 @@ package: Test version: '8.x-1.x-dev' core: '8.x' project: 'behat_test' +dependencies: + - language From c8e7ed578bdd828b0b98194f66c9d3f557f49bba Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 26 Jun 2015 19:37:02 +0200 Subject: [PATCH 09/10] Fix typo. --- .../DrupalExtension/Hook/Scope/BeforeLanguageCreateScope.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drupal/DrupalExtension/Hook/Scope/BeforeLanguageCreateScope.php b/src/Drupal/DrupalExtension/Hook/Scope/BeforeLanguageCreateScope.php index a1e10b09..2e88627b 100644 --- a/src/Drupal/DrupalExtension/Hook/Scope/BeforeLanguageCreateScope.php +++ b/src/Drupal/DrupalExtension/Hook/Scope/BeforeLanguageCreateScope.php @@ -12,7 +12,7 @@ final class BeforeLanguageCreateScope extends LanguageScope { /** - * Return the scope name. + * Returns the scope name. * * @return string */ From b4c98348520867d1170e2a4293b37708996a36f5 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 9 Jul 2015 19:20:34 +0200 Subject: [PATCH 10/10] Revert "Temporarily use the sister branch for DrupalDriver." This reverts commit 55f03a4f3aca56d2afec40131f6d802327bcfbfa. --- composer.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/composer.json b/composer.json index fd3890fe..17e61ff6 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "behat/mink-selenium2-driver": "~1.1", "behat/behat": "~3.0,>=3.0.5", "behat/mink-extension": "~2.0", - "drupal/drupal-driver": "dev-language" + "drupal/drupal-driver": "~1.0@dev" }, "require-dev": { "phpspec/phpspec": "~2.0", @@ -31,12 +31,6 @@ "Drupal\\DrupalExtension": "src/" } }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/pfrenssen/DrupalDriver" - } - ], "extra": { "branch-alias": { "dev-master": "3.0.x-dev"