25
25
use Symfony \Component \DomCrawler \Crawler ;
26
26
use Symfony \Component \DomCrawler \Field \ChoiceFormField ;
27
27
use Symfony \Component \DomCrawler \Field \FileFormField ;
28
+ use Symfony \Component \DomCrawler \Field \FormField ;
28
29
use Symfony \Component \DomCrawler \Field \InputFormField ;
29
30
use Symfony \Component \DomCrawler \Field \TextareaFormField ;
30
31
use Symfony \Component \DomCrawler \Form ;
@@ -57,7 +58,7 @@ class InnerBrowser extends Module implements Web, PageSourceSaver, ElementLocato
57
58
58
59
protected $ defaultCookieParameters = ['expires ' => null , 'path ' => '/ ' , 'domain ' => '' , 'secure ' => false ];
59
60
60
- protected $ internalDomains = null ;
61
+ protected $ internalDomains ;
61
62
62
63
private $ baseUrl ;
63
64
@@ -73,7 +74,7 @@ public function _failed(TestInterface $test, $fail)
73
74
return ;
74
75
}
75
76
$ filename = preg_replace ('~\W~ ' , '. ' , Descriptor::getTestSignatureUnique ($ test ));
76
-
77
+
77
78
$ extensions = [
78
79
'application/json ' => 'json ' ,
79
80
'text/xml ' => 'xml ' ,
@@ -86,12 +87,12 @@ public function _failed(TestInterface $test, $fail)
86
87
} catch (BadMethodCallException $ e ) {
87
88
$ internalResponse = false ;
88
89
}
89
-
90
+
90
91
$ responseContentType = $ internalResponse ? $ internalResponse ->getHeader ('content-type ' ) : '' ;
91
92
list ($ responseMimeType ) = explode ('; ' , $ responseContentType );
92
-
93
+
93
94
$ extension = isset ($ extensions [$ responseMimeType ]) ? $ extensions [$ responseMimeType ] : 'html ' ;
94
-
95
+
95
96
$ filename = mb_strcut ($ filename , 0 , 244 , 'utf-8 ' ) . '.fail. ' . $ extension ;
96
97
$ this ->_savePageSource ($ report = codecept_output_dir () . $ filename );
97
98
$ test ->getMetadata ()->addReport ('html ' , $ report );
@@ -444,7 +445,9 @@ protected function clickByLocator($link)
444
445
if ($ tag === 'a ' ) {
445
446
$ this ->openHrefFromDomNode ($ node );
446
447
return true ;
447
- } elseif (in_array ($ tag , ['input ' , 'button ' ]) && in_array ($ type , ['submit ' , 'image ' ])) {
448
+ }
449
+
450
+ if (in_array ($ tag , ['input ' , 'button ' ]) && in_array ($ type , ['submit ' , 'image ' ])) {
448
451
return $ this ->clickButton ($ node );
449
452
}
450
453
}
@@ -490,15 +493,15 @@ private function clickButton(\DOMNode $node)
490
493
$ formParams
491
494
);
492
495
return true ;
493
- } else {
494
- // Check if the button is inside an anchor.
495
- $ currentNode = $ node ;
496
- while ( $ currentNode-> parentNode !== null ) {
497
- $ currentNode = $ currentNode ->parentNode ;
498
- if ( $ currentNode ->nodeName === ' a ' ) {
499
- $ this -> openHrefFromDomNode ($ currentNode);
500
- return true ;
501
- }
496
+ }
497
+
498
+ // Check if the button is inside an anchor.
499
+ $ currentNode = $ node ;
500
+ while ( $ currentNode ->parentNode !== null ) {
501
+ $ currentNode = $ currentNode ->parentNode ;
502
+ if ($ currentNode-> nodeName === ' a ' ) {
503
+ $ this -> openHrefFromDomNode ( $ currentNode ) ;
504
+ return true ;
502
505
}
503
506
}
504
507
throw new TestRuntimeException ('Button is not inside a link or a form ' );
@@ -523,7 +526,7 @@ private function retrieveBaseUrl()
523
526
if (count ($ baseHref ) > 0 ) {
524
527
$ baseUrl = $ baseHref ->getNode (0 )->getAttribute ('href ' );
525
528
}
526
- if ($ baseUrl == '' ) {
529
+ if ($ baseUrl === '' ) {
527
530
$ baseUrl = $ this ->_getCurrentUri ();
528
531
}
529
532
return $ this ->getAbsoluteUrlFor ($ baseUrl );
@@ -579,10 +582,8 @@ public function seeLink($text, $url = null)
579
582
public function dontSeeLink ($ text , $ url = '' )
580
583
{
581
584
$ crawler = $ this ->getCrawler ()->selectLink ($ text );
582
- if (!$ url ) {
583
- if ($ crawler ->count () > 0 ) {
584
- $ this ->fail ("Link containing text ' $ text' was found in page " . $ this ->_getCurrentUri ());
585
- }
585
+ if (!$ url && $ crawler ->count () > 0 ) {
586
+ $ this ->fail ("Link containing text ' $ text' was found in page " . $ this ->_getCurrentUri ());
586
587
}
587
588
$ crawler = $ crawler ->filterXPath (
588
589
sprintf ('.//a[substring(@href, string-length(@href) - string-length(%1$s) + 1)=%1$s] ' ,
@@ -624,12 +625,12 @@ public function dontSeeCurrentUrlEquals($uri)
624
625
625
626
public function seeCurrentUrlMatches ($ uri )
626
627
{
627
- \ PHPUnit \ Framework \Assert:: assertRegExp ($ uri , $ this ->_getCurrentUri ());
628
+ $ this -> assertRegExp ($ uri , $ this ->_getCurrentUri ());
628
629
}
629
630
630
631
public function dontSeeCurrentUrlMatches ($ uri )
631
632
{
632
- \ PHPUnit \ Framework \Assert:: assertNotRegExp ($ uri , $ this ->_getCurrentUri ());
633
+ $ this -> assertNotRegExp ($ uri , $ this ->_getCurrentUri ());
633
634
}
634
635
635
636
public function grabFromCurrentUrl ($ uri = null )
@@ -694,9 +695,7 @@ protected function proceedSeeInFormFields($formSelector, array $params, $assertN
694
695
$ this ->pushFormField ($ fields , $ form , $ name , $ values );
695
696
}
696
697
697
- foreach ($ fields as $ element ) {
698
- list ($ field , $ values ) = $ element ;
699
-
698
+ foreach ($ fields as list ($ field , $ values )) {
700
699
if (!is_array ($ values )) {
701
700
$ values = [$ values ];
702
701
}
@@ -805,7 +804,8 @@ protected function getValueAndTextFromField(Crawler $nodes)
805
804
*/
806
805
protected function getInputValue ($ input )
807
806
{
808
- if ($ input ->attr ('type ' ) == 'checkbox ' or $ input ->attr ('type ' ) == 'radio ' ) {
807
+ $ inputType = $ input ->attr ('type ' );
808
+ if ($ inputType === 'checkbox ' || $ inputType === 'radio ' ) {
809
809
$ values = [];
810
810
811
811
foreach ($ input ->filter (':checked ' ) as $ checkbox ) {
@@ -854,10 +854,12 @@ protected function setCheckboxBoolValues(Crawler $form, array $params)
854
854
foreach ($ checkboxes as $ box ) {
855
855
$ fieldName = $ this ->getSubmissionFormFieldName ($ box ->getAttribute ('name ' ));
856
856
$ pos = (!isset ($ chFoundByName [$ fieldName ])) ? 0 : $ chFoundByName [$ fieldName ];
857
- $ skip = ( !isset ($ params [$ fieldName ]) )
857
+ $ skip = !isset ($ params [$ fieldName ])
858
858
|| (!is_array ($ params [$ fieldName ]) && !is_bool ($ params [$ fieldName ]))
859
- || (is_array ($ params [$ fieldName ]) && $ pos >= count ($ params [$ fieldName ])
860
- || (is_array ($ params [$ fieldName ]) && !is_bool ($ params [$ fieldName ][$ pos ])));
859
+ || (is_array ($ params [$ fieldName ]) &&
860
+ ($ pos >= count ($ params [$ fieldName ]) || !is_bool ($ params [$ fieldName ][$ pos ]))
861
+ );
862
+
861
863
if ($ skip ) {
862
864
continue ;
863
865
}
@@ -914,7 +916,7 @@ protected function proceedSubmitForm(Crawler $frmCrawl, array $params, $button =
914
916
if (!$ url ) {
915
917
$ url = $ this ->getFormUrl ($ frmCrawl );
916
918
}
917
-
919
+
918
920
if (strcasecmp ($ form ->getMethod (), 'GET ' ) === 0 ) {
919
921
$ url = Uri::mergeUrls ($ url , '? ' . http_build_query ($ requestParams ));
920
922
}
@@ -957,7 +959,7 @@ public function submitForm($selector, array $params, $button = null)
957
959
protected function getAbsoluteUrlFor ($ uri )
958
960
{
959
961
$ currentUrl = $ this ->getRunningClient ()->getHistory ()->current ()->getUri ();
960
- if (empty ($ uri ) || $ uri[ 0 ] === ' # ' ) {
962
+ if (empty ($ uri ) || strpos ( $ uri, ' # ' ) === 0 ) {
961
963
return $ currentUrl ;
962
964
}
963
965
return Uri::mergeUrls ($ currentUrl , $ uri );
@@ -1052,7 +1054,7 @@ protected function getFormValuesFor(Form $form)
1052
1054
$ values = [];
1053
1055
$ fields = $ form ->all ();
1054
1056
foreach ($ fields as $ field ) {
1055
- if ($ field ->isDisabled () || !$ field ->hasValue () || $ field instanceof FileFormField ) {
1057
+ if ($ field instanceof FileFormField || $ field ->isDisabled () || !$ field ->hasValue ()) {
1056
1058
continue ;
1057
1059
}
1058
1060
$ fieldName = $ this ->getSubmissionFormFieldName ($ field ->getName ());
@@ -1074,13 +1076,13 @@ public function fillField($field, $value)
1074
1076
$ form = $ this ->getFormFor ($ input );
1075
1077
$ name = $ input ->attr ('name ' );
1076
1078
1077
- $ dynamicField = $ input ->getNode (0 )->tagName == 'textarea '
1079
+ $ dynamicField = $ input ->getNode (0 )->tagName === 'textarea '
1078
1080
? new TextareaFormField ($ input ->getNode (0 ))
1079
1081
: new InputFormField ($ input ->getNode (0 ));
1080
1082
$ formField = $ this ->matchFormField ($ name , $ form , $ dynamicField );
1081
1083
$ formField ->setValue ($ value );
1082
1084
$ input ->getNode (0 )->setAttribute ('value ' , htmlspecialchars ($ value ));
1083
- if ($ input ->getNode (0 )->tagName == 'textarea ' ) {
1085
+ if ($ input ->getNode (0 )->tagName === 'textarea ' ) {
1084
1086
$ input ->getNode (0 )->nodeValue = htmlspecialchars ($ value );
1085
1087
}
1086
1088
}
@@ -1327,7 +1329,7 @@ protected function debugResponse($url)
1327
1329
public function makeHtmlSnapshot ($ name = null )
1328
1330
{
1329
1331
if (empty ($ name )) {
1330
- $ name = uniqid (date ("Y-m-d_H-i-s_ " ));
1332
+ $ name = uniqid (date ("Y-m-d_H-i-s_ " ), true );
1331
1333
}
1332
1334
$ debugDir = codecept_output_dir () . 'debug ' ;
1333
1335
if (!is_dir ($ debugDir )) {
@@ -1410,8 +1412,8 @@ protected function filterByAttributes(Crawler $nodes, array $attributes)
1410
1412
{
1411
1413
foreach ($ attributes as $ attr => $ val ) {
1412
1414
$ nodes = $ nodes ->reduce (
1413
- function (Crawler $ node ) use ($ attr , $ val ) {
1414
- return $ node ->attr ($ attr ) == $ val ;
1415
+ static function (Crawler $ node ) use ($ attr , $ val ) {
1416
+ return $ node ->attr ($ attr ) === $ val ;
1415
1417
}
1416
1418
);
1417
1419
}
@@ -1610,7 +1612,7 @@ public function seeOptionIsSelected($selector, $optionText)
1610
1612
$ selected = $ this ->matchSelectedOption ($ selector );
1611
1613
$ this ->assertDomContains ($ selected , 'selected option ' );
1612
1614
//If element is radio then we need to check value
1613
- $ value = $ selected ->getNode (0 )->tagName == 'option '
1615
+ $ value = $ selected ->getNode (0 )->tagName === 'option '
1614
1616
? $ selected ->text ()
1615
1617
: $ selected ->getNode (0 )->getAttribute ('value ' );
1616
1618
$ this ->assertEquals ($ optionText , $ value );
@@ -1624,7 +1626,7 @@ public function dontSeeOptionIsSelected($selector, $optionText)
1624
1626
return ;
1625
1627
}
1626
1628
//If element is radio then we need to check value
1627
- $ value = $ selected ->getNode (0 )->tagName == 'option '
1629
+ $ value = $ selected ->getNode (0 )->tagName === 'option '
1628
1630
? $ selected ->text ()
1629
1631
: $ selected ->getNode (0 )->getAttribute ('value ' );
1630
1632
$ this ->assertNotEquals ($ optionText , $ value );
@@ -1634,7 +1636,7 @@ protected function matchSelectedOption($select)
1634
1636
{
1635
1637
$ nodes = $ this ->getFieldsByLabelOrCss ($ select );
1636
1638
$ selectedOptions = $ nodes ->filter ('option[selected],input:checked ' );
1637
- if ($ selectedOptions ->count () == 0 ) {
1639
+ if ($ selectedOptions ->count () === 0 ) {
1638
1640
$ selectedOptions = $ nodes ->filter ('option,input ' )->first ();
1639
1641
}
1640
1642
return $ selectedOptions ;
@@ -1821,7 +1823,7 @@ protected function assertPageSourceNotContains($needle, $message = '')
1821
1823
*/
1822
1824
protected function matchFormField ($ name , $ form , $ dynamicField )
1823
1825
{
1824
- if (substr ($ name , -2 ) != '[] ' ) {
1826
+ if (substr ($ name , -2 ) !== '[] ' ) {
1825
1827
return $ form [$ name ];
1826
1828
}
1827
1829
$ name = substr ($ name , 0 , -2 );
@@ -1884,14 +1886,16 @@ protected function getFormPhpValues($requestParams)
1884
1886
1885
1887
/**
1886
1888
* @param $result
1889
+ * @param $maxRedirects
1890
+ * @param $redirectCount
1887
1891
* @return mixed
1888
1892
*/
1889
1893
protected function redirectIfNecessary ($ result , $ maxRedirects , $ redirectCount )
1890
1894
{
1891
1895
$ locationHeader = $ this ->client ->getInternalResponse ()->getHeader ('Location ' );
1892
1896
$ statusCode = $ this ->getResponseStatusCode ();
1893
1897
if ($ locationHeader && $ statusCode >= 300 && $ statusCode < 400 ) {
1894
- if ($ redirectCount == $ maxRedirects ) {
1898
+ if ($ redirectCount === $ maxRedirects ) {
1895
1899
throw new \LogicException (sprintf (
1896
1900
'The maximum number (%d) of redirections was reached. ' ,
1897
1901
$ maxRedirects
@@ -2042,6 +2046,7 @@ protected function getNormalizedResponseContent()
2042
2046
* ```php
2043
2047
* $I->setServerParameters([]);
2044
2048
* ```
2049
+ * @param array $params
2045
2050
*/
2046
2051
public function setServerParameters (array $ params )
2047
2052
{
@@ -2054,6 +2059,8 @@ public function setServerParameters(array $params)
2054
2059
* ```php
2055
2060
* $I->haveServerParameter('name', 'value');
2056
2061
* ```
2062
+ * @param $name
2063
+ * @param $value
2057
2064
*/
2058
2065
public function haveServerParameter ($ name , $ value )
2059
2066
{
0 commit comments