web_tester.php 52KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  1. <?php
  2. /**
  3. * Base include file for SimpleTest.
  4. * @package SimpleTest
  5. * @subpackage WebTester
  6. * @version $Id: web_tester.php 1808 2008-09-11 19:18:02Z pp11 $
  7. */
  8. /**#@+
  9. * include other SimpleTest class files
  10. */
  11. require_once(dirname(__FILE__) . '/test_case.php');
  12. require_once(dirname(__FILE__) . '/browser.php');
  13. require_once(dirname(__FILE__) . '/page.php');
  14. require_once(dirname(__FILE__) . '/expectation.php');
  15. /**#@-*/
  16. /**
  17. * Test for an HTML widget value match.
  18. * @package SimpleTest
  19. * @subpackage WebTester
  20. */
  21. class FieldExpectation extends SimpleExpectation {
  22. private $value;
  23. /**
  24. * Sets the field value to compare against.
  25. * @param mixed $value Test value to match. Can be an
  26. * expectation for say pattern matching.
  27. * @param string $message Optiona message override. Can use %s as
  28. * a placeholder for the original message.
  29. * @access public
  30. */
  31. function __construct($value, $message = '%s') {
  32. parent::__construct($message);
  33. if (is_array($value)) {
  34. sort($value);
  35. }
  36. $this->value = $value;
  37. }
  38. /**
  39. * Tests the expectation. True if it matches
  40. * a string value or an array value in any order.
  41. * @param mixed $compare Comparison value. False for
  42. * an unset field.
  43. * @return boolean True if correct.
  44. * @access public
  45. */
  46. function test($compare) {
  47. if ($this->value === false) {
  48. return ($compare === false);
  49. }
  50. if ($this->isSingle($this->value)) {
  51. return $this->testSingle($compare);
  52. }
  53. if (is_array($this->value)) {
  54. return $this->testMultiple($compare);
  55. }
  56. return false;
  57. }
  58. /**
  59. * Tests for valid field comparisons with a single option.
  60. * @param mixed $value Value to type check.
  61. * @return boolean True if integer, string or float.
  62. * @access private
  63. */
  64. protected function isSingle($value) {
  65. return is_string($value) || is_integer($value) || is_float($value);
  66. }
  67. /**
  68. * String comparison for simple field with a single option.
  69. * @param mixed $compare String to test against.
  70. * @returns boolean True if matching.
  71. * @access private
  72. */
  73. protected function testSingle($compare) {
  74. if (is_array($compare) && count($compare) == 1) {
  75. $compare = $compare[0];
  76. }
  77. if (! $this->isSingle($compare)) {
  78. return false;
  79. }
  80. return ($this->value == $compare);
  81. }
  82. /**
  83. * List comparison for multivalue field.
  84. * @param mixed $compare List in any order to test against.
  85. * @returns boolean True if matching.
  86. * @access private
  87. */
  88. protected function testMultiple($compare) {
  89. if (is_string($compare)) {
  90. $compare = array($compare);
  91. }
  92. if (! is_array($compare)) {
  93. return false;
  94. }
  95. sort($compare);
  96. return ($this->value === $compare);
  97. }
  98. /**
  99. * Returns a human readable test message.
  100. * @param mixed $compare Comparison value.
  101. * @return string Description of success
  102. * or failure.
  103. * @access public
  104. */
  105. function testMessage($compare) {
  106. $dumper = $this->getDumper();
  107. if (is_array($compare)) {
  108. sort($compare);
  109. }
  110. if ($this->test($compare)) {
  111. return "Field expectation [" . $dumper->describeValue($this->value) . "]";
  112. } else {
  113. return "Field expectation [" . $dumper->describeValue($this->value) .
  114. "] fails with [" .
  115. $dumper->describeValue($compare) . "] " .
  116. $dumper->describeDifference($this->value, $compare);
  117. }
  118. }
  119. }
  120. /**
  121. * Test for a specific HTTP header within a header block.
  122. * @package SimpleTest
  123. * @subpackage WebTester
  124. */
  125. class HttpHeaderExpectation extends SimpleExpectation {
  126. private $expected_header;
  127. private $expected_value;
  128. /**
  129. * Sets the field and value to compare against.
  130. * @param string $header Case insenstive trimmed header name.
  131. * @param mixed $value Optional value to compare. If not
  132. * given then any value will match. If
  133. * an expectation object then that will
  134. * be used instead.
  135. * @param string $message Optiona message override. Can use %s as
  136. * a placeholder for the original message.
  137. */
  138. function __construct($header, $value = false, $message = '%s') {
  139. parent::__construct($message);
  140. $this->expected_header = $this->normaliseHeader($header);
  141. $this->expected_value = $value;
  142. }
  143. /**
  144. * Accessor for aggregated object.
  145. * @return mixed Expectation set in constructor.
  146. * @access protected
  147. */
  148. protected function getExpectation() {
  149. return $this->expected_value;
  150. }
  151. /**
  152. * Removes whitespace at ends and case variations.
  153. * @param string $header Name of header.
  154. * @param string Trimmed and lowecased header
  155. * name.
  156. * @access private
  157. */
  158. protected function normaliseHeader($header) {
  159. return strtolower(trim($header));
  160. }
  161. /**
  162. * Tests the expectation. True if it matches
  163. * a string value or an array value in any order.
  164. * @param mixed $compare Raw header block to search.
  165. * @return boolean True if header present.
  166. * @access public
  167. */
  168. function test($compare) {
  169. return is_string($this->findHeader($compare));
  170. }
  171. /**
  172. * Searches the incoming result. Will extract the matching
  173. * line as text.
  174. * @param mixed $compare Raw header block to search.
  175. * @return string Matching header line.
  176. * @access protected
  177. */
  178. protected function findHeader($compare) {
  179. $lines = split("\r\n", $compare);
  180. foreach ($lines as $line) {
  181. if ($this->testHeaderLine($line)) {
  182. return $line;
  183. }
  184. }
  185. return false;
  186. }
  187. /**
  188. * Compares a single header line against the expectation.
  189. * @param string $line A single line to compare.
  190. * @return boolean True if matched.
  191. * @access private
  192. */
  193. protected function testHeaderLine($line) {
  194. if (count($parsed = split(':', $line, 2)) < 2) {
  195. return false;
  196. }
  197. list($header, $value) = $parsed;
  198. if ($this->normaliseHeader($header) != $this->expected_header) {
  199. return false;
  200. }
  201. return $this->testHeaderValue($value, $this->expected_value);
  202. }
  203. /**
  204. * Tests the value part of the header.
  205. * @param string $value Value to test.
  206. * @param mixed $expected Value to test against.
  207. * @return boolean True if matched.
  208. * @access protected
  209. */
  210. protected function testHeaderValue($value, $expected) {
  211. if ($expected === false) {
  212. return true;
  213. }
  214. if (SimpleExpectation::isExpectation($expected)) {
  215. return $expected->test(trim($value));
  216. }
  217. return (trim($value) == trim($expected));
  218. }
  219. /**
  220. * Returns a human readable test message.
  221. * @param mixed $compare Raw header block to search.
  222. * @return string Description of success
  223. * or failure.
  224. * @access public
  225. */
  226. function testMessage($compare) {
  227. if (SimpleExpectation::isExpectation($this->expected_value)) {
  228. $message = $this->expected_value->overlayMessage($compare, $this->getDumper());
  229. } else {
  230. $message = $this->expected_header .
  231. ($this->expected_value ? ': ' . $this->expected_value : '');
  232. }
  233. if (is_string($line = $this->findHeader($compare))) {
  234. return "Searching for header [$message] found [$line]";
  235. } else {
  236. return "Failed to find header [$message]";
  237. }
  238. }
  239. }
  240. /**
  241. * Test for a specific HTTP header within a header block that
  242. * should not be found.
  243. * @package SimpleTest
  244. * @subpackage WebTester
  245. */
  246. class NoHttpHeaderExpectation extends HttpHeaderExpectation {
  247. private $expected_header;
  248. private $expected_value;
  249. /**
  250. * Sets the field and value to compare against.
  251. * @param string $unwanted Case insenstive trimmed header name.
  252. * @param string $message Optiona message override. Can use %s as
  253. * a placeholder for the original message.
  254. */
  255. function __construct($unwanted, $message = '%s') {
  256. parent::__construct($unwanted, false, $message);
  257. }
  258. /**
  259. * Tests that the unwanted header is not found.
  260. * @param mixed $compare Raw header block to search.
  261. * @return boolean True if header present.
  262. * @access public
  263. */
  264. function test($compare) {
  265. return ($this->findHeader($compare) === false);
  266. }
  267. /**
  268. * Returns a human readable test message.
  269. * @param mixed $compare Raw header block to search.
  270. * @return string Description of success
  271. * or failure.
  272. * @access public
  273. */
  274. function testMessage($compare) {
  275. $expectation = $this->getExpectation();
  276. if (is_string($line = $this->findHeader($compare))) {
  277. return "Found unwanted header [$expectation] with [$line]";
  278. } else {
  279. return "Did not find unwanted header [$expectation]";
  280. }
  281. }
  282. }
  283. /**
  284. * Test for a text substring.
  285. * @package SimpleTest
  286. * @subpackage UnitTester
  287. */
  288. class TextExpectation extends SimpleExpectation {
  289. private $substring;
  290. /**
  291. * Sets the value to compare against.
  292. * @param string $substring Text to search for.
  293. * @param string $message Customised message on failure.
  294. * @access public
  295. */
  296. function __construct($substring, $message = '%s') {
  297. parent::__construct($message);
  298. $this->substring = $substring;
  299. }
  300. /**
  301. * Accessor for the substring.
  302. * @return string Text to match.
  303. * @access protected
  304. */
  305. protected function getSubstring() {
  306. return $this->substring;
  307. }
  308. /**
  309. * Tests the expectation. True if the text contains the
  310. * substring.
  311. * @param string $compare Comparison value.
  312. * @return boolean True if correct.
  313. * @access public
  314. */
  315. function test($compare) {
  316. return (strpos($compare, $this->substring) !== false);
  317. }
  318. /**
  319. * Returns a human readable test message.
  320. * @param mixed $compare Comparison value.
  321. * @return string Description of success
  322. * or failure.
  323. * @access public
  324. */
  325. function testMessage($compare) {
  326. if ($this->test($compare)) {
  327. return $this->describeTextMatch($this->getSubstring(), $compare);
  328. } else {
  329. $dumper = $this->getDumper();
  330. return "Text [" . $this->getSubstring() .
  331. "] not detected in [" .
  332. $dumper->describeValue($compare) . "]";
  333. }
  334. }
  335. /**
  336. * Describes a pattern match including the string
  337. * found and it's position.
  338. * @param string $substring Text to search for.
  339. * @param string $subject Subject to search.
  340. * @access protected
  341. */
  342. protected function describeTextMatch($substring, $subject) {
  343. $position = strpos($subject, $substring);
  344. $dumper = $this->getDumper();
  345. return "Text [$substring] detected at character [$position] in [" .
  346. $dumper->describeValue($subject) . "] in region [" .
  347. $dumper->clipString($subject, 100, $position) . "]";
  348. }
  349. }
  350. /**
  351. * Fail if a substring is detected within the
  352. * comparison text.
  353. * @package SimpleTest
  354. * @subpackage UnitTester
  355. */
  356. class NoTextExpectation extends TextExpectation {
  357. /**
  358. * Sets the reject pattern
  359. * @param string $substring Text to search for.
  360. * @param string $message Customised message on failure.
  361. * @access public
  362. */
  363. function __construct($substring, $message = '%s') {
  364. parent::__construct($substring, $message);
  365. }
  366. /**
  367. * Tests the expectation. False if the substring appears
  368. * in the text.
  369. * @param string $compare Comparison value.
  370. * @return boolean True if correct.
  371. * @access public
  372. */
  373. function test($compare) {
  374. return ! parent::test($compare);
  375. }
  376. /**
  377. * Returns a human readable test message.
  378. * @param string $compare Comparison value.
  379. * @return string Description of success
  380. * or failure.
  381. * @access public
  382. */
  383. function testMessage($compare) {
  384. if ($this->test($compare)) {
  385. $dumper = $this->getDumper();
  386. return "Text [" . $this->getSubstring() .
  387. "] not detected in [" .
  388. $dumper->describeValue($compare) . "]";
  389. } else {
  390. return $this->describeTextMatch($this->getSubstring(), $compare);
  391. }
  392. }
  393. }
  394. /**
  395. * Test case for testing of web pages. Allows
  396. * fetching of pages, parsing of HTML and
  397. * submitting forms.
  398. * @package SimpleTest
  399. * @subpackage WebTester
  400. */
  401. class WebTestCase extends SimpleTestCase {
  402. private $browser;
  403. private $ignore_errors = false;
  404. /**
  405. * Creates an empty test case. Should be subclassed
  406. * with test methods for a functional test case.
  407. * @param string $label Name of test case. Will use
  408. * the class name if none specified.
  409. * @access public
  410. */
  411. function __construct($label = false) {
  412. parent::__construct($label);
  413. }
  414. /**
  415. * Announces the start of the test.
  416. * @param string $method Test method just started.
  417. * @access public
  418. */
  419. function before($method) {
  420. parent::before($method);
  421. $this->setBrowser($this->createBrowser());
  422. }
  423. /**
  424. * Announces the end of the test. Includes private clean up.
  425. * @param string $method Test method just finished.
  426. * @access public
  427. */
  428. function after($method) {
  429. $this->unsetBrowser();
  430. parent::after($method);
  431. }
  432. /**
  433. * Gets a current browser reference for setting
  434. * special expectations or for detailed
  435. * examination of page fetches.
  436. * @return SimpleBrowser Current test browser object.
  437. * @access public
  438. */
  439. function getBrowser() {
  440. return $this->browser;
  441. }
  442. /**
  443. * Gets a current browser reference for setting
  444. * special expectations or for detailed
  445. * examination of page fetches.
  446. * @param SimpleBrowser $browser New test browser object.
  447. * @access public
  448. */
  449. function setBrowser($browser) {
  450. return $this->browser = $browser;
  451. }
  452. /**
  453. * Clears the current browser reference to help the
  454. * PHP garbage collector.
  455. * @access public
  456. */
  457. function unsetBrowser() {
  458. unset($this->browser);
  459. }
  460. /**
  461. * Creates a new default web browser object.
  462. * Will be cleared at the end of the test method.
  463. * @return TestBrowser New browser.
  464. * @access public
  465. */
  466. function createBrowser() {
  467. return new SimpleBrowser();
  468. }
  469. /**
  470. * Gets the last response error.
  471. * @return string Last low level HTTP error.
  472. * @access public
  473. */
  474. function getTransportError() {
  475. return $this->browser->getTransportError();
  476. }
  477. /**
  478. * Accessor for the currently selected URL.
  479. * @return string Current location or false if
  480. * no page yet fetched.
  481. * @access public
  482. */
  483. function getUrl() {
  484. return $this->browser->getUrl();
  485. }
  486. /**
  487. * Dumps the current request for debugging.
  488. * @access public
  489. */
  490. function showRequest() {
  491. $this->dump($this->browser->getRequest());
  492. }
  493. /**
  494. * Dumps the current HTTP headers for debugging.
  495. * @access public
  496. */
  497. function showHeaders() {
  498. $this->dump($this->browser->getHeaders());
  499. }
  500. /**
  501. * Dumps the current HTML source for debugging.
  502. * @access public
  503. */
  504. function showSource() {
  505. $this->dump($this->browser->getContent());
  506. }
  507. /**
  508. * Dumps the visible text only for debugging.
  509. * @access public
  510. */
  511. function showText() {
  512. $this->dump(wordwrap($this->browser->getContentAsText(), 80));
  513. }
  514. /**
  515. * Simulates the closing and reopening of the browser.
  516. * Temporary cookies will be discarded and timed
  517. * cookies will be expired if later than the
  518. * specified time.
  519. * @param string/integer $date Time when session restarted.
  520. * If ommitted then all persistent
  521. * cookies are kept. Time is either
  522. * Cookie format string or timestamp.
  523. * @access public
  524. */
  525. function restart($date = false) {
  526. if ($date === false) {
  527. $date = time();
  528. }
  529. $this->browser->restart($date);
  530. }
  531. /**
  532. * Moves cookie expiry times back into the past.
  533. * Useful for testing timeouts and expiries.
  534. * @param integer $interval Amount to age in seconds.
  535. * @access public
  536. */
  537. function ageCookies($interval) {
  538. $this->browser->ageCookies($interval);
  539. }
  540. /**
  541. * Disables frames support. Frames will not be fetched
  542. * and the frameset page will be used instead.
  543. * @access public
  544. */
  545. function ignoreFrames() {
  546. $this->browser->ignoreFrames();
  547. }
  548. /**
  549. * Switches off cookie sending and recieving.
  550. * @access public
  551. */
  552. function ignoreCookies() {
  553. $this->browser->ignoreCookies();
  554. }
  555. /**
  556. * Skips errors for the next request only. You might
  557. * want to confirm that a page is unreachable for
  558. * example.
  559. * @access public
  560. */
  561. function ignoreErrors() {
  562. $this->ignore_errors = true;
  563. }
  564. /**
  565. * Issues a fail if there is a transport error anywhere
  566. * in the current frameset. Only one such error is
  567. * reported.
  568. * @param string/boolean $result HTML or failure.
  569. * @return string/boolean $result Passes through result.
  570. * @access private
  571. */
  572. protected function failOnError($result) {
  573. if (! $this->ignore_errors) {
  574. if ($error = $this->browser->getTransportError()) {
  575. $this->fail($error);
  576. }
  577. }
  578. $this->ignore_errors = false;
  579. return $result;
  580. }
  581. /**
  582. * Adds a header to every fetch.
  583. * @param string $header Header line to add to every
  584. * request until cleared.
  585. * @access public
  586. */
  587. function addHeader($header) {
  588. $this->browser->addHeader($header);
  589. }
  590. /**
  591. * Sets the maximum number of redirects before
  592. * the web page is loaded regardless.
  593. * @param integer $max Maximum hops.
  594. * @access public
  595. */
  596. function setMaximumRedirects($max) {
  597. if (! $this->browser) {
  598. trigger_error(
  599. 'Can only set maximum redirects in a test method, setUp() or tearDown()');
  600. }
  601. $this->browser->setMaximumRedirects($max);
  602. }
  603. /**
  604. * Sets the socket timeout for opening a connection and
  605. * receiving at least one byte of information.
  606. * @param integer $timeout Maximum time in seconds.
  607. * @access public
  608. */
  609. function setConnectionTimeout($timeout) {
  610. $this->browser->setConnectionTimeout($timeout);
  611. }
  612. /**
  613. * Sets proxy to use on all requests for when
  614. * testing from behind a firewall. Set URL
  615. * to false to disable.
  616. * @param string $proxy Proxy URL.
  617. * @param string $username Proxy username for authentication.
  618. * @param string $password Proxy password for authentication.
  619. * @access public
  620. */
  621. function useProxy($proxy, $username = false, $password = false) {
  622. $this->browser->useProxy($proxy, $username, $password);
  623. }
  624. /**
  625. * Fetches a page into the page buffer. If
  626. * there is no base for the URL then the
  627. * current base URL is used. After the fetch
  628. * the base URL reflects the new location.
  629. * @param string $url URL to fetch.
  630. * @param hash $parameters Optional additional GET data.
  631. * @return boolean/string Raw page on success.
  632. * @access public
  633. */
  634. function get($url, $parameters = false) {
  635. return $this->failOnError($this->browser->get($url, $parameters));
  636. }
  637. /**
  638. * Fetches a page by POST into the page buffer.
  639. * If there is no base for the URL then the
  640. * current base URL is used. After the fetch
  641. * the base URL reflects the new location.
  642. * @param string $url URL to fetch.
  643. * @param hash $parameters Optional additional GET data.
  644. * @return boolean/string Raw page on success.
  645. * @access public
  646. */
  647. function post($url, $parameters = false) {
  648. return $this->failOnError($this->browser->post($url, $parameters));
  649. }
  650. /**
  651. * Does a HTTP HEAD fetch, fetching only the page
  652. * headers. The current base URL is unchanged by this.
  653. * @param string $url URL to fetch.
  654. * @param hash $parameters Optional additional GET data.
  655. * @return boolean True on success.
  656. * @access public
  657. */
  658. function head($url, $parameters = false) {
  659. return $this->failOnError($this->browser->head($url, $parameters));
  660. }
  661. /**
  662. * Equivalent to hitting the retry button on the
  663. * browser. Will attempt to repeat the page fetch.
  664. * @return boolean True if fetch succeeded.
  665. * @access public
  666. */
  667. function retry() {
  668. return $this->failOnError($this->browser->retry());
  669. }
  670. /**
  671. * Equivalent to hitting the back button on the
  672. * browser.
  673. * @return boolean True if history entry and
  674. * fetch succeeded.
  675. * @access public
  676. */
  677. function back() {
  678. return $this->failOnError($this->browser->back());
  679. }
  680. /**
  681. * Equivalent to hitting the forward button on the
  682. * browser.
  683. * @return boolean True if history entry and
  684. * fetch succeeded.
  685. * @access public
  686. */
  687. function forward() {
  688. return $this->failOnError($this->browser->forward());
  689. }
  690. /**
  691. * Retries a request after setting the authentication
  692. * for the current realm.
  693. * @param string $username Username for realm.
  694. * @param string $password Password for realm.
  695. * @return boolean/string HTML on successful fetch. Note
  696. * that authentication may still have
  697. * failed.
  698. * @access public
  699. */
  700. function authenticate($username, $password) {
  701. return $this->failOnError(
  702. $this->browser->authenticate($username, $password));
  703. }
  704. /**
  705. * Gets the cookie value for the current browser context.
  706. * @param string $name Name of cookie.
  707. * @return string Value of cookie or false if unset.
  708. * @access public
  709. */
  710. function getCookie($name) {
  711. return $this->browser->getCurrentCookieValue($name);
  712. }
  713. /**
  714. * Sets a cookie in the current browser.
  715. * @param string $name Name of cookie.
  716. * @param string $value Cookie value.
  717. * @param string $host Host upon which the cookie is valid.
  718. * @param string $path Cookie path if not host wide.
  719. * @param string $expiry Expiry date.
  720. * @access public
  721. */
  722. function setCookie($name, $value, $host = false, $path = '/', $expiry = false) {
  723. $this->browser->setCookie($name, $value, $host, $path, $expiry);
  724. }
  725. /**
  726. * Accessor for current frame focus. Will be
  727. * false if no frame has focus.
  728. * @return integer/string/boolean Label if any, otherwise
  729. * the position in the frameset
  730. * or false if none.
  731. * @access public
  732. */
  733. function getFrameFocus() {
  734. return $this->browser->getFrameFocus();
  735. }
  736. /**
  737. * Sets the focus by index. The integer index starts from 1.
  738. * @param integer $choice Chosen frame.
  739. * @return boolean True if frame exists.
  740. * @access public
  741. */
  742. function setFrameFocusByIndex($choice) {
  743. return $this->browser->setFrameFocusByIndex($choice);
  744. }
  745. /**
  746. * Sets the focus by name.
  747. * @param string $name Chosen frame.
  748. * @return boolean True if frame exists.
  749. * @access public
  750. */
  751. function setFrameFocus($name) {
  752. return $this->browser->setFrameFocus($name);
  753. }
  754. /**
  755. * Clears the frame focus. All frames will be searched
  756. * for content.
  757. * @access public
  758. */
  759. function clearFrameFocus() {
  760. return $this->browser->clearFrameFocus();
  761. }
  762. /**
  763. * Clicks a visible text item. Will first try buttons,
  764. * then links and then images.
  765. * @param string $label Visible text or alt text.
  766. * @return string/boolean Raw page or false.
  767. * @access public
  768. */
  769. function click($label) {
  770. return $this->failOnError($this->browser->click($label));
  771. }
  772. /**
  773. * Checks for a click target.
  774. * @param string $label Visible text or alt text.
  775. * @return boolean True if click target.
  776. * @access public
  777. */
  778. function assertClickable($label, $message = '%s') {
  779. return $this->assertTrue(
  780. $this->browser->isClickable($label),
  781. sprintf($message, "Click target [$label] should exist"));
  782. }
  783. /**
  784. * Clicks the submit button by label. The owning
  785. * form will be submitted by this.
  786. * @param string $label Button label. An unlabeled
  787. * button can be triggered by 'Submit'.
  788. * @param hash $additional Additional form values.
  789. * @return boolean/string Page on success, else false.
  790. * @access public
  791. */
  792. function clickSubmit($label = 'Submit', $additional = false) {
  793. return $this->failOnError(
  794. $this->browser->clickSubmit($label, $additional));
  795. }
  796. /**
  797. * Clicks the submit button by name attribute. The owning
  798. * form will be submitted by this.
  799. * @param string $name Name attribute of button.
  800. * @param hash $additional Additional form values.
  801. * @return boolean/string Page on success.
  802. * @access public
  803. */
  804. function clickSubmitByName($name, $additional = false) {
  805. return $this->failOnError(
  806. $this->browser->clickSubmitByName($name, $additional));
  807. }
  808. /**
  809. * Clicks the submit button by ID attribute. The owning
  810. * form will be submitted by this.
  811. * @param string $id ID attribute of button.
  812. * @param hash $additional Additional form values.
  813. * @return boolean/string Page on success.
  814. * @access public
  815. */
  816. function clickSubmitById($id, $additional = false) {
  817. return $this->failOnError(
  818. $this->browser->clickSubmitById($id, $additional));
  819. }
  820. /**
  821. * Checks for a valid button label.
  822. * @param string $label Visible text.
  823. * @return boolean True if click target.
  824. * @access public
  825. */
  826. function assertSubmit($label, $message = '%s') {
  827. return $this->assertTrue(
  828. $this->browser->isSubmit($label),
  829. sprintf($message, "Submit button [$label] should exist"));
  830. }
  831. /**
  832. * Clicks the submit image by some kind of label. Usually
  833. * the alt tag or the nearest equivalent. The owning
  834. * form will be submitted by this. Clicking outside of
  835. * the boundary of the coordinates will result in
  836. * a failure.
  837. * @param string $label Alt attribute of button.
  838. * @param integer $x X-coordinate of imaginary click.
  839. * @param integer $y Y-coordinate of imaginary click.
  840. * @param hash $additional Additional form values.
  841. * @return boolean/string Page on success.
  842. * @access public
  843. */
  844. function clickImage($label, $x = 1, $y = 1, $additional = false) {
  845. return $this->failOnError(
  846. $this->browser->clickImage($label, $x, $y, $additional));
  847. }
  848. /**
  849. * Clicks the submit image by the name. Usually
  850. * the alt tag or the nearest equivalent. The owning
  851. * form will be submitted by this. Clicking outside of
  852. * the boundary of the coordinates will result in
  853. * a failure.
  854. * @param string $name Name attribute of button.
  855. * @param integer $x X-coordinate of imaginary click.
  856. * @param integer $y Y-coordinate of imaginary click.
  857. * @param hash $additional Additional form values.
  858. * @return boolean/string Page on success.
  859. * @access public
  860. */
  861. function clickImageByName($name, $x = 1, $y = 1, $additional = false) {
  862. return $this->failOnError(
  863. $this->browser->clickImageByName($name, $x, $y, $additional));
  864. }
  865. /**
  866. * Clicks the submit image by ID attribute. The owning
  867. * form will be submitted by this. Clicking outside of
  868. * the boundary of the coordinates will result in
  869. * a failure.
  870. * @param integer/string $id ID attribute of button.
  871. * @param integer $x X-coordinate of imaginary click.
  872. * @param integer $y Y-coordinate of imaginary click.
  873. * @param hash $additional Additional form values.
  874. * @return boolean/string Page on success.
  875. * @access public
  876. */
  877. function clickImageById($id, $x = 1, $y = 1, $additional = false) {
  878. return $this->failOnError(
  879. $this->browser->clickImageById($id, $x, $y, $additional));
  880. }
  881. /**
  882. * Checks for a valid image with atht alt text or title.
  883. * @param string $label Visible text.
  884. * @return boolean True if click target.
  885. * @access public
  886. */
  887. function assertImage($label, $message = '%s') {
  888. return $this->assertTrue(
  889. $this->browser->isImage($label),
  890. sprintf($message, "Image with text [$label] should exist"));
  891. }
  892. /**
  893. * Submits a form by the ID.
  894. * @param string $id Form ID. No button information
  895. * is submitted this way.
  896. * @return boolean/string Page on success.
  897. * @access public
  898. */
  899. function submitFormById($id) {
  900. return $this->failOnError($this->browser->submitFormById($id));
  901. }
  902. /**
  903. * Follows a link by name. Will click the first link
  904. * found with this link text by default, or a later
  905. * one if an index is given. Match is case insensitive
  906. * with normalised space.
  907. * @param string $label Text between the anchor tags.
  908. * @param integer $index Link position counting from zero.
  909. * @return boolean/string Page on success.
  910. * @access public
  911. */
  912. function clickLink($label, $index = 0) {
  913. return $this->failOnError($this->browser->clickLink($label, $index));
  914. }
  915. /**
  916. * Follows a link by id attribute.
  917. * @param string $id ID attribute value.
  918. * @return boolean/string Page on success.
  919. * @access public
  920. */
  921. function clickLinkById($id) {
  922. return $this->failOnError($this->browser->clickLinkById($id));
  923. }
  924. /**
  925. * Tests for the presence of a link label. Match is
  926. * case insensitive with normalised space.
  927. * @param string $label Text between the anchor tags.
  928. * @param mixed $expected Expected URL or expectation object.
  929. * @param string $message Message to display. Default
  930. * can be embedded with %s.
  931. * @return boolean True if link present.
  932. * @access public
  933. */
  934. function assertLink($label, $expected = true, $message = '%s') {
  935. $url = $this->browser->getLink($label);
  936. if ($expected === true || ($expected !== true && $url === false)) {
  937. return $this->assertTrue($url !== false, sprintf($message, "Link [$label] should exist"));
  938. }
  939. if (! SimpleExpectation::isExpectation($expected)) {
  940. $expected = new IdenticalExpectation($expected);
  941. }
  942. return $this->assert($expected, $url->asString(), sprintf($message, "Link [$label] should match"));
  943. }
  944. /**
  945. * Tests for the non-presence of a link label. Match is
  946. * case insensitive with normalised space.
  947. * @param string/integer $label Text between the anchor tags
  948. * or ID attribute.
  949. * @param string $message Message to display. Default
  950. * can be embedded with %s.
  951. * @return boolean True if link missing.
  952. * @access public
  953. */
  954. function assertNoLink($label, $message = '%s') {
  955. return $this->assertTrue(
  956. $this->browser->getLink($label) === false,
  957. sprintf($message, "Link [$label] should not exist"));
  958. }
  959. /**
  960. * Tests for the presence of a link id attribute.
  961. * @param string $id Id attribute value.
  962. * @param mixed $expected Expected URL or expectation object.
  963. * @param string $message Message to display. Default
  964. * can be embedded with %s.
  965. * @return boolean True if link present.
  966. * @access public
  967. */
  968. function assertLinkById($id, $expected = true, $message = '%s') {
  969. $url = $this->browser->getLinkById($id);
  970. if ($expected === true) {
  971. return $this->assertTrue($url !== false, sprintf($message, "Link ID [$id] should exist"));
  972. }
  973. if (! SimpleExpectation::isExpectation($expected)) {
  974. $expected = new IdenticalExpectation($expected);
  975. }
  976. return $this->assert($expected, $url->asString(), sprintf($message, "Link ID [$id] should match"));
  977. }
  978. /**
  979. * Tests for the non-presence of a link label. Match is
  980. * case insensitive with normalised space.
  981. * @param string $id Id attribute value.
  982. * @param string $message Message to display. Default
  983. * can be embedded with %s.
  984. * @return boolean True if link missing.
  985. * @access public
  986. */
  987. function assertNoLinkById($id, $message = '%s') {
  988. return $this->assertTrue(
  989. $this->browser->getLinkById($id) === false,
  990. sprintf($message, "Link ID [$id] should not exist"));
  991. }
  992. /**
  993. * Sets all form fields with that label, or name if there
  994. * is no label attached.
  995. * @param string $name Name of field in forms.
  996. * @param string $value New value of field.
  997. * @return boolean True if field exists, otherwise false.
  998. * @access public
  999. */
  1000. function setField($label, $value, $position=false) {
  1001. return $this->browser->setField($label, $value, $position);
  1002. }
  1003. /**
  1004. * Sets all form fields with that name.
  1005. * @param string $name Name of field in forms.
  1006. * @param string $value New value of field.
  1007. * @return boolean True if field exists, otherwise false.
  1008. * @access public
  1009. */
  1010. function setFieldByName($name, $value, $position=false) {
  1011. return $this->browser->setFieldByName($name, $value, $position);
  1012. }
  1013. /**
  1014. * Sets all form fields with that id.
  1015. * @param string/integer $id Id of field in forms.
  1016. * @param string $value New value of field.
  1017. * @return boolean True if field exists, otherwise false.
  1018. * @access public
  1019. */
  1020. function setFieldById($id, $value) {
  1021. return $this->browser->setFieldById($id, $value);
  1022. }
  1023. /**
  1024. * Confirms that the form element is currently set
  1025. * to the expected value. A missing form will always
  1026. * fail. If no value is given then only the existence
  1027. * of the field is checked.
  1028. * @param string $name Name of field in forms.
  1029. * @param mixed $expected Expected string/array value or
  1030. * false for unset fields.
  1031. * @param string $message Message to display. Default
  1032. * can be embedded with %s.
  1033. * @return boolean True if pass.
  1034. * @access public
  1035. */
  1036. function assertField($label, $expected = true, $message = '%s') {
  1037. $value = $this->browser->getField($label);
  1038. return $this->assertFieldValue($label, $value, $expected, $message);
  1039. }
  1040. /**
  1041. * Confirms that the form element is currently set
  1042. * to the expected value. A missing form element will always
  1043. * fail. If no value is given then only the existence
  1044. * of the field is checked.
  1045. * @param string $name Name of field in forms.
  1046. * @param mixed $expected Expected string/array value or
  1047. * false for unset fields.
  1048. * @param string $message Message to display. Default
  1049. * can be embedded with %s.
  1050. * @return boolean True if pass.
  1051. * @access public
  1052. */
  1053. function assertFieldByName($name, $expected = true, $message = '%s') {
  1054. $value = $this->browser->getFieldByName($name);
  1055. return $this->assertFieldValue($name, $value, $expected, $message);
  1056. }
  1057. /**
  1058. * Confirms that the form element is currently set
  1059. * to the expected value. A missing form will always
  1060. * fail. If no ID is given then only the existence
  1061. * of the field is checked.
  1062. * @param string/integer $id Name of field in forms.
  1063. * @param mixed $expected Expected string/array value or
  1064. * false for unset fields.
  1065. * @param string $message Message to display. Default
  1066. * can be embedded with %s.
  1067. * @return boolean True if pass.
  1068. * @access public
  1069. */
  1070. function assertFieldById($id, $expected = true, $message = '%s') {
  1071. $value = $this->browser->getFieldById($id);
  1072. return $this->assertFieldValue($id, $value, $expected, $message);
  1073. }
  1074. /**
  1075. * Tests the field value against the expectation.
  1076. * @param string $identifier Name, ID or label.
  1077. * @param mixed $value Current field value.
  1078. * @param mixed $expected Expected value to match.
  1079. * @param string $message Failure message.
  1080. * @return boolean True if pass
  1081. * @access protected
  1082. */
  1083. protected function assertFieldValue($identifier, $value, $expected, $message) {
  1084. if ($expected === true) {
  1085. return $this->assertTrue(
  1086. isset($value),
  1087. sprintf($message, "Field [$identifier] should exist"));
  1088. }
  1089. if (! SimpleExpectation::isExpectation($expected)) {
  1090. $identifier = str_replace('%', '%%', $identifier);
  1091. $expected = new FieldExpectation(
  1092. $expected,
  1093. "Field [$identifier] should match with [%s]");
  1094. }
  1095. return $this->assert($expected, $value, $message);
  1096. }
  1097. /**
  1098. * Checks the response code against a list
  1099. * of possible values.
  1100. * @param array $responses Possible responses for a pass.
  1101. * @param string $message Message to display. Default
  1102. * can be embedded with %s.
  1103. * @return boolean True if pass.
  1104. * @access public
  1105. */
  1106. function assertResponse($responses, $message = '%s') {
  1107. $responses = (is_array($responses) ? $responses : array($responses));
  1108. $code = $this->browser->getResponseCode();
  1109. $message = sprintf($message, "Expecting response in [" .
  1110. implode(", ", $responses) . "] got [$code]");
  1111. return $this->assertTrue(in_array($code, $responses), $message);
  1112. }
  1113. /**
  1114. * Checks the mime type against a list
  1115. * of possible values.
  1116. * @param array $types Possible mime types for a pass.
  1117. * @param string $message Message to display.
  1118. * @return boolean True if pass.
  1119. * @access public
  1120. */
  1121. function assertMime($types, $message = '%s') {
  1122. $types = (is_array($types) ? $types : array($types));
  1123. $type = $this->browser->getMimeType();
  1124. $message = sprintf($message, "Expecting mime type in [" .
  1125. implode(", ", $types) . "] got [$type]");
  1126. return $this->assertTrue(in_array($type, $types), $message);
  1127. }
  1128. /**
  1129. * Attempt to match the authentication type within
  1130. * the security realm we are currently matching.
  1131. * @param string $authentication Usually basic.
  1132. * @param string $message Message to display.
  1133. * @return boolean True if pass.
  1134. * @access public
  1135. */
  1136. function assertAuthentication($authentication = false, $message = '%s') {
  1137. if (! $authentication) {
  1138. $message = sprintf($message, "Expected any authentication type, got [" .
  1139. $this->browser->getAuthentication() . "]");
  1140. return $this->assertTrue(
  1141. $this->browser->getAuthentication(),
  1142. $message);
  1143. } else {
  1144. $message = sprintf($message, "Expected authentication [$authentication] got [" .
  1145. $this->browser->getAuthentication() . "]");
  1146. return $this->assertTrue(
  1147. strtolower($this->browser->getAuthentication()) == strtolower($authentication),
  1148. $message);
  1149. }
  1150. }
  1151. /**
  1152. * Checks that no authentication is necessary to view
  1153. * the desired page.
  1154. * @param string $message Message to display.
  1155. * @return boolean True if pass.
  1156. * @access public
  1157. */
  1158. function assertNoAuthentication($message = '%s') {
  1159. $message = sprintf($message, "Expected no authentication type, got [" .
  1160. $this->browser->getAuthentication() . "]");
  1161. return $this->assertFalse($this->browser->getAuthentication(), $message);
  1162. }
  1163. /**
  1164. * Attempts to match the current security realm.
  1165. * @param string $realm Name of security realm.
  1166. * @param string $message Message to display.
  1167. * @return boolean True if pass.
  1168. * @access public
  1169. */
  1170. function assertRealm($realm, $message = '%s') {
  1171. if (! SimpleExpectation::isExpectation($realm)) {
  1172. $realm = new EqualExpectation($realm);
  1173. }
  1174. return $this->assert(
  1175. $realm,
  1176. $this->browser->getRealm(),
  1177. "Expected realm -> $message");
  1178. }
  1179. /**
  1180. * Checks each header line for the required value. If no
  1181. * value is given then only an existence check is made.
  1182. * @param string $header Case insensitive header name.
  1183. * @param mixed $value Case sensitive trimmed string to
  1184. * match against. An expectation object
  1185. * can be used for pattern matching.
  1186. * @return boolean True if pass.
  1187. * @access public
  1188. */
  1189. function assertHeader($header, $value = false, $message = '%s') {
  1190. return $this->assert(
  1191. new HttpHeaderExpectation($header, $value),
  1192. $this->browser->getHeaders(),
  1193. $message);
  1194. }
  1195. /**
  1196. * Confirms that the header type has not been received.
  1197. * Only the landing page is checked. If you want to check
  1198. * redirect pages, then you should limit redirects so
  1199. * as to capture the page you want.
  1200. * @param string $header Case insensitive header name.
  1201. * @return boolean True if pass.
  1202. * @access public
  1203. */
  1204. function assertNoHeader($header, $message = '%s') {
  1205. return $this->assert(
  1206. new NoHttpHeaderExpectation($header),
  1207. $this->browser->getHeaders(),
  1208. $message);
  1209. }
  1210. /**
  1211. * Tests the text between the title tags.
  1212. * @param string/SimpleExpectation $title Expected title.
  1213. * @param string $message Message to display.
  1214. * @return boolean True if pass.
  1215. * @access public
  1216. */
  1217. function assertTitle($title = false, $message = '%s') {
  1218. if (! SimpleExpectation::isExpectation($title)) {
  1219. $title = new EqualExpectation($title);
  1220. }
  1221. return $this->assert($title, $this->browser->getTitle(), $message);
  1222. }
  1223. /**
  1224. * Will trigger a pass if the text is found in the plain
  1225. * text form of the page.
  1226. * @param string $text Text to look for.
  1227. * @param string $message Message to display.
  1228. * @return boolean True if pass.
  1229. * @access public
  1230. */
  1231. function assertText($text, $message = '%s') {
  1232. return $this->assert(
  1233. new TextExpectation($text),
  1234. $this->browser->getContentAsText(),
  1235. $message);
  1236. }
  1237. /**
  1238. * Will trigger a pass if the text is not found in the plain
  1239. * text form of the page.
  1240. * @param string $text Text to look for.
  1241. * @param string $message Message to display.
  1242. * @return boolean True if pass.
  1243. * @access public
  1244. */
  1245. function assertNoText($text, $message = '%s') {
  1246. return $this->assert(
  1247. new NoTextExpectation($text),
  1248. $this->browser->getContentAsText(),
  1249. $message);
  1250. }
  1251. /**
  1252. * Will trigger a pass if the Perl regex pattern
  1253. * is found in the raw content.
  1254. * @param string $pattern Perl regex to look for including
  1255. * the regex delimiters.
  1256. * @param string $message Message to display.
  1257. * @return boolean True if pass.
  1258. * @access public
  1259. */
  1260. function assertPattern($pattern, $message = '%s') {
  1261. return $this->assert(
  1262. new PatternExpectation($pattern),
  1263. $this->browser->getContent(),
  1264. $message);
  1265. }
  1266. /**
  1267. * Will trigger a pass if the perl regex pattern
  1268. * is not present in raw content.
  1269. * @param string $pattern Perl regex to look for including
  1270. * the regex delimiters.
  1271. * @param string $message Message to display.
  1272. * @return boolean True if pass.
  1273. * @access public
  1274. */
  1275. function assertNoPattern($pattern, $message = '%s') {
  1276. return $this->assert(
  1277. new NoPatternExpectation($pattern),
  1278. $this->browser->getContent(),
  1279. $message);
  1280. }
  1281. /**
  1282. * Checks that a cookie is set for the current page
  1283. * and optionally checks the value.
  1284. * @param string $name Name of cookie to test.
  1285. * @param string $expected Expected value as a string or
  1286. * false if any value will do.
  1287. * @param string $message Message to display.
  1288. * @return boolean True if pass.
  1289. * @access public
  1290. */
  1291. function assertCookie($name, $expected = false, $message = '%s') {
  1292. $value = $this->getCookie($name);
  1293. if (! $expected) {
  1294. return $this->assertTrue(
  1295. $value,
  1296. sprintf($message, "Expecting cookie [$name]"));
  1297. }
  1298. if (! SimpleExpectation::isExpectation($expected)) {
  1299. $expected = new EqualExpectation($expected);
  1300. }
  1301. return $this->assert($expected, $value, "Expecting cookie [$name] -> $message");
  1302. }
  1303. /**
  1304. * Checks that no cookie is present or that it has
  1305. * been successfully cleared.
  1306. * @param string $name Name of cookie to test.
  1307. * @param string $message Message to display.
  1308. * @return boolean True if pass.
  1309. * @access public
  1310. */
  1311. function assertNoCookie($name, $message = '%s') {
  1312. return $this->assertTrue(
  1313. $this->getCookie($name) === null or $this->getCookie($name) === false,
  1314. sprintf($message, "Not expecting cookie [$name]"));
  1315. }
  1316. /**
  1317. * Called from within the test methods to register
  1318. * passes and failures.
  1319. * @param boolean $result Pass on true.
  1320. * @param string $message Message to display describing
  1321. * the test state.
  1322. * @return boolean True on pass
  1323. * @access public
  1324. */
  1325. function assertTrue($result, $message = false) {
  1326. return $this->assert(new TrueExpectation(), $result, $message);
  1327. }
  1328. /**
  1329. * Will be true on false and vice versa. False
  1330. * is the PHP definition of false, so that null,
  1331. * empty strings, zero and an empty array all count
  1332. * as false.
  1333. * @param boolean $result Pass on false.
  1334. * @param string $message Message to display.
  1335. * @return boolean True on pass
  1336. * @access public
  1337. */
  1338. function assertFalse($result, $message = '%s') {
  1339. return $this->assert(new FalseExpectation(), $result, $message);
  1340. }
  1341. /**
  1342. * Will trigger a pass if the two parameters have
  1343. * the same value only. Otherwise a fail. This
  1344. * is for testing hand extracted text, etc.
  1345. * @param mixed $first Value to compare.
  1346. * @param mixed $second Value to compare.
  1347. * @param string $message Message to display.
  1348. * @return boolean True on pass
  1349. * @access public
  1350. */
  1351. function assertEqual($first, $second, $message = '%s') {
  1352. return $this->assert(
  1353. new EqualExpectation($first),
  1354. $second,
  1355. $message);
  1356. }
  1357. /**
  1358. * Will trigger a pass if the two parameters have
  1359. * a different value. Otherwise a fail. This
  1360. * is for testing hand extracted text, etc.
  1361. * @param mixed $first Value to compare.
  1362. * @param mixed $second Value to compare.
  1363. * @param string $message Message to display.
  1364. * @return boolean True on pass
  1365. * @access public
  1366. */
  1367. function assertNotEqual($first, $second, $message = '%s') {
  1368. return $this->assert(
  1369. new NotEqualExpectation($first),
  1370. $second,
  1371. $message);
  1372. }
  1373. /**
  1374. * Uses a stack trace to find the line of an assertion.
  1375. * @return string Line number of first assert*
  1376. * method embedded in format string.
  1377. * @access public
  1378. */
  1379. function getAssertionLine() {
  1380. $trace = new SimpleStackTrace(array('assert', 'click', 'pass', 'fail'));
  1381. return $trace->traceMethod();
  1382. }
  1383. }
  1384. ?>