@@ -72,6 +72,7 @@ |
||
72 | 72 | |
73 | 73 | /** |
74 | 74 | * This function localizes the field based on Drupal standards. English language is used as a base. |
75 | + * @return string |
|
75 | 76 | */ |
76 | 77 | |
77 | 78 | public function localizeField($field) { |
@@ -4,13 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use Behat\Behat\Context\Context; |
6 | 6 | use Symfony\Component\Yaml\Yaml; |
7 | -use Drupal\DrupalExtension\Context\DrupalContext; |
|
8 | -use Behat\MinkExtension; |
|
9 | -use Behat\Behat\Context\TranslatableContext; |
|
10 | 7 | use Behat\Mink\Element\Element; |
11 | -use Behat\Gherkin\Node\TableNode; |
|
12 | -use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
|
13 | -use Behat\MinkExtension\Context\RawMinkContext; |
|
14 | 8 | |
15 | 9 | /** |
16 | 10 | * This is the file for Multilingual context for Drupal. The context is working based on specifications |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | $file_path = $base_path.$this->multilingual_parameters['translations']; |
48 | 48 | $yaml = file_get_contents($file_path); |
49 | 49 | $yaml_parse_array_check = Yaml::parse($yaml); |
50 | - if(is_array($yaml_parse_array_check)) { |
|
50 | + if (is_array($yaml_parse_array_check)) { |
|
51 | 51 | $this->translations = $yaml_parse_array_check; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | 55 | // Checks whether the translations file variable is set in the Behat profile and parses it to array. |
56 | 56 | public function initializeMultilanguage() { |
57 | - if(isset($this->multilingual_parameters['translations'])) { |
|
57 | + if (isset($this->multilingual_parameters['translations'])) { |
|
58 | 58 | $this->parseTranslationFile(); |
59 | 59 | } |
60 | 60 | $this->parseLanguageCodes(); |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | } |
81 | 81 | $base_url_length = strlen($base_url); |
82 | 82 | //Get the 2 symbols in current URL after the base_url when Clean URLs is enabled |
83 | - $clean_url_language_code = substr($current_url,$base_url_length,2); |
|
84 | - $not_clean_url_language_code = substr($current_url,$base_url_length+3,2); |
|
85 | - if(in_array($clean_url_language_code,$this->languages_iso_codes) && substr($current_url,$base_url_length+2,1) == "/") { |
|
83 | + $clean_url_language_code = substr($current_url, $base_url_length, 2); |
|
84 | + $not_clean_url_language_code = substr($current_url, $base_url_length + 3, 2); |
|
85 | + if (in_array($clean_url_language_code, $this->languages_iso_codes)&&substr($current_url, $base_url_length + 2, 1) == "/") { |
|
86 | 86 | return $clean_url_language_code; |
87 | 87 | } |
88 | - else if (in_array($not_clean_url_language_code,$this->languages_iso_codes) && substr($current_url,$base_url_length+5,1) == "/"){ |
|
88 | + else if (in_array($not_clean_url_language_code, $this->languages_iso_codes)&&substr($current_url, $base_url_length + 5, 1) == "/") { |
|
89 | 89 | return $not_clean_url_language_code; |
90 | 90 | } |
91 | 91 | else return $this->multilingual_parameters['default_language']; |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | |
101 | 101 | public function localizeTarget($target) { |
102 | 102 | $translations = $this->multilingual_parameters['translations']; |
103 | - if(isset($this->translations[$target][$this->multilingual_parameters['default_language']])){ |
|
103 | + if (isset($this->translations[$target][$this->multilingual_parameters['default_language']])) { |
|
104 | 104 | $target = $this->translations[$target][$this->languageDetection()]; |
105 | 105 | return $target; |
106 | 106 | } |
107 | 107 | elseif (isset($this->translations[$target])) { |
108 | 108 | return $target; |
109 | 109 | } |
110 | - else throw new \Exception ("The text '$target'' is not defined in '$translations' translation file."); |
|
110 | + else throw new \Exception("The text '$target'' is not defined in '$translations' translation file."); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | public function localizeField($field) { |
118 | 118 | $re = "/(?:[-])(".$this->multilingual_parameters['default_language'].")(?:[-])/"; |
119 | 119 | $language = "-".$this->languageDetection()."-"; |
120 | - $field = preg_replace($re, $language,$field); |
|
120 | + $field = preg_replace($re, $language, $field); |
|
121 | 121 | return $field; |
122 | 122 | } |
123 | 123 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @When /^I wait for localized text "([^"]*)" to appear with max time "([^"]+)"(?: seconds)?$/ |
208 | 208 | */ |
209 | - public function iWaitForLocalizedTextToAppearWithMaxTime($target, $maxExecutionTime){ |
|
209 | + public function iWaitForLocalizedTextToAppearWithMaxTime($target, $maxExecutionTime) { |
|
210 | 210 | $target = $this->localizeTarget($target); |
211 | 211 | $this->iWaitForTextToAppearWithMaxTime($target, $maxExecutionTime); |
212 | 212 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @Given I click localized :link in the :rowText row |
231 | 231 | * @Then I (should )see the localized :link in the :rowText row |
232 | 232 | */ |
233 | - public function assertLocalizedClickInTableRow($link, $rowText){ |
|
233 | + public function assertLocalizedClickInTableRow($link, $rowText) { |
|
234 | 234 | $link = $this->localizeTarget($link); |
235 | 235 | $page = $this->getSession()->getPage(); |
236 | 236 | if ($link_element = $this->getTableRow($page, $rowText)->findLink($link)) { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @When /^I click on the localized text "([^"]*)" in the "(?P<region>[^"]*)"(?:| region)$/ |
261 | 261 | */ |
262 | - public function iClickOnTheLocalizedTextInRegion($text, $region){ |
|
262 | + public function iClickOnTheLocalizedTextInRegion($text, $region) { |
|
263 | 263 | $text = $this->localizeTarget($text); |
264 | 264 | $this->iClickOnTheTextInRegion($text, $region); |
265 | 265 | } |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | $not_clean_url_language_code = substr($current_url,$base_url_length+3,2); |
85 | 85 | if(in_array($clean_url_language_code,$this->languages_iso_codes) && substr($current_url,$base_url_length+2,1) == "/") { |
86 | 86 | return $clean_url_language_code; |
87 | - } |
|
88 | - else if (in_array($not_clean_url_language_code,$this->languages_iso_codes) && substr($current_url,$base_url_length+5,1) == "/"){ |
|
87 | + } else if (in_array($not_clean_url_language_code,$this->languages_iso_codes) && substr($current_url,$base_url_length+5,1) == "/"){ |
|
89 | 88 | return $not_clean_url_language_code; |
89 | + } else { |
|
90 | + return $this->multilingual_parameters['default_language']; |
|
90 | 91 | } |
91 | - else return $this->multilingual_parameters['default_language']; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | if(isset($this->translations[$target][$this->multilingual_parameters['default_language']])){ |
104 | 104 | $target = $this->translations[$target][$this->languageDetection()]; |
105 | 105 | return $target; |
106 | - } |
|
107 | - elseif (isset($this->translations[$target])) { |
|
106 | + } elseif (isset($this->translations[$target])) { |
|
108 | 107 | return $target; |
108 | + } else { |
|
109 | + throw new \Exception ("The text '$target'' is not defined in '$translations' translation file."); |
|
109 | 110 | } |
110 | - else throw new \Exception ("The text '$target'' is not defined in '$translations' translation file."); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $session = $this->getSession(); |
51 | 51 | $element = $session->getPage()->find( |
52 | 52 | 'xpath', |
53 | - $session->getSelectorsHandler()->selectorToXpath('xpath', '//*[contains(text(),"' . $text . '")]')); |
|
53 | + $session->getSelectorsHandler()->selectorToXpath('xpath', '//*[contains(text(),"'.$text.'")]')); |
|
54 | 54 | |
55 | 55 | if (null === $element) { |
56 | 56 | throw new \InvalidArgumentException(sprintf('Cannot find text: "%s"', $text)); |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | |
62 | 62 | public function assertValueInInput($value, $input) { |
63 | 63 | |
64 | - if (substr($input,0,1) != "#") { |
|
65 | - $input = "#" . $input; |
|
64 | + if (substr($input, 0, 1) != "#") { |
|
65 | + $input = "#".$input; |
|
66 | 66 | } |
67 | 67 | $session = $this->getSession(); |
68 | 68 | $element = $session->getPage()->find('css', $input); |
69 | 69 | $text = ""; |
70 | 70 | |
71 | - if(isset($element)) { |
|
71 | + if (isset($element)) { |
|
72 | 72 | $text = $element->getValue(); |
73 | 73 | } |
74 | 74 | else { |
75 | 75 | throw new \Exception(sprintf("Element is null")); |
76 | 76 | } |
77 | 77 | |
78 | - if($text === $value) { |
|
78 | + if ($text === $value) { |
|
79 | 79 | return true; |
80 | 80 | } |
81 | 81 | else { |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | |
108 | 108 | $html = $this->getSession()->getDriver()->getContent(); |
109 | 109 | $text = $this->validateTextForSearchInSource($text); |
110 | - $regex = '/' . $text . '/'; |
|
110 | + $regex = '/'.$text.'/'; |
|
111 | 111 | |
112 | 112 | preg_match($regex, $html, $results); |
113 | 113 | |
114 | 114 | if ($results == null) { |
115 | - throw new \Exception('The searched text ' . $text . ' was not found in the source of the page.'); |
|
115 | + throw new \Exception('The searched text '.$text.' was not found in the source of the page.'); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return true; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | $session = $this->getSession(); |
133 | 133 | $element = $session->getPage()->find('region', $region)->find('xpath', $session->getSelectorsHandler()->selectorToXpath('xpath', |
134 | - '//*[contains(text(),"' . $text . '")]')); |
|
134 | + '//*[contains(text(),"'.$text.'")]')); |
|
135 | 135 | |
136 | 136 | if (null === $element) { |
137 | 137 | throw new \InvalidArgumentException(sprintf('Cannot find text: "%s"', $text)); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | |
145 | 145 | $session = $this->getSession(); |
146 | 146 | $element = $session->getPage()->find('region', $region)->find('xpath', $session->getSelectorsHandler()->selectorToXpath('xpath', |
147 | - '//*[contains(text(),"' . $text . '")]')); |
|
147 | + '//*[contains(text(),"'.$text.'")]')); |
|
148 | 148 | |
149 | 149 | if (null === $element) { |
150 | 150 | throw new \InvalidArgumentException(sprintf('Cannot find text: "%s"', $text)); |
@@ -70,15 +70,13 @@ discard block |
||
70 | 70 | |
71 | 71 | if(isset($element)) { |
72 | 72 | $text = $element->getValue(); |
73 | - } |
|
74 | - else { |
|
73 | + } else { |
|
75 | 74 | throw new \Exception(sprintf("Element is null")); |
76 | 75 | } |
77 | 76 | |
78 | 77 | if($text === $value) { |
79 | 78 | return true; |
80 | - } |
|
81 | - else { |
|
79 | + } else { |
|
82 | 80 | throw new \Exception(sprintf('Value of input : "%s" does not match the text "%s"', $text, $value)); |
83 | 81 | } |
84 | 82 | } |
@@ -92,8 +90,7 @@ discard block |
||
92 | 90 | $this->iShouldSeeInTheSourceOfThePage($text); |
93 | 91 | $isTextFound = true; |
94 | 92 | break; |
95 | - } |
|
96 | - catch (\Exception $e) { |
|
93 | + } catch (\Exception $e) { |
|
97 | 94 | sleep(1); |
98 | 95 | } |
99 | 96 | } |