Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 05c0579

Browse files
authored
Merge pull request #338 from OndraM/fix/post-params
Fixes incompatibility with Appium
2 parents 70872c4 + b1d4b9f commit 05c0579

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"require-dev": {
1818
"phpunit/phpunit": "4.6.* || ~5.0",
1919
"friendsofphp/php-cs-fixer": "^1.11",
20-
"squizlabs/php_codesniffer": "^2.6"
20+
"squizlabs/php_codesniffer": "^2.6",
21+
"php-mock/php-mock-phpunit": "^1.1"
2122
},
2223
"suggest": {
2324
"phpdocumentor/phpdocumentor": "2.*"

lib/Remote/HttpCommandExecutor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ public function execute(WebDriverCommand $command)
240240
foreach ($params as $name => $value) {
241241
if ($name[0] === ':') {
242242
$url = str_replace($name, $value, $url);
243-
if ($http_method != 'POST') {
244-
unset($params[$name]);
245-
}
243+
unset($params[$name]);
246244
}
247245
}
248246

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
namespace Facebook\WebDriver\Remote;
17+
18+
use phpmock\phpunit\PHPMock;
19+
20+
class HttpCommandExecutorTest extends \PHPUnit_Framework_TestCase
21+
{
22+
use PHPMock;
23+
/** @var HttpCommandExecutor */
24+
private $executor;
25+
26+
public function setUp()
27+
{
28+
$this->executor = new HttpCommandExecutor('http://localhost:4444');
29+
}
30+
31+
/**
32+
* @dataProvider commandProvider
33+
* @param int $command
34+
* @param array $params
35+
* @param string $expectedUrl
36+
* @param string $expectedPostData
37+
*/
38+
public function testShouldSendRequestToAssembledUrl($command, array $params, $expectedUrl, $expectedPostData)
39+
{
40+
$command = new WebDriverCommand('foo-123', $command, $params);
41+
42+
$curlSetoptMock = $this->getFunctionMock(__NAMESPACE__, 'curl_setopt');
43+
$curlSetoptMock->expects($this->at(0))
44+
->with($this->anything(), CURLOPT_URL, $expectedUrl);
45+
46+
$curlSetoptMock->expects($this->at(2))
47+
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
48+
49+
$curlExecMock = $this->getFunctionMock(__NAMESPACE__, 'curl_exec');
50+
$curlExecMock->expects($this->once())
51+
->willReturn('{}');
52+
53+
$this->executor->execute($command);
54+
}
55+
56+
/**
57+
* @return array[]
58+
*/
59+
public function commandProvider()
60+
{
61+
return [
62+
'POST command having :id placeholder in url' => [
63+
DriverCommand::SEND_KEYS_TO_ELEMENT,
64+
['value' => 'submitted-value', ':id' => '1337'],
65+
'http://localhost:4444/session/foo-123/element/1337/value',
66+
'{"value":"submitted-value"}',
67+
],
68+
'POST command without :id placeholder in url' => [
69+
DriverCommand::TOUCH_UP,
70+
['x' => 3, 'y' => 6],
71+
'http://localhost:4444/session/foo-123/touch/up',
72+
'{"x":3,"y":6}',
73+
],
74+
'Extra useless placeholder parameter should be removed' => [
75+
DriverCommand::TOUCH_UP,
76+
['x' => 3, 'y' => 6, ':useless' => 'foo'],
77+
'http://localhost:4444/session/foo-123/touch/up',
78+
'{"x":3,"y":6}',
79+
],
80+
'DELETE command' => [
81+
DriverCommand::DELETE_COOKIE,
82+
[':name' => 'cookie-name'],
83+
'http://localhost:4444/session/foo-123/cookie/cookie-name',
84+
null,
85+
],
86+
'GET command without session in URL' => [
87+
DriverCommand::GET_ALL_SESSIONS,
88+
[],
89+
'http://localhost:4444/sessions',
90+
null,
91+
],
92+
];
93+
}
94+
}

0 commit comments

Comments
 (0)