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

Commit 1c98108

Browse files
committed
Merge pull request #274 from OndraM/improve-tests
Improve unit tests & codestyle
2 parents 805ca9b + a0485d4 commit 1c98108

27 files changed

+347
-83
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
},
2727
"autoload-dev": {
2828
"psr-4": {
29-
"Facebook\\WebDriver\\": "tests/functional"
30-
}
29+
"Facebook\\WebDriver\\": "tests/unit"
30+
},
31+
"classmap": ["tests/functional/"]
3132
}
3233
}

lib/Chrome/ChromeOptions.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public function addExtensions(array $paths) {
8585
}
8686

8787
/**
88-
* @param array $encoded_extensions An array of base64 encoded of the
89-
* extensions.
88+
* @param array $encoded_extensions An array of base64 encoded of the extensions.
9089
* @return ChromeOptions
9190
*/
9291
public function addEncodedExtensions(array $encoded_extensions) {
@@ -109,8 +108,7 @@ public function setExperimentalOption($name, $value) {
109108
}
110109

111110
/**
112-
* @return DesiredCapabilities The DesiredCapabilities for Chrome with this
113-
* options.
111+
* @return DesiredCapabilities The DesiredCapabilities for Chrome with this options.
114112
*/
115113
public function toCapabilities() {
116114
$capabilities = DesiredCapabilities::chrome();

lib/Firefox/FirefoxDriver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
namespace Facebook\WebDriver\Firefox;
1717

1818
class FirefoxDriver {
19-
2019
const PROFILE = 'firefox_profile';
20+
21+
private function __construct()
22+
{
23+
}
2124
}

lib/Firefox/FirefoxPreferences.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Firefox;
17+
18+
/**
19+
* Constants of common Firefox profile preferences (about:config values).
20+
* @see http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
21+
*/
22+
class FirefoxPreferences {
23+
/** @var string Port WebDriver uses to communicate with Firefox instance */
24+
const WEBDRIVER_FIREFOX_PORT = 'webdriver_firefox_port';
25+
/** @var string Should the reader view (FF 38+) be enabled? */
26+
const READER_PARSE_ON_LOAD_ENABLED = 'reader.parse-on-load.enabled';
27+
/** @var string Browser homepage */
28+
const BROWSER_STARTUP_HOMEPAGE = 'browser.startup.homepage';
29+
30+
private function __construct()
31+
{
32+
}
33+
}

lib/Firefox/FirefoxProfile.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function addExtension($extension) {
5555
/**
5656
* @param string $extension_datas The path to the folder containing the datas to add to the extension
5757
* @return FirefoxProfile
58-
*/
58+
*/
5959
public function addExtensionDatas($extension_datas) {
6060
if (!is_dir($extension_datas)) {
6161
return;
@@ -73,7 +73,7 @@ public function setRdfFile($rdf_file) {
7373
if (!is_file($rdf_file)) {
7474
return;
7575
}
76-
76+
7777
$this->rdf_file = $rdf_file;
7878
return $this;
7979
}
@@ -99,6 +99,19 @@ public function setPreference($key, $value) {
9999
return $this;
100100
}
101101

102+
/**
103+
* @param $key
104+
* @return mixed
105+
*/
106+
public function getPreference($key)
107+
{
108+
if (array_key_exists($key, $this->preferences)) {
109+
return $this->preferences[$key];
110+
}
111+
112+
return null;
113+
}
114+
102115
/**
103116
* @return string
104117
*/

lib/Remote/DesiredCapabilities.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Exception;
1919
use Facebook\WebDriver\Chrome\ChromeOptions;
2020
use Facebook\WebDriver\Firefox\FirefoxDriver;
21+
use Facebook\WebDriver\Firefox\FirefoxPreferences;
2122
use Facebook\WebDriver\Firefox\FirefoxProfile;
2223
use Facebook\WebDriver\WebDriverCapabilities;
2324
use Facebook\WebDriver\WebDriverPlatform;
@@ -203,7 +204,7 @@ public static function firefox() {
203204

204205
// disable the "Reader View" help tooltip, which can hide elements in the window.document
205206
$profile = new FirefoxProfile();
206-
$profile->setPreference('reader.parse-on-load.enabled', false);
207+
$profile->setPreference(FirefoxPreferences::READER_PARSE_ON_LOAD_ENABLED, false);
207208
$caps->setCapability(FirefoxDriver::PROFILE, $profile);
208209

209210
return $caps;

lib/Remote/DriverCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* This list of command defined in the WebDriver json wire protocol.
2020
*/
2121
class DriverCommand {
22-
2322
const GET_ALL_SESSIONS = "getAllSessions";
2423
const GET_CAPABILITIES = "getCapabilities";
2524
const NEW_SESSION = "newSession";
@@ -126,16 +125,14 @@ class DriverCommand {
126125
const SET_SCREEN_ORIENTATION = "setScreenOrientation";
127126
const GET_SCREEN_ORIENTATION = "getScreenOrientation";
128127

129-
// These belong to the Advanced user interactions - an element is
130-
// optional for these commands.
128+
// These belong to the Advanced user interactions - an element is optional for these commands.
131129
const CLICK = "mouseClick";
132130
const DOUBLE_CLICK = "mouseDoubleClick";
133131
const MOUSE_DOWN = "mouseButtonDown";
134132
const MOUSE_UP = "mouseButtonUp";
135133
const MOVE_TO = "mouseMoveTo";
136134

137-
// Those allow interactions with the Input Methods installed on
138-
// the system.
135+
// Those allow interactions with the Input Methods installed on the system.
139136
const IME_GET_AVAILABLE_ENGINES = "imeGetAvailableEngines";
140137
const IME_GET_ACTIVE_ENGINE = "imeGetActiveEngine";
141138
const IME_IS_ACTIVATED = "imeIsActivated";
@@ -168,4 +165,7 @@ class DriverCommand {
168165
const GET_NETWORK_CONNECTION = "getNetworkConnection";
169166
const SET_NETWORK_CONNECTION = "setNetworkConnection";
170167

168+
private function __construct()
169+
{
170+
}
171171
}

lib/Remote/RemoteWebDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function create(
7474
) {
7575
$url = preg_replace('#/+$#', '', $url);
7676

77-
// Passing DesiredCapabilities as $desired_capabilities is encourged but
77+
// Passing DesiredCapabilities as $desired_capabilities is encouraged but
7878
// array is also accepted for legacy reason.
7979
if ($desired_capabilities instanceof DesiredCapabilities) {
8080
$desired_capabilities = $desired_capabilities->toArray();

lib/Remote/Service/DriverCommandExecutor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ public function __construct(DriverService $service) {
3838

3939
/**
4040
* @param WebDriverCommand $command
41-
* @param array $curl_opts
4241
*
4342
* @return mixed
4443
* @throws WebDriverException
4544
* @throws \Exception
4645
*/
47-
public function execute(WebDriverCommand $command, $curl_opts = array()) {
46+
public function execute(WebDriverCommand $command) {
4847
if ($command->getName() === DriverCommand::NEW_SESSION) {
4948
$this->service->start();
5049
}

lib/Remote/WebDriverBrowserType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* All the browsers supported by selenium
2020
*/
2121
class WebDriverBrowserType {
22-
2322
const FIREFOX = "firefox";
2423
const FIREFOX_2 = "firefox2";
2524
const FIREFOX_3 = "firefox3";
@@ -42,4 +41,8 @@ class WebDriverBrowserType {
4241
const IPHONE = "iphone";
4342
const IPAD = "iPad";
4443
const PHANTOMJS = "phantomjs";
44+
45+
private function __construct()
46+
{
47+
}
4548
}

0 commit comments

Comments
 (0)