Completed
Push — master ( 527efe...c8c92c )
by Toni
02:56
created
src/Context/MultilingualContext.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -72,6 +72,7 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Unused Use Statements   -6 removed lines patch added patch discarded remove patch
@@ -4,13 +4,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
         $file_path = $base_path.$this->multilingual_parameters['translations'];
47 47
         $yaml = file_get_contents($file_path);
48 48
         $yaml_parse_array_check = Yaml::parse($yaml);
49
-        if(is_array($yaml_parse_array_check)) {
49
+        if (is_array($yaml_parse_array_check)) {
50 50
             $this->translations = $yaml_parse_array_check;
51 51
         }
52 52
     }
53 53
 
54 54
     public function initializeMultilanguage() {
55
-        if(isset($this->multilingual_parameters['translations'])) {
55
+        if (isset($this->multilingual_parameters['translations'])) {
56 56
             $this->parseTranslationFile();
57 57
         }
58 58
         $this->parseLanguageCodes();
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
         $current_url = $this->getSession()->getCurrentUrl();
77 77
         $base_url = $this->getMinkParameter('base_url');
78 78
         $base_url_length = strlen($base_url);
79
-        $clean_url_language_code = substr($current_url,$base_url_length,2);
80
-        $not_clean_url_language_code = substr($current_url,$base_url_length+3,2);
79
+        $clean_url_language_code = substr($current_url, $base_url_length, 2);
80
+        $not_clean_url_language_code = substr($current_url, $base_url_length + 3, 2);
81 81
 
82
-        if(in_array($clean_url_language_code,$this->languages_iso_codes)) {
82
+        if (in_array($clean_url_language_code, $this->languages_iso_codes)) {
83 83
             return $clean_url_language_code;
84 84
         }
85
-        else if (in_array($not_clean_url_language_code,$this->languages_iso_codes)){
85
+        else if (in_array($not_clean_url_language_code, $this->languages_iso_codes)) {
86 86
             return $not_clean_url_language_code;
87 87
         }
88 88
         else return $this->multilingual_parameters['default_language'];
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
 
98 98
     public function localizeTarget($target) {
99 99
         $translations = $this->multilingual_parameters['translations'];
100
-        if(isset($this->translations[$target][$this->multilingual_parameters['default_language']])){
100
+        if (isset($this->translations[$target][$this->multilingual_parameters['default_language']])) {
101 101
             $target = $this->translations[$target][$this->languageDetection()];
102 102
             return $target;
103 103
         }
104 104
         elseif (isset($this->translations[$target])) {
105 105
             return $target;
106 106
         }
107
-        else throw new \Exception ("The text '$target'' is not defined in '$translations' translation file.");
107
+        else throw new \Exception("The text '$target'' is not defined in '$translations' translation file.");
108 108
     }
109 109
 
110 110
     /**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     public function localizeField($field) {
115 115
         $re = "/(?:[-])(".$this->multilingual_parameters['default_language'].")(?:[-])/";
116 116
         $language = "-".$this->languageDetection()."-";
117
-        $field = preg_replace($re, $language,$field);
117
+        $field = preg_replace($re, $language, $field);
118 118
         return $field;
119 119
     }
120 120
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @When /^I wait for localized text "([^"]*)" to appear with max time "([^"]+)"(?: seconds)?$/
205 205
      */
206
-    public function iWaitForLocalizedTextToAppearWithMaxTime($target, $maxExecutionTime){
206
+    public function iWaitForLocalizedTextToAppearWithMaxTime($target, $maxExecutionTime) {
207 207
         $target = $this->localizeTarget($target);
208 208
         $this->iWaitForTextToAppearWithMaxTime($target, $maxExecutionTime);
209 209
     }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      * @Given I click localized :link in the :rowText row
228 228
      * @Then I (should )see the localized :link in the :rowText row
229 229
      */
230
-    public function assertLocalizedClickInTableRow($link, $rowText){
230
+    public function assertLocalizedClickInTableRow($link, $rowText) {
231 231
         $link = $this->localizeTarget($link);
232 232
         $page = $this->getSession()->getPage();
233 233
         if ($link_element = $this->getTableRow($page, $rowText)->findLink($link)) {
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      *
257 257
      * @When /^I click on the localized text "([^"]*)" in the "(?P<region>[^"]*)"(?:| region)$/
258 258
      */
259
-    public function iClickOnTheLocalizedTextInRegion($text, $region){
259
+    public function iClickOnTheLocalizedTextInRegion($text, $region) {
260 260
         $text = $this->localizeTarget($text);
261 261
         $this->iClickOnTheTextInRegion($text, $region);
262 262
     }
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 
82 82
         if(in_array($clean_url_language_code,$this->languages_iso_codes)) {
83 83
             return $clean_url_language_code;
84
-        }
85
-        else if (in_array($not_clean_url_language_code,$this->languages_iso_codes)){
84
+        } else if (in_array($not_clean_url_language_code,$this->languages_iso_codes)){
86 85
             return $not_clean_url_language_code;
86
+        } else {
87
+            return $this->multilingual_parameters['default_language'];
87 88
         }
88
-        else return $this->multilingual_parameters['default_language'];
89 89
     }
90 90
 
91 91
     /**
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
         if(isset($this->translations[$target][$this->multilingual_parameters['default_language']])){
101 101
             $target = $this->translations[$target][$this->languageDetection()];
102 102
             return $target;
103
-        }
104
-        elseif (isset($this->translations[$target])) {
103
+        } elseif (isset($this->translations[$target])) {
105 104
             return $target;
105
+        } else {
106
+            throw new \Exception ("The text '$target'' is not defined in '$translations' translation file.");
106 107
         }
107
-        else throw new \Exception ("The text '$target'' is not defined in '$translations' translation file.");
108 108
     }
109 109
 
110 110
     /**
Please login to merge, or discard this patch.
src/Context/RawMultilingualContext.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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));
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -70,15 +70,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.