Skip to content

Commit

Permalink
OPENEUROPA-660: Corrections in behat tests according to feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergepavle committed Oct 10, 2018
1 parent 983b98c commit ef5a068
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
50 changes: 22 additions & 28 deletions tests/Behat/DrupalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Element\NodeElement;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Drupal\field\Entity\FieldConfig;
Expand Down Expand Up @@ -203,32 +202,32 @@ protected function getLanguageIdByName(string $name): string {
}

/**
* Redirect user on Node creation page.
* Redirect user to the node creation page.
*
* @param string $content_type_name
* Content type name.
*
* @Given I am visiting the :content_type_name create node page
* @Given I am visiting the :content_type_name creation page
*/
public function iAmVisitingTheCreateNodePage(string $content_type_name): void {
public function iAmVisitingTheCreationPage(string $content_type_name): void {
$node_bundle = $this->getEntityTypeByLabel($content_type_name);
$this->visitPath('node/add/' . $node_bundle);
}

/**
* Check that selectbox with node language selector is hidden.
* Check that the field is not present.
*
* @param string $label
* Label of selectbox.
* @param string $field
* Input id, name or label.
*
* @Then I should not see selectbox with label :label
* @Then I should not see the field :field
*/
public function iShouldNotSeeSelectboxWithLabel(string $label): void {
public function iShouldNotSeeTheField(string $field): void {
$element = $this->getSession()
->getPage()
->findField($label);
->findField($field);
if ($element) {
throw new \RuntimeException("Selectbox for selecting initial language still visible.");
throw new \RuntimeException("Field '{$field}' is present.");
}
}

Expand All @@ -238,27 +237,22 @@ public function iShouldNotSeeSelectboxWithLabel(string $label): void {
* @param string $title
* Title of node.
*
* @Then I have to be sure that :title node translation only in site default language.
* @Then The only available translation for :title is in the site's default language
*/
public function assertOnlyDefaultLanguageTranslationExist(string $title) {
$title_element = $this->getSession()
->getPage()
->findAll('named', ['link', $title]);
public function assertOnlyDefaultLanguageTranslationExist(string $title): void {
$node = $this->getEntityByLabel('node', $title);
if (!$node) {
throw new \RuntimeException("Node '{$title}' is not exist.");
}

if (count($title_element) !== 1) {
$node_translation_languages = $node->getTranslationLanguages();
if (!is_array($node_translation_languages) || count($node_translation_languages) !== 1) {
throw new \RuntimeException("We have not correct number of translations.");
}
if ($title_element[0] instanceof NodeElement) {
$translation_language = $title_element[0]
->getParent()
->getParent()
->findAll('named', ['content', \Drupal::languageManager()->getDefaultLanguage()->getName()]);
if (!count($translation_language)) {
throw new \RuntimeException("Original translation of node not equal to default site language.");
}
}
else {
throw new \RuntimeException("Not found translation of node.");

$node_language = key($node_translation_languages);
if ($node_language != \Drupal::languageManager()->getDefaultLanguage()->getId()) {
throw new \RuntimeException("Original translation language of the '{$title}' node is not equal to site's default language.");
}
}

Expand Down
10 changes: 4 additions & 6 deletions tests/features/content-default-language.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ Feature: Content initial language.
than the site default language

Scenario: Content editor try to create node without possibility select initial node language
Given I am logged in as a user with the "create oe_demo_translatable_page content,translate oe_demo_translatable_page node" permission
And I am visiting the "Demo translatable page" create node page
Then I should not see selectbox with label "Language"
Given I am logged in as a user with the "create oe_demo_translatable_page content" permission
And I am visiting the "Demo translatable page" creation page
Then I should not see the field "Language"

When I fill in "Title" with "Title Default value"
And I fill in "Body" with "Body Default value"
And I press "Save"
Then I should see the success message "Demo translatable page Title Default value has been created."

When I click "Translate"
Then I have to be sure that "Title Default value" node translation only in site default language.
And The only available translation for "Title Default value" is in the site's default language

0 comments on commit ef5a068

Please sign in to comment.