1212
1313use Behat \Mink \Exception \DriverException ;
1414use Behat \Mink \Exception \UnsupportedDriverActionException ;
15+ use Symfony \Component \BrowserKit \AbstractBrowser ;
1516use Symfony \Component \BrowserKit \Client ;
1617use Symfony \Component \BrowserKit \Cookie ;
1718use Symfony \Component \BrowserKit \Exception \BadMethodCallException ;
2122use Symfony \Component \DomCrawler \Field \FileFormField ;
2223use Symfony \Component \DomCrawler \Field \FormField ;
2324use Symfony \Component \DomCrawler \Field \InputFormField ;
24- use Symfony \Component \DomCrawler \Field \TextareaFormField ;
2525use Symfony \Component \DomCrawler \Form ;
26- use Symfony \Component \HttpKernel \Client as HttpKernelClient ;
26+ use Symfony \Component \HttpKernel \HttpKernelBrowser ;
2727
2828/**
2929 * Symfony2 BrowserKit driver.
@@ -40,67 +40,33 @@ class BrowserKitDriver extends CoreDriver
4040 private $ forms = array ();
4141 private $ serverParameters = array ();
4242 private $ started = false ;
43- private $ removeScriptFromUrl = false ;
44- private $ removeHostFromUrl = false ;
4543
4644 /**
4745 * Initializes BrowserKit driver.
4846 *
4947 * @param Client $client BrowserKit client instance
5048 * @param string|null $baseUrl Base URL for HttpKernel clients
5149 */
52- public function __construct (Client $ client , $ baseUrl = null )
50+ public function __construct (AbstractBrowser $ client , $ baseUrl = null )
5351 {
5452 $ this ->client = $ client ;
5553 $ this ->client ->followRedirects (true );
5654
57- if ($ baseUrl !== null && $ client instanceof HttpKernelClient ) {
55+ if ($ baseUrl !== null && $ client instanceof HttpKernelBrowser ) {
5856 $ client ->setServerParameter ('SCRIPT_FILENAME ' , parse_url ($ baseUrl , PHP_URL_PATH ));
5957 }
6058 }
6159
6260 /**
63- * Returns BrowserKit HTTP client instance.
61+ * Returns BrowserKit browser instance.
6462 *
65- * @return Client
63+ * @return AbstractBrowser
6664 */
6765 public function getClient ()
6866 {
6967 return $ this ->client ;
7068 }
7169
72- /**
73- * Tells driver to remove hostname from URL.
74- *
75- * @param boolean $remove
76- *
77- * @deprecated Deprecated as of 1.2, to be removed in 2.0. Pass the base url in the constructor instead.
78- */
79- public function setRemoveHostFromUrl ($ remove = true )
80- {
81- @trigger_error (
82- 'setRemoveHostFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead. ' ,
83- E_USER_DEPRECATED
84- );
85- $ this ->removeHostFromUrl = (bool ) $ remove ;
86- }
87-
88- /**
89- * Tells driver to remove script name from URL.
90- *
91- * @param boolean $remove
92- *
93- * @deprecated Deprecated as of 1.2, to be removed in 2.0. Pass the base url in the constructor instead.
94- */
95- public function setRemoveScriptFromUrl ($ remove = true )
96- {
97- @trigger_error (
98- 'setRemoveScriptFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead. ' ,
99- E_USER_DEPRECATED
100- );
101- $ this ->removeScriptFromUrl = (bool ) $ remove ;
102- }
103-
10470 /**
10571 * {@inheritdoc}
10672 */
@@ -316,11 +282,6 @@ public function getStatusCode()
316282 {
317283 $ response = $ this ->getResponse ();
318284
319- // BC layer for Symfony < 4.3
320- if (!method_exists ($ response , 'getStatusCode ' )) {
321- return $ response ->getStatus ();
322- }
323-
324285 return $ response ->getStatusCode ();
325286 }
326287
@@ -361,11 +322,8 @@ public function getTagName($xpath)
361322 public function getText ($ xpath )
362323 {
363324 $ text = $ this ->getFilteredCrawler ($ xpath )->text (null , true );
364- // TODO drop our own normalization once supporting only dom-crawler 4.4+ as it already does it.
365- $ text = str_replace ("\n" , ' ' , $ text );
366- $ text = preg_replace ('/ {2,}/ ' , ' ' , $ text );
367325
368- return trim ( $ text) ;
326+ return $ text ;
369327 }
370328
371329 /**
@@ -383,13 +341,7 @@ public function getOuterHtml($xpath)
383341 {
384342 $ crawler = $ this ->getFilteredCrawler ($ xpath );
385343
386- if (method_exists ($ crawler , 'outerHtml ' )) {
387- return $ crawler ->outerHtml ();
388- }
389-
390- $ node = $ this ->getCrawlerNode ($ crawler );
391-
392- return $ node ->ownerDocument ->saveHTML ($ node );
344+ return $ crawler ->outerHtml ();
393345 }
394346
395347 /**
@@ -592,13 +544,7 @@ protected function getResponse()
592544 */
593545 protected function prepareUrl ($ url )
594546 {
595- if (!$ this ->removeHostFromUrl && !$ this ->removeScriptFromUrl ) {
596- return $ url ;
597- }
598-
599- $ replacement = ($ this ->removeHostFromUrl ? '' : '$1 ' ) . ($ this ->removeScriptFromUrl ? '' : '$2 ' );
600-
601- return preg_replace ('#(https?\://[^/]+)(/[^/\.]+\.php)?# ' , $ replacement , $ url );
547+ return $ url ;
602548 }
603549
604550 /**
@@ -725,13 +671,6 @@ private function submit(Form $form)
725671 }
726672 }
727673
728- foreach ($ form ->all () as $ field ) {
729- // Add a fix for https://github.com/symfony/symfony/pull/10733 to support Symfony versions which are not fixed
730- if ($ field instanceof TextareaFormField && null === $ field ->getValue ()) {
731- $ field ->setValue ('' );
732- }
733- }
734-
735674 $ this ->client ->submit ($ form , array (), $ this ->serverParameters );
736675
737676 $ this ->forms = array ();
@@ -846,15 +785,7 @@ private function mergeForms(Form $to, Form $from)
846785 */
847786 private function getCrawlerNode (Crawler $ crawler )
848787 {
849- $ node = null ;
850-
851- if ($ crawler instanceof \Iterator) {
852- // for symfony 2.3 compatibility as getNode is not public before symfony 2.4
853- $ crawler ->rewind ();
854- $ node = $ crawler ->current ();
855- } else {
856- $ node = $ crawler ->getNode (0 );
857- }
788+ $ node = $ crawler ->getNode (0 );
858789
859790 if (null !== $ node ) {
860791 return $ node ;
0 commit comments