forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_tester.php
1541 lines (1424 loc) · 53.4 KB
/
web_tester.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Base include file for SimpleTest.
* @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
/**#@+
* include other SimpleTest class files
*/
require_once(dirname(__FILE__) . '/test_case.php');
require_once(dirname(__FILE__) . '/browser.php');
require_once(dirname(__FILE__) . '/page.php');
require_once(dirname(__FILE__) . '/expectation.php');
/**#@-*/
/**
* Test for an HTML widget value match.
* @package SimpleTest
* @subpackage WebTester
*/
class FieldExpectation extends SimpleExpectation {
var $_value;
/**
* Sets the field value to compare against.
* @param mixed $value Test value to match. Can be an
* expectation for say pattern matching.
* @param string $message Optiona message override. Can use %s as
* a placeholder for the original message.
* @access public
*/
function FieldExpectation($value, $message = '%s') {
$this->SimpleExpectation($message);
if (is_array($value)) {
sort($value);
}
$this->_value = $value;
}
/**
* Tests the expectation. True if it matches
* a string value or an array value in any order.
* @param mixed $compare Comparison value. False for
* an unset field.
* @return boolean True if correct.
* @access public
*/
function test($compare) {
if ($this->_value === false) {
return ($compare === false);
}
if ($this->_isSingle($this->_value)) {
return $this->_testSingle($compare);
}
if (is_array($this->_value)) {
return $this->_testMultiple($compare);
}
return false;
}
/**
* Tests for valid field comparisons with a single option.
* @param mixed $value Value to type check.
* @return boolean True if integer, string or float.
* @access private
*/
function _isSingle($value) {
return is_string($value) || is_integer($value) || is_float($value);
}
/**
* String comparison for simple field with a single option.
* @param mixed $compare String to test against.
* @returns boolean True if matching.
* @access private
*/
function _testSingle($compare) {
if (is_array($compare) && count($compare) == 1) {
$compare = $compare[0];
}
if (! $this->_isSingle($compare)) {
return false;
}
return ($this->_value == $compare);
}
/**
* List comparison for multivalue field.
* @param mixed $compare List in any order to test against.
* @returns boolean True if matching.
* @access private
*/
function _testMultiple($compare) {
if (is_string($compare)) {
$compare = array($compare);
}
if (! is_array($compare)) {
return false;
}
sort($compare);
return ($this->_value === $compare);
}
/**
* Returns a human readable test message.
* @param mixed $compare Comparison value.
* @return string Description of success
* or failure.
* @access public
*/
function testMessage($compare) {
$dumper = &$this->_getDumper();
if (is_array($compare)) {
sort($compare);
}
if ($this->test($compare)) {
return "Field expectation [" . $dumper->describeValue($this->_value) . "]";
} else {
return "Field expectation [" . $dumper->describeValue($this->_value) .
"] fails with [" .
$dumper->describeValue($compare) . "] " .
$dumper->describeDifference($this->_value, $compare);
}
}
}
/**
* Test for a specific HTTP header within a header block.
* @package SimpleTest
* @subpackage WebTester
*/
class HttpHeaderExpectation extends SimpleExpectation {
var $_expected_header;
var $_expected_value;
/**
* Sets the field and value to compare against.
* @param string $header Case insenstive trimmed header name.
* @param mixed $value Optional value to compare. If not
* given then any value will match. If
* an expectation object then that will
* be used instead.
* @param string $message Optiona message override. Can use %s as
* a placeholder for the original message.
*/
function HttpHeaderExpectation($header, $value = false, $message = '%s') {
$this->SimpleExpectation($message);
$this->_expected_header = $this->_normaliseHeader($header);
$this->_expected_value = $value;
}
/**
* Accessor for aggregated object.
* @return mixed Expectation set in constructor.
* @access protected
*/
function _getExpectation() {
return $this->_expected_value;
}
/**
* Removes whitespace at ends and case variations.
* @param string $header Name of header.
* @param string Trimmed and lowecased header
* name.
* @access private
*/
function _normaliseHeader($header) {
return strtolower(trim($header));
}
/**
* Tests the expectation. True if it matches
* a string value or an array value in any order.
* @param mixed $compare Raw header block to search.
* @return boolean True if header present.
* @access public
*/
function test($compare) {
return is_string($this->_findHeader($compare));
}
/**
* Searches the incoming result. Will extract the matching
* line as text.
* @param mixed $compare Raw header block to search.
* @return string Matching header line.
* @access protected
*/
function _findHeader($compare) {
$lines = explode("\r\n", $compare);
foreach ($lines as $line) {
if ($this->_testHeaderLine($line)) {
return $line;
}
}
return false;
}
/**
* Compares a single header line against the expectation.
* @param string $line A single line to compare.
* @return boolean True if matched.
* @access private
*/
function _testHeaderLine($line) {
if (count($parsed = explode(':', $line, 2)) < 2) {
return false;
}
list($header, $value) = $parsed;
if ($this->_normaliseHeader($header) != $this->_expected_header) {
return false;
}
return $this->_testHeaderValue($value, $this->_expected_value);
}
/**
* Tests the value part of the header.
* @param string $value Value to test.
* @param mixed $expected Value to test against.
* @return boolean True if matched.
* @access protected
*/
function _testHeaderValue($value, $expected) {
if ($expected === false) {
return true;
}
if (SimpleExpectation::isExpectation($expected)) {
return $expected->test(trim($value));
}
return (trim($value) == trim($expected));
}
/**
* Returns a human readable test message.
* @param mixed $compare Raw header block to search.
* @return string Description of success
* or failure.
* @access public
*/
function testMessage($compare) {
if (SimpleExpectation::isExpectation($this->_expected_value)) {
$message = $this->_expected_value->overlayMessage($compare, $this->_getDumper());
} else {
$message = $this->_expected_header .
($this->_expected_value ? ': ' . $this->_expected_value : '');
}
if (is_string($line = $this->_findHeader($compare))) {
return "Searching for header [$message] found [$line]";
} else {
return "Failed to find header [$message]";
}
}
}
/**
* Test for a specific HTTP header within a header block that
* should not be found.
* @package SimpleTest
* @subpackage WebTester
*/
class NoHttpHeaderExpectation extends HttpHeaderExpectation {
var $_expected_header;
var $_expected_value;
/**
* Sets the field and value to compare against.
* @param string $unwanted Case insenstive trimmed header name.
* @param string $message Optiona message override. Can use %s as
* a placeholder for the original message.
*/
function NoHttpHeaderExpectation($unwanted, $message = '%s') {
$this->HttpHeaderExpectation($unwanted, false, $message);
}
/**
* Tests that the unwanted header is not found.
* @param mixed $compare Raw header block to search.
* @return boolean True if header present.
* @access public
*/
function test($compare) {
return ($this->_findHeader($compare) === false);
}
/**
* Returns a human readable test message.
* @param mixed $compare Raw header block to search.
* @return string Description of success
* or failure.
* @access public
*/
function testMessage($compare) {
$expectation = $this->_getExpectation();
if (is_string($line = $this->_findHeader($compare))) {
return "Found unwanted header [$expectation] with [$line]";
} else {
return "Did not find unwanted header [$expectation]";
}
}
}
/**
* Test for a text substring.
* @package SimpleTest
* @subpackage UnitTester
*/
class TextExpectation extends SimpleExpectation {
var $_substring;
/**
* Sets the value to compare against.
* @param string $substring Text to search for.
* @param string $message Customised message on failure.
* @access public
*/
function TextExpectation($substring, $message = '%s') {
$this->SimpleExpectation($message);
$this->_substring = $substring;
}
/**
* Accessor for the substring.
* @return string Text to match.
* @access protected
*/
function _getSubstring() {
return $this->_substring;
}
/**
* Tests the expectation. True if the text contains the
* substring.
* @param string $compare Comparison value.
* @return boolean True if correct.
* @access public
*/
function test($compare) {
return (strpos($compare, $this->_substring) !== false);
}
/**
* Returns a human readable test message.
* @param mixed $compare Comparison value.
* @return string Description of success
* or failure.
* @access public
*/
function testMessage($compare) {
if ($this->test($compare)) {
return $this->_describeTextMatch($this->_getSubstring(), $compare);
} else {
$dumper = &$this->_getDumper();
return "Text [" . $this->_getSubstring() .
"] not detected in [" .
$dumper->describeValue($compare) . "]";
}
}
/**
* Describes a pattern match including the string
* found and it's position.
* @param string $substring Text to search for.
* @param string $subject Subject to search.
* @access protected
*/
function _describeTextMatch($substring, $subject) {
$position = strpos($subject, $substring);
$dumper = &$this->_getDumper();
return "Text [$substring] detected at character [$position] in [" .
$dumper->describeValue($subject) . "] in region [" .
$dumper->clipString($subject, 100, $position) . "]";
}
}
/**
* Fail if a substring is detected within the
* comparison text.
* @package SimpleTest
* @subpackage UnitTester
*/
class NoTextExpectation extends TextExpectation {
/**
* Sets the reject pattern
* @param string $substring Text to search for.
* @param string $message Customised message on failure.
* @access public
*/
function NoTextExpectation($substring, $message = '%s') {
$this->TextExpectation($substring, $message);
}
/**
* Tests the expectation. False if the substring appears
* in the text.
* @param string $compare Comparison value.
* @return boolean True if correct.
* @access public
*/
function test($compare) {
return ! parent::test($compare);
}
/**
* Returns a human readable test message.
* @param string $compare Comparison value.
* @return string Description of success
* or failure.
* @access public
*/
function testMessage($compare) {
if ($this->test($compare)) {
$dumper = &$this->_getDumper();
return "Text [" . $this->_getSubstring() .
"] not detected in [" .
$dumper->describeValue($compare) . "]";
} else {
return $this->_describeTextMatch($this->_getSubstring(), $compare);
}
}
}
/**
* Test case for testing of web pages. Allows
* fetching of pages, parsing of HTML and
* submitting forms.
* @package SimpleTest
* @subpackage WebTester
*/
class WebTestCase extends SimpleTestCase {
var $_browser;
var $_ignore_errors = false;
/**
* Creates an empty test case. Should be subclassed
* with test methods for a functional test case.
* @param string $label Name of test case. Will use
* the class name if none specified.
* @access public
*/
function WebTestCase($label = false) {
$this->SimpleTestCase($label);
}
/**
* Announces the start of the test.
* @param string $method Test method just started.
* @access public
*/
function before($method) {
parent::before($method);
$this->setBrowser($this->createBrowser());
}
/**
* Announces the end of the test. Includes private clean up.
* @param string $method Test method just finished.
* @access public
*/
function after($method) {
$this->unsetBrowser();
parent::after($method);
}
/**
* Gets a current browser reference for setting
* special expectations or for detailed
* examination of page fetches.
* @return SimpleBrowser Current test browser object.
* @access public
*/
function &getBrowser() {
return $this->_browser;
}
/**
* Gets a current browser reference for setting
* special expectations or for detailed
* examination of page fetches.
* @param SimpleBrowser $browser New test browser object.
* @access public
*/
function setBrowser(&$browser) {
return $this->_browser = &$browser;
}
/**
* Clears the current browser reference to help the
* PHP garbage collector.
* @access public
*/
function unsetBrowser() {
unset($this->_browser);
}
/**
* Creates a new default web browser object.
* Will be cleared at the end of the test method.
* @return TestBrowser New browser.
* @access public
*/
function &createBrowser() {
$browser = new SimpleBrowser();
return $browser;
}
/**
* Gets the last response error.
* @return string Last low level HTTP error.
* @access public
*/
function getTransportError() {
return $this->_browser->getTransportError();
}
/**
* Accessor for the currently selected URL.
* @return string Current location or false if
* no page yet fetched.
* @access public
*/
function getUrl() {
return $this->_browser->getUrl();
}
/**
* Dumps the current request for debugging.
* @access public
*/
function showRequest() {
$this->dump($this->_browser->getRequest());
}
/**
* Dumps the current HTTP headers for debugging.
* @access public
*/
function showHeaders() {
$this->dump($this->_browser->getHeaders());
}
/**
* Dumps the current HTML source for debugging.
* @access public
*/
function showSource() {
$this->dump($this->_browser->getContent());
}
/**
* Dumps the visible text only for debugging.
* @access public
*/
function showText() {
$this->dump(wordwrap($this->_browser->getContentAsText(), 80));
}
/**
* Simulates the closing and reopening of the browser.
* Temporary cookies will be discarded and timed
* cookies will be expired if later than the
* specified time.
* @param string/integer $date Time when session restarted.
* If ommitted then all persistent
* cookies are kept. Time is either
* Cookie format string or timestamp.
* @access public
*/
function restart($date = false) {
if ($date === false) {
$date = time();
}
$this->_browser->restart($date);
}
/**
* Moves cookie expiry times back into the past.
* Useful for testing timeouts and expiries.
* @param integer $interval Amount to age in seconds.
* @access public
*/
function ageCookies($interval) {
$this->_browser->ageCookies($interval);
}
/**
* Disables frames support. Frames will not be fetched
* and the frameset page will be used instead.
* @access public
*/
function ignoreFrames() {
$this->_browser->ignoreFrames();
}
/**
* Switches off cookie sending and recieving.
* @access public
*/
function ignoreCookies() {
$this->_browser->ignoreCookies();
}
/**
* Skips errors for the next request only. You might
* want to confirm that a page is unreachable for
* example.
* @access public
*/
function ignoreErrors() {
$this->_ignore_errors = true;
}
/**
* Issues a fail if there is a transport error anywhere
* in the current frameset. Only one such error is
* reported.
* @param string/boolean $result HTML or failure.
* @return string/boolean $result Passes through result.
* @access private
*/
function _failOnError($result) {
if (! $this->_ignore_errors) {
if ($error = $this->_browser->getTransportError()) {
$this->fail($error);
}
}
$this->_ignore_errors = false;
return $result;
}
/**
* Adds a header to every fetch.
* @param string $header Header line to add to every
* request until cleared.
* @access public
*/
function addHeader($header) {
$this->_browser->addHeader($header);
}
/**
* Sets the maximum number of redirects before
* the web page is loaded regardless.
* @param integer $max Maximum hops.
* @access public
*/
function setMaximumRedirects($max) {
if (! $this->_browser) {
trigger_error(
'Can only set maximum redirects in a test method, setUp() or tearDown()');
}
$this->_browser->setMaximumRedirects($max);
}
/**
* Sets the socket timeout for opening a connection and
* receiving at least one byte of information.
* @param integer $timeout Maximum time in seconds.
* @access public
*/
function setConnectionTimeout($timeout) {
$this->_browser->setConnectionTimeout($timeout);
}
/**
* Sets proxy to use on all requests for when
* testing from behind a firewall. Set URL
* to false to disable.
* @param string $proxy Proxy URL.
* @param string $username Proxy username for authentication.
* @param string $password Proxy password for authentication.
* @access public
*/
function useProxy($proxy, $username = false, $password = false) {
$this->_browser->useProxy($proxy, $username, $password);
}
/**
* Fetches a page into the page buffer. If
* there is no base for the URL then the
* current base URL is used. After the fetch
* the base URL reflects the new location.
* @param string $url URL to fetch.
* @param hash $parameters Optional additional GET data.
* @return boolean/string Raw page on success.
* @access public
*/
function get($url, $parameters = false) {
return $this->_failOnError($this->_browser->get($url, $parameters));
}
/**
* Fetches a page by POST into the page buffer.
* If there is no base for the URL then the
* current base URL is used. After the fetch
* the base URL reflects the new location.
* @param string $url URL to fetch.
* @param hash $parameters Optional additional GET data.
* @return boolean/string Raw page on success.
* @access public
*/
function post($url, $parameters = false) {
return $this->_failOnError($this->_browser->post($url, $parameters));
}
/**
* Does a HTTP HEAD fetch, fetching only the page
* headers. The current base URL is unchanged by this.
* @param string $url URL to fetch.
* @param hash $parameters Optional additional GET data.
* @return boolean True on success.
* @access public
*/
function head($url, $parameters = false) {
return $this->_failOnError($this->_browser->head($url, $parameters));
}
/**
* Equivalent to hitting the retry button on the
* browser. Will attempt to repeat the page fetch.
* @return boolean True if fetch succeeded.
* @access public
*/
function retry() {
return $this->_failOnError($this->_browser->retry());
}
/**
* Equivalent to hitting the back button on the
* browser.
* @return boolean True if history entry and
* fetch succeeded.
* @access public
*/
function back() {
return $this->_failOnError($this->_browser->back());
}
/**
* Equivalent to hitting the forward button on the
* browser.
* @return boolean True if history entry and
* fetch succeeded.
* @access public
*/
function forward() {
return $this->_failOnError($this->_browser->forward());
}
/**
* Retries a request after setting the authentication
* for the current realm.
* @param string $username Username for realm.
* @param string $password Password for realm.
* @return boolean/string HTML on successful fetch. Note
* that authentication may still have
* failed.
* @access public
*/
function authenticate($username, $password) {
return $this->_failOnError(
$this->_browser->authenticate($username, $password));
}
/**
* Gets the cookie value for the current browser context.
* @param string $name Name of cookie.
* @return string Value of cookie or false if unset.
* @access public
*/
function getCookie($name) {
return $this->_browser->getCurrentCookieValue($name);
}
/**
* Sets a cookie in the current browser.
* @param string $name Name of cookie.
* @param string $value Cookie value.
* @param string $host Host upon which the cookie is valid.
* @param string $path Cookie path if not host wide.
* @param string $expiry Expiry date.
* @access public
*/
function setCookie($name, $value, $host = false, $path = '/', $expiry = false) {
$this->_browser->setCookie($name, $value, $host, $path, $expiry);
}
/**
* Accessor for current frame focus. Will be
* false if no frame has focus.
* @return integer/string/boolean Label if any, otherwise
* the position in the frameset
* or false if none.
* @access public
*/
function getFrameFocus() {
return $this->_browser->getFrameFocus();
}
/**
* Sets the focus by index. The integer index starts from 1.
* @param integer $choice Chosen frame.
* @return boolean True if frame exists.
* @access public
*/
function setFrameFocusByIndex($choice) {
return $this->_browser->setFrameFocusByIndex($choice);
}
/**
* Sets the focus by name.
* @param string $name Chosen frame.
* @return boolean True if frame exists.
* @access public
*/
function setFrameFocus($name) {
return $this->_browser->setFrameFocus($name);
}
/**
* Clears the frame focus. All frames will be searched
* for content.
* @access public
*/
function clearFrameFocus() {
return $this->_browser->clearFrameFocus();
}
/**
* Clicks a visible text item. Will first try buttons,
* then links and then images.
* @param string $label Visible text or alt text.
* @return string/boolean Raw page or false.
* @access public
*/
function click($label) {
return $this->_failOnError($this->_browser->click($label));
}
/**
* Checks for a click target.
* @param string $label Visible text or alt text.
* @return boolean True if click target.
* @access public
*/
function assertClickable($label, $message = '%s') {
return $this->assertTrue(
$this->_browser->isClickable($label),
sprintf($message, "Click target [$label] should exist"));
}
/**
* Clicks the submit button by label. The owning
* form will be submitted by this.
* @param string $label Button label. An unlabeled
* button can be triggered by 'Submit'.
* @param hash $additional Additional form values.
* @return boolean/string Page on success, else false.
* @access public
*/
function clickSubmit($label = 'Submit', $additional = false) {
return $this->_failOnError(
$this->_browser->clickSubmit($label, $additional));
}
/**
* Clicks the submit button by name attribute. The owning
* form will be submitted by this.
* @param string $name Name attribute of button.
* @param hash $additional Additional form values.
* @return boolean/string Page on success.
* @access public
*/
function clickSubmitByName($name, $additional = false) {
return $this->_failOnError(
$this->_browser->clickSubmitByName($name, $additional));
}
/**
* Clicks the submit button by ID attribute. The owning
* form will be submitted by this.
* @param string $id ID attribute of button.
* @param hash $additional Additional form values.
* @return boolean/string Page on success.
* @access public
*/
function clickSubmitById($id, $additional = false) {
return $this->_failOnError(
$this->_browser->clickSubmitById($id, $additional));
}
/**
* Checks for a valid button label.
* @param string $label Visible text.
* @return boolean True if click target.
* @access public
*/
function assertSubmit($label, $message = '%s') {
return $this->assertTrue(
$this->_browser->isSubmit($label),
sprintf($message, "Submit button [$label] should exist"));
}
/**
* Clicks the submit image by some kind of label. Usually
* the alt tag or the nearest equivalent. The owning
* form will be submitted by this. Clicking outside of
* the boundary of the coordinates will result in
* a failure.
* @param string $label Alt attribute of button.
* @param integer $x X-coordinate of imaginary click.
* @param integer $y Y-coordinate of imaginary click.
* @param hash $additional Additional form values.
* @return boolean/string Page on success.
* @access public
*/
function clickImage($label, $x = 1, $y = 1, $additional = false) {
return $this->_failOnError(
$this->_browser->clickImage($label, $x, $y, $additional));
}
/**
* Clicks the submit image by the name. Usually
* the alt tag or the nearest equivalent. The owning
* form will be submitted by this. Clicking outside of
* the boundary of the coordinates will result in
* a failure.
* @param string $name Name attribute of button.
* @param integer $x X-coordinate of imaginary click.
* @param integer $y Y-coordinate of imaginary click.
* @param hash $additional Additional form values.
* @return boolean/string Page on success.
* @access public
*/
function clickImageByName($name, $x = 1, $y = 1, $additional = false) {
return $this->_failOnError(
$this->_browser->clickImageByName($name, $x, $y, $additional));
}
/**
* Clicks the submit image by ID attribute. The owning
* form will be submitted by this. Clicking outside of
* the boundary of the coordinates will result in
* a failure.
* @param integer/string $id ID attribute of button.
* @param integer $x X-coordinate of imaginary click.
* @param integer $y Y-coordinate of imaginary click.
* @param hash $additional Additional form values.
* @return boolean/string Page on success.
* @access public
*/
function clickImageById($id, $x = 1, $y = 1, $additional = false) {
return $this->_failOnError(
$this->_browser->clickImageById($id, $x, $y, $additional));
}
/**
* Checks for a valid image with atht alt text or title.
* @param string $label Visible text.
* @return boolean True if click target.
* @access public
*/
function assertImage($label, $message = '%s') {
return $this->assertTrue(
$this->_browser->isImage($label),
sprintf($message, "Image with text [$label] should exist"));
}
/**
* Submits a form by the ID.
* @param string $id Form ID. No button information
* is submitted this way.
* @return boolean/string Page on success.
* @access public
*/
function submitFormById($id) {
return $this->_failOnError($this->_browser->submitFormById($id));
}
/**
* Follows a link by name. Will click the first link
* found with this link text by default, or a later
* one if an index is given. Match is case insensitive
* with normalised space.
* @param string $label Text between the anchor tags.
* @param integer $index Link position counting from zero.
* @return boolean/string Page on success.
* @access public
*/
function clickLink($label, $index = 0) {
return $this->_failOnError($this->_browser->clickLink($label, $index));
}
/**
* Follows a link by id attribute.
* @param string $id ID attribute value.
* @return boolean/string Page on success.