PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/php/PHPUnit/Extensions/SeleniumTestCase.php

https://github.com/yeco/lz77-kit
PHP | 1781 lines | 953 code | 192 blank | 636 comment | 108 complexity | 48356c7d51e0de43518306e7bcdd2189 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * PHPUnit
  4. *
  5. * Copyright (c) 2002-2008, Sebastian Bergmann <sb@sebastian-bergmann.de>.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * Neither the name of Sebastian Bergmann nor the names of his
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * @category Testing
  38. * @package PHPUnit
  39. * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
  40. * @copyright 2002-2008 Sebastian Bergmann <sb@sebastian-bergmann.de>
  41. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  42. * @version SVN: $Id: SeleniumTestCase.php 3165 2008-06-08 12:23:59Z sb $
  43. * @link http://www.phpunit.de/
  44. * @since File available since Release 3.0.0
  45. */
  46. require_once 'PHPUnit/Framework.php';
  47. require_once 'PHPUnit/Util/Log/Database.php';
  48. require_once 'PHPUnit/Util/Filter.php';
  49. require_once 'PHPUnit/Util/Test.php';
  50. require_once 'PHPUnit/Util/XML.php';
  51. PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
  52. /**
  53. * TestCase class that uses Selenium to provide
  54. * the functionality required for web testing.
  55. *
  56. * @category Testing
  57. * @package PHPUnit
  58. * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
  59. * @copyright 2002-2008 Sebastian Bergmann <sb@sebastian-bergmann.de>
  60. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  61. * @version Release: 3.2.21
  62. * @link http://www.phpunit.de/
  63. * @since Class available since Release 3.0.0
  64. */
  65. abstract class PHPUnit_Extensions_SeleniumTestCase extends PHPUnit_Framework_TestCase
  66. {
  67. /**
  68. * @var array
  69. */
  70. public static $browsers = array();
  71. /**
  72. * @var string
  73. */
  74. protected $browser;
  75. /**
  76. * @var string
  77. */
  78. protected $browserName;
  79. /**
  80. * @var string
  81. */
  82. protected $browserUrl;
  83. /**
  84. * @var string
  85. */
  86. protected $host = 'localhost';
  87. /**
  88. * @var integer
  89. */
  90. protected $port = 4444;
  91. /**
  92. * @var integer
  93. */
  94. protected $timeout = 30000;
  95. /**
  96. * @var array
  97. */
  98. protected static $sessionId = array();
  99. /**
  100. * @var integer
  101. */
  102. protected $sleep = 0;
  103. /**
  104. * @var boolean
  105. */
  106. protected $autoStop = TRUE;
  107. /**
  108. * @var boolean
  109. */
  110. protected $collectCodeCoverageInformation = FALSE;
  111. /**
  112. * @var string
  113. */
  114. protected $coverageScriptUrl = '';
  115. /**
  116. * @var string
  117. */
  118. protected $testId;
  119. /**
  120. * @var boolean
  121. */
  122. protected $inDefaultAssertions = FALSE;
  123. /**
  124. * @var boolean
  125. */
  126. protected $useWaitForPageToLoad = TRUE;
  127. /**
  128. * @var boolean
  129. */
  130. protected $wait = 5;
  131. /**
  132. * @param string $name
  133. * @param array $browser
  134. * @throws InvalidArgumentException
  135. */
  136. public function __construct($name = NULL, array $data = array(), array $browser = array())
  137. {
  138. parent::__construct($name, $data);
  139. if (isset($browser['name'])) {
  140. if (!is_string($browser['name'])) {
  141. throw new InvalidArgumentException;
  142. }
  143. } else {
  144. $browser['name'] = '';
  145. }
  146. if (isset($browser['browser'])) {
  147. if (!is_string($browser['browser'])) {
  148. throw new InvalidArgumentException;
  149. }
  150. } else {
  151. $browser['browser'] = '';
  152. }
  153. if (isset($browser['host'])) {
  154. if (!is_string($browser['host'])) {
  155. throw new InvalidArgumentException;
  156. }
  157. } else {
  158. $browser['host'] = 'localhost';
  159. }
  160. if (isset($browser['port'])) {
  161. if (!is_int($browser['port'])) {
  162. throw new InvalidArgumentException;
  163. }
  164. } else {
  165. $browser['port'] = 4444;
  166. }
  167. if (isset($browser['timeout'])) {
  168. if (!is_int($browser['timeout'])) {
  169. throw new InvalidArgumentException;
  170. }
  171. } else {
  172. $browser['timeout'] = 30000;
  173. }
  174. $this->browserName = $browser['name'];
  175. $this->browser = $browser['browser'];
  176. $this->host = $browser['host'];
  177. $this->port = $browser['port'];
  178. $this->timeout = $browser['timeout'];
  179. }
  180. /**
  181. * @param string $className
  182. * @return PHPUnit_Framework_TestSuite
  183. */
  184. public static function suite($className)
  185. {
  186. $suite = new PHPUnit_Framework_TestSuite;
  187. $suite->setName($className);
  188. $class = new ReflectionClass($className);
  189. $classGroups = PHPUnit_Util_Test::getGroups($class);
  190. $staticProperties = $class->getStaticProperties();
  191. // Create tests from Selenese/HTML files.
  192. if (isset($staticProperties['seleneseDirectory']) &&
  193. is_dir($staticProperties['seleneseDirectory'])) {
  194. $files = new PHPUnit_Util_FilterIterator(
  195. new RecursiveIteratorIterator(
  196. new RecursiveDirectoryIterator(
  197. $staticProperties['seleneseDirectory']
  198. )
  199. ),
  200. '.htm'
  201. );
  202. // Create tests from Selenese/HTML files for multiple browsers.
  203. if (!empty($staticProperties['browsers'])) {
  204. foreach ($staticProperties['browsers'] as $browser) {
  205. $browserSuite = new PHPUnit_Framework_TestSuite;
  206. $browserSuite->setName($className . ': ' . $browser['name']);
  207. foreach ($files as $file) {
  208. $browserSuite->addTest(
  209. new $className((string)$file, array(), $browser),
  210. $classGroups
  211. );
  212. }
  213. $suite->addTest($browserSuite);
  214. }
  215. }
  216. // Create tests from Selenese/HTML files for single browser.
  217. else {
  218. foreach ($files as $file) {
  219. $suite->addTest(new $className((string)$file), $classGroups);
  220. }
  221. }
  222. }
  223. // Create tests from test methods for multiple browsers.
  224. if (!empty($staticProperties['browsers'])) {
  225. foreach ($staticProperties['browsers'] as $browser) {
  226. $browserSuite = new PHPUnit_Framework_TestSuite;
  227. $browserSuite->setName($className . ': ' . $browser['name']);
  228. foreach ($class->getMethods() as $method) {
  229. if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
  230. $name = $method->getName();
  231. $data = PHPUnit_Util_Test::getProvidedData($className, $name);
  232. $groups = PHPUnit_Util_Test::getGroups($method, $classGroups);
  233. // Test method with @dataProvider.
  234. if (is_array($data) || $data instanceof Iterator) {
  235. $dataSuite = new PHPUnit_Framework_TestSuite(
  236. $className . '::' . $name
  237. );
  238. foreach ($data as $_data) {
  239. $dataSuite->addTest(
  240. new $className($name, $_data, $browser),
  241. $groups
  242. );
  243. }
  244. $browserSuite->addTest($dataSuite);
  245. }
  246. // Test method without @dataProvider.
  247. else {
  248. $browserSuite->addTest(
  249. new $className($name, array(), $browser), $groups
  250. );
  251. }
  252. }
  253. }
  254. $suite->addTest($browserSuite);
  255. }
  256. }
  257. // Create tests from test methods for single browser.
  258. else {
  259. foreach ($class->getMethods() as $method) {
  260. if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
  261. $name = $method->getName();
  262. $data = PHPUnit_Util_Test::getProvidedData($className, $name);
  263. $groups = PHPUnit_Util_Test::getGroups($method, $classGroups);
  264. // Test method with @dataProvider.
  265. if (is_array($data) || $data instanceof Iterator) {
  266. $dataSuite = new PHPUnit_Framework_TestSuite(
  267. $className . '::' . $name
  268. );
  269. foreach ($data as $_data) {
  270. $dataSuite->addTest(
  271. new $className($name, $_data),
  272. $groups
  273. );
  274. }
  275. $suite->addTest($dataSuite);
  276. }
  277. // Test method without @dataProvider.
  278. else {
  279. $suite->addTest(
  280. new $className($name), $groups
  281. );
  282. }
  283. }
  284. }
  285. }
  286. return $suite;
  287. }
  288. /**
  289. * Runs the test case and collects the results in a TestResult object.
  290. * If no TestResult object is passed a new one will be created.
  291. *
  292. * @param PHPUnit_Framework_TestResult $result
  293. * @return PHPUnit_Framework_TestResult
  294. * @throws InvalidArgumentException
  295. */
  296. public function run(PHPUnit_Framework_TestResult $result = NULL)
  297. {
  298. if ($result === NULL) {
  299. $result = $this->createResult();
  300. }
  301. $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
  302. $result->run($this);
  303. if ($this->collectCodeCoverageInformation) {
  304. $result->appendCodeCoverageInformation(
  305. $this, $this->getCodeCoverage()
  306. );
  307. }
  308. return $result;
  309. }
  310. /**
  311. */
  312. protected function runTest()
  313. {
  314. $this->start();
  315. if (!is_file($this->name)) {
  316. parent::runTest();
  317. } else {
  318. $this->runSelenese($this->name);
  319. }
  320. if ($this->autoStop) {
  321. try {
  322. $this->stop();
  323. }
  324. catch (RuntimeException $e) {
  325. }
  326. }
  327. }
  328. /**
  329. * If you want to override tearDown() make sure to either call stop() or
  330. * parent::tearDown(). Otherwise the Selenium RC session will not be
  331. * closed upon test failure.
  332. *
  333. */
  334. protected function tearDown()
  335. {
  336. if ($this->autoStop) {
  337. try {
  338. $this->stop();
  339. }
  340. catch (RuntimeException $e) {
  341. }
  342. }
  343. }
  344. /**
  345. * Returns a string representation of the test case.
  346. *
  347. * @return string
  348. */
  349. public function toString()
  350. {
  351. $buffer = parent::toString();
  352. if (!empty($this->browserName)) {
  353. $buffer .= ' with browser ' . $this->browserName;
  354. }
  355. return $buffer;
  356. }
  357. /**
  358. * @return string
  359. */
  360. public function start()
  361. {
  362. if (!isset(self::$sessionId[$this->host][$this->port][$this->browser])) {
  363. self::$sessionId[$this->host][$this->port][$this->browser] = $this->getString(
  364. 'getNewBrowserSession',
  365. array($this->browser, $this->browserUrl)
  366. );
  367. $this->doCommand('setTimeout', array($this->timeout));
  368. }
  369. $this->testId = md5(uniqid(rand(), TRUE));
  370. return self::$sessionId[$this->host][$this->port][$this->browser];
  371. }
  372. /**
  373. */
  374. public function stop()
  375. {
  376. if (!isset(self::$sessionId[$this->host][$this->port][$this->browser])) {
  377. return;
  378. }
  379. $this->doCommand('testComplete');
  380. unset(self::$sessionId[$this->host][$this->port][$this->browser]);
  381. }
  382. /**
  383. * @param boolean $autoStop
  384. * @throws InvalidArgumentException
  385. */
  386. public function setAutoStop($autoStop)
  387. {
  388. if (!is_bool($autoStop)) {
  389. throw new InvalidArgumentException;
  390. }
  391. $this->autoStop = $autoStop;
  392. }
  393. /**
  394. * @param string $browser
  395. * @throws InvalidArgumentException
  396. */
  397. public function setBrowser($browser)
  398. {
  399. if (!is_string($browser)) {
  400. throw new InvalidArgumentException;
  401. }
  402. $this->browser = $browser;
  403. }
  404. /**
  405. * @param string $browserUrl
  406. * @throws InvalidArgumentException
  407. */
  408. public function setBrowserUrl($browserUrl)
  409. {
  410. if (!is_string($browserUrl)) {
  411. throw new InvalidArgumentException;
  412. }
  413. $this->browserUrl = $browserUrl;
  414. }
  415. /**
  416. * @param string $host
  417. * @throws InvalidArgumentException
  418. */
  419. public function setHost($host)
  420. {
  421. if (!is_string($host)) {
  422. throw new InvalidArgumentException;
  423. }
  424. $this->host = $host;
  425. }
  426. /**
  427. * @param integer $port
  428. * @throws InvalidArgumentException
  429. */
  430. public function setPort($port)
  431. {
  432. if (!is_int($port)) {
  433. throw new InvalidArgumentException;
  434. }
  435. $this->port = $port;
  436. }
  437. /**
  438. * @param integer $timeout
  439. * @throws InvalidArgumentException
  440. */
  441. public function setTimeout($timeout)
  442. {
  443. if (!is_int($timeout)) {
  444. throw new InvalidArgumentException;
  445. }
  446. $this->timeout = $timeout;
  447. }
  448. /**
  449. * @param integer $seconds
  450. * @throws InvalidArgumentException
  451. */
  452. public function setSleep($seconds)
  453. {
  454. if (!is_int($seconds)) {
  455. throw new InvalidArgumentException;
  456. }
  457. $this->sleep = $seconds;
  458. }
  459. /**
  460. * Sets the number of seconds to sleep() after *AndWait commands
  461. * when setWaitForPageToLoad(FALSE) is used.
  462. *
  463. * @param integer $seconds
  464. * @throws InvalidArgumentException
  465. * @since Method available since Release 3.2.15
  466. */
  467. public function setWait($seconds)
  468. {
  469. if (!is_int($seconds)) {
  470. throw new InvalidArgumentException;
  471. }
  472. $this->wait = $seconds;
  473. }
  474. /**
  475. * Sets whether waitForPageToLoad (TRUE) or sleep() (FALSE)
  476. * is used after *AndWait commands.
  477. *
  478. * @param boolean $flag
  479. * @throws InvalidArgumentException
  480. * @since Method available since Release 3.2.15
  481. */
  482. public function setWaitForPageToLoad($flag)
  483. {
  484. if (!is_bool($flag)) {
  485. throw new InvalidArgumentException;
  486. }
  487. $this->useWaitForPageToLoad = $flag;
  488. }
  489. /**
  490. * Runs a test from a Selenese (HTML) specification.
  491. *
  492. * @param string $filename
  493. */
  494. public function runSelenese($filename)
  495. {
  496. $document = PHPUnit_Util_XML::load($filename, TRUE);
  497. $xpath = new DOMXPath($document);
  498. $rows = $xpath->query('body/table/tbody/tr');
  499. foreach ($rows as $row)
  500. {
  501. $action = NULL;
  502. $arguments = array();
  503. $columns = $xpath->query('td', $row);
  504. foreach ($columns as $column)
  505. {
  506. if ($action === NULL) {
  507. $action = $column->nodeValue;
  508. } else {
  509. $arguments[] = $column->nodeValue;
  510. }
  511. }
  512. if (method_exists($this, $action)) {
  513. call_user_func_array(array($this, $action), $arguments);
  514. } else {
  515. $this->__call($action, $arguments);
  516. }
  517. }
  518. }
  519. /**
  520. * This method implements the Selenium RC protocol.
  521. *
  522. * @param string $command
  523. * @param array $arguments
  524. * @return mixed
  525. * @method unknown addLocationStrategy()
  526. * @method unknown addSelection()
  527. * @method unknown addSelectionAndWait()
  528. * @method unknown allowNativeXpath()
  529. * @method unknown altKeyDown()
  530. * @method unknown altKeyDownAndWait()
  531. * @method unknown altKeyUp()
  532. * @method unknown altKeyUpAndWait()
  533. * @method unknown answerOnNextPrompt()
  534. * @method unknown assignId()
  535. * @method unknown captureScreenshot()
  536. * @method unknown check()
  537. * @method unknown chooseCancelOnNextConfirmation()
  538. * @method unknown click()
  539. * @method unknown clickAndWait()
  540. * @method unknown clickAt()
  541. * @method unknown clickAtAndWait()
  542. * @method unknown close()
  543. * @method unknown controlKeyDown()
  544. * @method unknown controlKeyDownAndWait()
  545. * @method unknown controlKeyUp()
  546. * @method unknown controlKeyUpAndWait()
  547. * @method unknown createCookie()
  548. * @method unknown createCookieAndWait()
  549. * @method unknown deleteCookie()
  550. * @method unknown deleteCookieAndWait()
  551. * @method unknown doubleClick()
  552. * @method unknown doubleClickAndWait()
  553. * @method unknown doubleClickAt()
  554. * @method unknown doubleClickAtAndWait()
  555. * @method unknown dragAndDrop()
  556. * @method unknown dragAndDropAndWait()
  557. * @method unknown dragAndDropToObject()
  558. * @method unknown dragAndDropToObjectAndWait()
  559. * @method unknown dragDrop()
  560. * @method unknown dragDropAndWait()
  561. * @method unknown fireEvent()
  562. * @method unknown fireEventAndWait()
  563. * @method string getAlert()
  564. * @method array getAllButtons()
  565. * @method array getAllFields()
  566. * @method array getAllLinks()
  567. * @method array getAllWindowIds()
  568. * @method array getAllWindowNames()
  569. * @method array getAllWindowTitles()
  570. * @method string getAttribute()
  571. * @method array getAttributeFromAllWindows()
  572. * @method string getBodyText()
  573. * @method string getConfirmation()
  574. * @method string getCookie()
  575. * @method integer getCursorPosition()
  576. * @method integer getElementHeight()
  577. * @method integer getElementIndex()
  578. * @method integer getElementPositionLeft()
  579. * @method integer getElementPositionTop()
  580. * @method integer getElementWidth()
  581. * @method string getEval()
  582. * @method string getExpression()
  583. * @method string getHtmlSource()
  584. * @method string getLocation()
  585. * @method string getLogMessages()
  586. * @method integer getMouseSpeed()
  587. * @method string getPrompt()
  588. * @method array getSelectOptions()
  589. * @method string getSelectedId()
  590. * @method array getSelectedIds()
  591. * @method string getSelectedIndex()
  592. * @method array getSelectedIndexes()
  593. * @method string getSelectedLabel()
  594. * @method array getSelectedLabels()
  595. * @method string getSelectedValue()
  596. * @method array getSelectedValues()
  597. * @method unknown getSpeed()
  598. * @method unknown getSpeedAndWait()
  599. * @method string getTable()
  600. * @method string getText()
  601. * @method string getTitle()
  602. * @method string getValue()
  603. * @method boolean getWhetherThisFrameMatchFrameExpression()
  604. * @method boolean getWhetherThisWindowMatchWindowExpression()
  605. * @method integer getXpathCount()
  606. * @method unknown goBack()
  607. * @method unknown goBackAndWait()
  608. * @method unknown highlight()
  609. * @method unknown highlightAndWait()
  610. * @method boolean isAlertPresent()
  611. * @method boolean isChecked()
  612. * @method boolean isConfirmationPresent()
  613. * @method boolean isEditable()
  614. * @method boolean isElementPresent()
  615. * @method boolean isOrdered()
  616. * @method boolean isPromptPresent()
  617. * @method boolean isSomethingSelected()
  618. * @method boolean isTextPresent()
  619. * @method boolean isVisible()
  620. * @method unknown keyDown()
  621. * @method unknown keyDownAndWait()
  622. * @method unknown keyPress()
  623. * @method unknown keyPressAndWait()
  624. * @method unknown keyUp()
  625. * @method unknown keyUpAndWait()
  626. * @method unknown metaKeyDown()
  627. * @method unknown metaKeyDownAndWait()
  628. * @method unknown metaKeyUp()
  629. * @method unknown metaKeyUpAndWait()
  630. * @method unknown mouseDown()
  631. * @method unknown mouseDownAndWait()
  632. * @method unknown mouseDownAt()
  633. * @method unknown mouseDownAtAndWait()
  634. * @method unknown mouseMove()
  635. * @method unknown mouseMoveAndWait()
  636. * @method unknown mouseMoveAt()
  637. * @method unknown mouseMoveAtAndWait()
  638. * @method unknown mouseOut()
  639. * @method unknown mouseOutAndWait()
  640. * @method unknown mouseOver()
  641. * @method unknown mouseOverAndWait()
  642. * @method unknown mouseUp()
  643. * @method unknown mouseUpAndWait()
  644. * @method unknown mouseUpAt()
  645. * @method unknown mouseUpAtAndWait()
  646. * @method unknown open()
  647. * @method unknown openWindow()
  648. * @method unknown openWindowAndWait()
  649. * @method unknown refresh()
  650. * @method unknown refreshAndWait()
  651. * @method unknown removeAllSelections()
  652. * @method unknown removeAllSelectionsAndWait()
  653. * @method unknown removeSelection()
  654. * @method unknown removeSelectionAndWait()
  655. * @method unknown select()
  656. * @method unknown selectAndWait()
  657. * @method unknown selectFrame()
  658. * @method unknown selectWindow()
  659. * @method unknown setContext()
  660. * @method unknown setCursorPosition()
  661. * @method unknown setCursorPositionAndWait()
  662. * @method unknown setMouseSpeed()
  663. * @method unknown setMouseSpeedAndWait()
  664. * @method unknown setSpeed()
  665. * @method unknown setSpeedAndWait()
  666. * @method unknown shiftKeyDown()
  667. * @method unknown shiftKeyDownAndWait()
  668. * @method unknown shiftKeyUp()
  669. * @method unknown shiftKeyUpAndWait()
  670. * @method unknown submit()
  671. * @method unknown submitAndWait()
  672. * @method unknown type()
  673. * @method unknown typeAndWait()
  674. * @method unknown typeKeys()
  675. * @method unknown typeKeysAndWait()
  676. * @method unknown uncheck()
  677. * @method unknown uncheckAndWait()
  678. * @method unknown waitForCondition()
  679. * @method unknown waitForPageToLoad()
  680. * @method unknown waitForPopUp()
  681. * @method unknown windowFocus()
  682. * @method unknown windowMaximize()
  683. */
  684. public function __call($command, $arguments)
  685. {
  686. $wait = FALSE;
  687. if (substr($command, -7, 7) == 'AndWait') {
  688. $command = substr($command, 0, -7);
  689. $wait = TRUE;
  690. }
  691. switch ($command) {
  692. case 'addLocationStrategy':
  693. case 'addSelection':
  694. case 'allowNativeXpath':
  695. case 'altKeyDown':
  696. case 'altKeyUp':
  697. case 'answerOnNextPrompt':
  698. case 'assignId':
  699. case 'captureScreenshot':
  700. case 'check':
  701. case 'chooseCancelOnNextConfirmation':
  702. case 'click':
  703. case 'clickAt':
  704. case 'close':
  705. case 'controlKeyDown':
  706. case 'controlKeyUp':
  707. case 'createCookie':
  708. case 'deleteCookie':
  709. case 'doubleClick':
  710. case 'doubleClickAt':
  711. case 'dragAndDrop':
  712. case 'dragAndDropToObject':
  713. case 'dragDrop':
  714. case 'fireEvent':
  715. case 'goBack':
  716. case 'highlight':
  717. case 'keyDown':
  718. case 'keyPress':
  719. case 'keyUp':
  720. case 'metaKeyDown':
  721. case 'metaKeyUp':
  722. case 'mouseDown':
  723. case 'mouseDownAt':
  724. case 'mouseMove':
  725. case 'mouseMoveAt':
  726. case 'mouseOut':
  727. case 'mouseOver':
  728. case 'mouseUp':
  729. case 'mouseUpAt':
  730. case 'open':
  731. case 'openWindow':
  732. case 'refresh':
  733. case 'removeAllSelections':
  734. case 'removeSelection':
  735. case 'select':
  736. case 'selectFrame':
  737. case 'selectWindow':
  738. case 'setContext':
  739. case 'setCursorPosition':
  740. case 'setMouseSpeed':
  741. case 'setSpeed':
  742. case 'shiftKeyDown':
  743. case 'shiftKeyUp':
  744. case 'submit':
  745. case 'type':
  746. case 'typeKeys':
  747. case 'uncheck':
  748. case 'windowFocus':
  749. case 'windowMaximize': {
  750. // Pre-Command Actions
  751. switch ($command) {
  752. case 'open':
  753. case 'openWindow': {
  754. if ($this->collectCodeCoverageInformation) {
  755. $this->deleteCookie('PHPUNIT_SELENIUM_TEST_ID', '/');
  756. $this->createCookie(
  757. 'PHPUNIT_SELENIUM_TEST_ID=' . $this->testId,
  758. 'path=/'
  759. );
  760. }
  761. }
  762. break;
  763. }
  764. $this->doCommand($command, $arguments);
  765. // Post-Command Actions
  766. switch ($command) {
  767. case 'addLocationStrategy':
  768. case 'allowNativeXpath':
  769. case 'assignId':
  770. case 'captureScreenshot': {
  771. // intentionally empty
  772. }
  773. break;
  774. default: {
  775. if ($wait) {
  776. if ($this->useWaitForPageToLoad) {
  777. $this->doCommand('waitForPageToLoad', array($this->timeout));
  778. } else {
  779. sleep($this->wait);
  780. }
  781. }
  782. if ($this->sleep > 0) {
  783. sleep($this->sleep);
  784. }
  785. $this->runDefaultAssertions($command);
  786. }
  787. }
  788. }
  789. break;
  790. case 'getWhetherThisFrameMatchFrameExpression':
  791. case 'getWhetherThisWindowMatchWindowExpression':
  792. case 'isAlertPresent':
  793. case 'isChecked':
  794. case 'isConfirmationPresent':
  795. case 'isEditable':
  796. case 'isElementPresent':
  797. case 'isOrdered':
  798. case 'isPromptPresent':
  799. case 'isSomethingSelected':
  800. case 'isTextPresent':
  801. case 'isVisible': {
  802. return $this->getBoolean($command, $arguments);
  803. }
  804. break;
  805. case 'getCursorPosition':
  806. case 'getElementHeight':
  807. case 'getElementIndex':
  808. case 'getElementPositionLeft':
  809. case 'getElementPositionTop':
  810. case 'getElementWidth':
  811. case 'getMouseSpeed':
  812. case 'getSpeed':
  813. case 'getXpathCount': {
  814. $result = $this->getNumber($command, $arguments);
  815. if ($wait) {
  816. $this->doCommand('waitForPageToLoad', array($this->timeout));
  817. }
  818. return $result;
  819. }
  820. break;
  821. case 'getAlert':
  822. case 'getAttribute':
  823. case 'getBodyText':
  824. case 'getConfirmation':
  825. case 'getCookie':
  826. case 'getEval':
  827. case 'getExpression':
  828. case 'getHtmlSource':
  829. case 'getLocation':
  830. case 'getLogMessages':
  831. case 'getPrompt':
  832. case 'getSelectedId':
  833. case 'getSelectedIndex':
  834. case 'getSelectedLabel':
  835. case 'getSelectedValue':
  836. case 'getTable':
  837. case 'getText':
  838. case 'getTitle':
  839. case 'getValue': {
  840. $result = $this->getString($command, $arguments);
  841. if ($wait) {
  842. $this->doCommand('waitForPageToLoad', array($this->timeout));
  843. }
  844. return $result;
  845. }
  846. break;
  847. case 'getAllButtons':
  848. case 'getAllFields':
  849. case 'getAllLinks':
  850. case 'getAllWindowIds':
  851. case 'getAllWindowNames':
  852. case 'getAllWindowTitles':
  853. case 'getAttributeFromAllWindows':
  854. case 'getSelectedIds':
  855. case 'getSelectedIndexes':
  856. case 'getSelectedLabels':
  857. case 'getSelectedValues':
  858. case 'getSelectOptions': {
  859. $result = $this->getStringArray($command, $arguments);
  860. if ($wait) {
  861. $this->doCommand('waitForPageToLoad', array($this->timeout));
  862. }
  863. return $result;
  864. }
  865. break;
  866. case 'waitForCondition':
  867. case 'waitForPopUp': {
  868. if (count($arguments) == 1) {
  869. $arguments[] = $this->timeout;
  870. }
  871. $this->doCommand($command, $arguments);
  872. $this->runDefaultAssertions($command);
  873. }
  874. break;
  875. case 'waitForPageToLoad': {
  876. if (empty($arguments)) {
  877. $arguments[] = $this->timeout;
  878. }
  879. $this->doCommand($command, $arguments);
  880. $this->runDefaultAssertions($command);
  881. }
  882. break;
  883. default: {
  884. $this->stop();
  885. throw new BadMethodCallException(
  886. "Method $command not defined."
  887. );
  888. }
  889. }
  890. }
  891. /**
  892. * Asserts that an alert is present.
  893. *
  894. * @param string $message
  895. */
  896. public function assertAlertPresent($message = 'No alert present.')
  897. {
  898. $this->assertTrue($this->isAlertPresent(), $message);
  899. }
  900. /**
  901. * Asserts that no alert is present.
  902. *
  903. * @param string $message
  904. */
  905. public function assertNoAlertPresent($message = 'Alert present.')
  906. {
  907. $this->assertFalse($this->isAlertPresent(), $message);
  908. }
  909. /**
  910. * Asserts that an option is checked.
  911. *
  912. * @param string $locator
  913. * @param string $message
  914. */
  915. public function assertChecked($locator, $message = '')
  916. {
  917. if ($message == '') {
  918. $message = sprintf(
  919. '"%s" not checked.',
  920. $locator
  921. );
  922. }
  923. $this->assertTrue($this->isChecked($locator), $message);
  924. }
  925. /**
  926. * Asserts that an option is not checked.
  927. *
  928. * @param string $locator
  929. * @param string $message
  930. */
  931. public function assertNotChecked($locator, $message = '')
  932. {
  933. if ($message == '') {
  934. $message = sprintf(
  935. '"%s" checked.',
  936. $locator
  937. );
  938. }
  939. $this->assertFalse($this->isChecked($locator), $message);
  940. }
  941. /**
  942. * Assert that a confirmation is present.
  943. *
  944. * @param string $message
  945. */
  946. public function assertConfirmationPresent($message = 'No confirmation present.')
  947. {
  948. $this->assertTrue($this->isConfirmationPresent(), $message);
  949. }
  950. /**
  951. * Assert that no confirmation is present.
  952. *
  953. * @param string $message
  954. */
  955. public function assertNoConfirmationPresent($message = 'Confirmation present.')
  956. {
  957. $this->assertFalse($this->isConfirmationPresent(), $message);
  958. }
  959. /**
  960. * Asserts that an input field is editable.
  961. *
  962. * @param string $locator
  963. * @param string $message
  964. */
  965. public function assertEditable($locator, $message = '')
  966. {
  967. if ($message == '') {
  968. $message = sprintf(
  969. '"%s" not editable.',
  970. $locator
  971. );
  972. }
  973. $this->assertTrue($this->isEditable($locator), $message);
  974. }
  975. /**
  976. * Asserts that an input field is not editable.
  977. *
  978. * @param string $locator
  979. * @param string $message
  980. */
  981. public function assertNotEditable($locator, $message = '')
  982. {
  983. if ($message == '') {
  984. $message = sprintf(
  985. '"%s" editable.',
  986. $locator
  987. );
  988. }
  989. $this->assertFalse($this->isEditable($locator), $message);
  990. }
  991. /**
  992. * Asserts that an element's value is equal to a given string.
  993. *
  994. * @param string $locator
  995. * @param string $text
  996. * @param string $message
  997. */
  998. public function assertElementValueEquals($locator, $text, $message = '')
  999. {
  1000. $this->assertEquals($text, $this->getValue($locator), $message);
  1001. }
  1002. /**
  1003. * Asserts that an element's value is not equal to a given string.
  1004. *
  1005. * @param string $locator
  1006. * @param string $text
  1007. * @param string $message
  1008. */
  1009. public function assertElementValueNotEquals($locator, $text, $message = '')
  1010. {
  1011. $this->assertNotEquals($text, $this->getValue($locator), $message);
  1012. }
  1013. /**
  1014. * Asserts that an element contains a given string.
  1015. *
  1016. * @param string $locator
  1017. * @param string $text
  1018. * @param string $message
  1019. */
  1020. public function assertElementContainsText($locator, $text, $message = '')
  1021. {
  1022. $this->assertContains($text, $this->getValue($locator), $message);
  1023. }
  1024. /**
  1025. * Asserts that an element does not contain a given string.
  1026. *
  1027. * @param string $locator
  1028. * @param string $text
  1029. * @param string $message
  1030. */
  1031. public function assertElementNotContainsText($locator, $text, $message = '')
  1032. {
  1033. $this->assertNotContains($text, $this->getValue($locator), $message);
  1034. }
  1035. /**
  1036. * Asserts than an element is present.
  1037. *
  1038. * @param string $locator
  1039. * @param string $message
  1040. */
  1041. public function assertElementPresent($locator, $message = '')
  1042. {
  1043. if ($message == '') {
  1044. $message = sprintf(
  1045. 'Element "%s" not present.',
  1046. $locator
  1047. );
  1048. }
  1049. $this->assertTrue($this->isElementPresent($locator), $message);
  1050. }
  1051. /**
  1052. * Asserts than an element is not present.
  1053. *
  1054. * @param string $locator
  1055. * @param string $message
  1056. */
  1057. public function assertElementNotPresent($locator, $message = '')
  1058. {
  1059. if ($message == '') {
  1060. $message = sprintf(
  1061. 'Element "%s" present.',
  1062. $locator
  1063. );
  1064. }
  1065. $this->assertFalse($this->isElementPresent($locator), $message);
  1066. }
  1067. /**
  1068. * Asserts that the location is equal to a specified one.
  1069. *
  1070. * @param string $location
  1071. * @param string $message
  1072. */
  1073. public function assertLocationEquals($location, $message = '')
  1074. {
  1075. $this->assertEquals($location, $this->getLocation(), $message);
  1076. }
  1077. /**
  1078. * Asserts that the location is not equal to a specified one.
  1079. *
  1080. * @param string $location
  1081. * @param string $message
  1082. */
  1083. public function assertLocationNotEquals($location, $message = '')
  1084. {
  1085. $this->assertNotEquals($location, $this->getLocation(), $message);
  1086. }
  1087. /**
  1088. * Asserts than a prompt is present.
  1089. *
  1090. * @param string $message
  1091. */
  1092. public function assertPromptPresent($message = 'No prompt present.')
  1093. {
  1094. $this->assertTrue($this->isPromptPresent(), $message);
  1095. }
  1096. /**
  1097. * Asserts than no prompt is present.
  1098. *
  1099. * @param string $message
  1100. */
  1101. public function assertNoPromptPresent($message = 'Prompt present.')
  1102. {
  1103. $this->assertFalse($this->isPromptPresent(), $message);
  1104. }
  1105. /**
  1106. * Asserts that a select element has a specific option.
  1107. *
  1108. * @param string $selectLocator
  1109. * @param string $option
  1110. * @param string $message
  1111. * @since Method available since Release 3.2.0
  1112. */
  1113. public function assertSelectHasOption($selectLocator, $option, $message = '')
  1114. {
  1115. $this->assertContains($option, $this->getSelectOptions($selectLocator), $message);
  1116. }
  1117. /**
  1118. * Asserts that a select element does not have a specific option.
  1119. *
  1120. * @param string $selectLocator
  1121. * @param string $option
  1122. * @param string $message
  1123. * @since Method available since Release 3.2.0
  1124. */
  1125. public function assertSelectNotHasOption($selectLocator, $option, $message = '')
  1126. {
  1127. $this->assertNotContains($option, $this->getSelectOptions($selectLocator), $message);
  1128. }
  1129. /**
  1130. * Asserts that a specific label is selected.
  1131. *
  1132. * @param string $selectLocator
  1133. * @param string $value
  1134. * @param string $message
  1135. * @since Method available since Release 3.2.0
  1136. */
  1137. public function assertSelected($selectLocator, $option, $message = '')
  1138. {
  1139. if ($message == '') {
  1140. $message = sprintf(
  1141. 'Label "%s" not selected in "%s".',
  1142. $option,
  1143. $selectLocator
  1144. );
  1145. }
  1146. $this->assertEquals(
  1147. $option,
  1148. $this->getSelectedLabel($selectLocator),
  1149. $message
  1150. );
  1151. }
  1152. /**
  1153. * Asserts that a specific label is not selected.
  1154. *
  1155. * @param string $selectLocator
  1156. * @param string $value
  1157. * @param string $message
  1158. * @since Method available since Release 3.2.0
  1159. */
  1160. public function assertNotSelected($selectLocator, $option, $message = '')
  1161. {
  1162. if ($message == '') {
  1163. $message = sprintf(
  1164. 'Label "%s" selected in "%s".',
  1165. $option,
  1166. $selectLocator
  1167. );
  1168. }
  1169. $this->assertNotEquals(
  1170. $option,
  1171. $this->getSelectedLabel($selectLocator),
  1172. $message
  1173. );
  1174. }
  1175. /**
  1176. * Asserts that a specific value is selected.
  1177. *
  1178. * @param string $selectLocator
  1179. * @param string $value
  1180. * @param string $message
  1181. */
  1182. public function assertIsSelected($selectLocator, $value, $message = '')
  1183. {
  1184. if ($message == '') {
  1185. $message = sprintf(
  1186. 'Value "%s" not selected in "%s".',
  1187. $value,
  1188. $selectLocator
  1189. );
  1190. }
  1191. $this->assertEquals(
  1192. $value, $this->getSelectedValue($selectLocator),
  1193. $message
  1194. );
  1195. }
  1196. /**
  1197. * Asserts that a specific value is not selected.
  1198. *
  1199. * @param string $selectLocator
  1200. * @param string $value
  1201. * @param string $message
  1202. */
  1203. public function assertIsNotSelected($selectLocator, $value, $message = '')
  1204. {
  1205. if ($message == '') {
  1206. $message = sprintf(
  1207. 'Value "%s" selected in "%s".',
  1208. $value,
  1209. $selectLocator
  1210. );
  1211. }
  1212. $this->assertNotEquals(
  1213. $value,
  1214. $this->getSelectedValue($selectLocator),
  1215. $message
  1216. );
  1217. }
  1218. /**
  1219. * Asserts that something is selected.
  1220. *
  1221. * @param string $selectLocator
  1222. * @param string $message
  1223. */
  1224. public function assertSomethingSelected($selectLocator, $message = '')
  1225. {
  1226. if ($message == '') {
  1227. $message = sprintf(
  1228. 'Nothing selected from "%s".',
  1229. $selectLocator
  1230. );
  1231. }
  1232. $this->assertTrue($this->isSomethingSelected($selectLocator), $message);
  1233. }
  1234. /**
  1235. * Asserts that nothing is selected.
  1236. *
  1237. * @param string $selectLocator
  1238. * @param string $message
  1239. */
  1240. public function assertNothingSelected($selectLocator, $message = '')
  1241. {
  1242. if ($message == '') {
  1243. $message = sprintf(
  1244. 'Something selected from "%s".',
  1245. $selectLocator
  1246. );
  1247. }
  1248. $this->assertFalse($this->isSomethingSelected($selectLocator), $message);
  1249. }
  1250. /**
  1251. * Asserts that a given text is present.
  1252. *
  1253. * @param string $pattern
  1254. * @param string $message
  1255. */
  1256. public function assertTextPresent($pattern, $message = '')
  1257. {
  1258. if ($message == '') {
  1259. $message = sprintf(
  1260. '"%s" not present.',
  1261. $pattern
  1262. );
  1263. }
  1264. $this->assertTrue($this->isTextPresent($pattern), $message);
  1265. }
  1266. /**
  1267. * Asserts that a given text is not present.
  1268. *
  1269. * @param string $pattern
  1270. * @param string $message
  1271. */
  1272. public function assertTextNotPresent($pattern, $message = '')
  1273. {
  1274. if ($message == '') {
  1275. $message = sprintf(
  1276. '"%s" present.',
  1277. $pattern
  1278. );
  1279. }
  1280. $this->assertFalse($this->isTextPresent($pattern), $message);
  1281. }
  1282. /**
  1283. * Asserts that the title is equal to a given string.
  1284. *
  1285. * @param string $title
  1286. * @param string $message
  1287. */
  1288. public function assertTitleEquals($title, $message = '')
  1289. {
  1290. $this->assertEquals($title, $this->getTitle(), $message);
  1291. }
  1292. /**
  1293. * Asserts that the title is not equal to a given string.
  1294. *
  1295. * @param string $title
  1296. * @param string $message
  1297. */
  1298. public function assertTitleNotEquals($title, $message = '')
  1299. {
  1300. $this->assertNotEquals($title, $this->getTitle(), $message);
  1301. }
  1302. /**
  1303. * Asserts that something is visible.
  1304. *
  1305. * @param string $locator
  1306. * @param string $message
  1307. */
  1308. public function assertVisible($locator, $message = '')
  1309. {
  1310. if ($message == '') {
  1311. $message = sprintf(
  1312. '"%s" not visible.',
  1313. $locator
  1314. );
  1315. }
  1316. $this->assertTrue($this->isVisible($locator), $message);
  1317. }
  1318. /**
  1319. * Asserts that something is not visible.
  1320. *
  1321. * @param string $locator
  1322. * @param string $message
  1323. */
  1324. public function assertNotVisible($locator, $message = '')
  1325. {
  1326. if ($message == '') {
  1327. $message = sprintf(
  1328. '"%s" visible.',
  1329. $locator
  1330. );
  1331. }
  1332. $this->assertFalse($this->isVisible($locator), $message);
  1333. }
  1334. /**
  1335. * Template Method that is called after Selenium actions.
  1336. *
  1337. * @param string $action
  1338. * @since Method available since Release 3.1.0
  1339. */
  1340. protected function defaultAssertions($action)
  1341. {
  1342. }
  1343. /**
  1344. * Send a command to the Selenium RC server.
  1345. *
  1346. * @param string $command
  1347. * @param array $arguments
  1348. * @return string
  1349. * @author Shin Ohno <ganchiku@gmail.com>
  1350. * @author Bjoern Schotte <schotte@mayflower.de>
  1351. * @since Method available since Release 3.1.0
  1352. */
  1353. protected function doCommand($command, array $arguments = array())
  1354. {
  1355. $url = sprintf(
  1356. 'http://%s:%s/selenium-server/driver/?cmd=%s',
  1357. $this->host,
  1358. $this->port,
  1359. urlencode($command)
  1360. );
  1361. for ($i = 0; $i < count($arguments); $i++) {
  1362. $argNum = strval($i + 1);
  1363. $url .= sprintf('&%s=%s', $argNum, urlencode(trim($arguments[$i])));
  1364. }
  1365. if (isset(self::$sessionId[$this->host][$this->port][$this->browser])) {
  1366. $url .= sprintf('&%s=%s', 'sessionId', self::$sessionId[$this->host][$this->port][$this->browser]);
  1367. }
  1368. if (!$handle = @fopen($url, 'r')) {
  1369. throw new RuntimeException(
  1370. 'Could not connect to the Selenium RC server.'
  1371. );
  1372. }
  1373. stream_set_blocking($handle, 1);
  1374. stream_set_timeout($handle, 0, $this->timeout);
  1375. $info = stream_get_meta_data($handle);
  1376. $response = '';
  1377. while ((!feof($handle)) && (!$info['timed_out'])) {
  1378. $response .= fgets($handle, 4096);
  1379. $info = stream_get_meta_data($handle);
  1380. }
  1381. fclose($handle);
  1382. if (!preg_match('/^OK/', $response)) {
  1383. $this->stop();
  1384. throw new RuntimeException(
  1385. 'The response from the Selenium RC server is invalid: ' . $response
  1386. );
  1387. }
  1388. return $response;
  1389. }
  1390. /**
  1391. * Send a command to the Selenium RC server and treat the result
  1392. * as a boolean.
  1393. *
  1394. * @param string $command
  1395. * @param array $arguments
  1396. * @return boolean
  1397. * @author Shin Ohno <ganchiku@gmail.com>
  1398. * @author Bjoern Schotte <schotte@mayflower.de>
  1399. * @since Method available since Release 3.1.0
  1400. */
  1401. protected function getBoolean($command, array $arguments)
  1402. {
  1403. $result = $this->getString($command, $arguments);
  1404. switch ($result) {
  1405. case 'true': return TRUE;
  1406. case 'false': return FALSE;
  1407. default: {
  1408. $this->stop();
  1409. throw new RuntimeException(
  1410. 'Result is neither "true" nor "false": ' . PHPUnit_Util_Type::toString($result, TRUE)
  1411. );
  1412. }
  1413. }
  1414. }
  1415. /**
  1416. * Send a command to the Selenium RC server and treat the result
  1417. * as a number.
  1418. *
  1419. * @param string $command
  1420. * @param array $arguments
  1421. * @return numeric
  1422. * @author Shin Ohno <ganchiku@gmail.com>
  1423. * @author Bjoern Schotte <schotte@mayflower.de>
  1424. * @since Method available since Release 3.1.0
  1425. */
  1426. protected function getNumber($command, array $arguments)
  1427. {
  1428. $result = $this->getString($command, $arguments);
  1429. if (!is_numeric($result)) {
  1430. $this->stop();
  1431. throw new RuntimeException(
  1432. 'Result is not numeric: ' . PHPUnit_Util_Type::toString($result, TRUE)
  1433. );
  1434. }
  1435. return $result;
  1436. }
  1437. /**
  1438. * Send a command to the Selenium RC server and treat the result
  1439. * as a string.
  1440. *
  1441. * @param string $command
  1442. * @param array $arguments
  1443. * @return string
  1444. * @author Shin Ohno <ganchiku@gmail.com>
  1445. * @author Bjoern Schotte <schotte@mayflower.de>
  1446. * @since Method available since Release 3.1.0
  1447. */
  1448. protected function getString($command, array $arguments)
  1449. {
  1450. try {
  1451. $result = $this->doCommand($command, $arguments);
  1452. }
  1453. catch (RuntimeException $e) {
  1454. $this->stop();
  1455. throw $e;
  1456. }
  1457. return (strlen($result) > 3) ? substr($result, 3) : '';
  1458. }
  1459. /**
  1460. * Send a command to the Selenium RC server and treat the result
  1461. * as an array of strings.
  1462. *
  1463. * @param string $command
  1464. * @param array $arguments
  1465. * @return array
  1466. * @author Shin Ohno <ganchiku@gmail.com>
  1467. * @author Bjoern Schotte <schotte@mayflower.de>
  1468. * @since Method available since Release 3.1.0
  1469. */
  1470. protected function getStringArray($command, array $arguments)
  1471. {
  1472. $csv = $this->getString($command, $arguments);
  1473. $token = '';
  1474. $tokens = array();
  1475. $letters = preg_split('//', $csv, -1, PREG_SPLIT_NO_EMPTY);
  1476. $count = count($letters);
  1477. for ($i = 0; $i < $count; $i++) {
  1478. $letter = $letters[$i];
  1479. switch($letter) {
  1480. case '\\': {
  1481. $letter = $letters[++$i];
  1482. $token .= $letter;
  1483. }
  1484. break;
  1485. case ',': {
  1486. $tokens[] = $token;
  1487. $token = '';
  1488. }
  1489. break;
  1490. default: {
  1491. $token .= $letter;
  1492. }
  1493. }
  1494. }
  1495. $tokens[] = $token;
  1496. return $tokens;
  1497. }
  1498. /**
  1499. * @return array
  1500. * @since Method available since Release 3.2.0
  1501. */
  1502. protected function getCodeCoverage()
  1503. {
  1504. if (!empty($this->coverageScriptUrl)) {
  1505. $url = sprintf(
  1506. '%s?PHPUNIT_SELENIUM_TEST_ID=%s',
  1507. $this->coverageScriptUrl,
  1508. $this->testId
  1509. );
  1510. return $this->matchLocalAndRemotePaths(
  1511. unserialize(file_get_contents($url))
  1512. );
  1513. } else {
  1514. return array();
  1515. }
  1516. }
  1517. /**
  1518. * @param array $coverage
  1519. * @return array
  1520. * @author Mattis Stordalen Flister <mattis@xait.no>
  1521. * @since Method available since Release 3.2.9
  1522. */
  1523. protected function matchLocalAndRemotePaths(array $coverage)
  1524. {
  1525. $coverageWithLocalPaths = array();
  1526. foreach ($coverage as $originalRemotePath => $value) {
  1527. $remotePath = $originalRemotePath;
  1528. $separator = $this->findDirectorySeparator($remotePath);
  1529. while (!($localpat

Large files files are truncated, but you can click here to view the full file