| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | require_once 'Test.class.php'; |
|---|
| 4 | require_once 'HTML/FillInForm.class.php'; |
|---|
| 5 | |
|---|
| 6 | plan(5); |
|---|
| 7 | |
|---|
| 8 | $form_in = ' |
|---|
| 9 | <form action=""> |
|---|
| 10 | <input type="text" name="one" value="not disturbed"> |
|---|
| 11 | <input type="text" name="two" value="not disturbed"> |
|---|
| 12 | <input type="text" name="three" value="not disturbed"> |
|---|
| 13 | </form> |
|---|
| 14 | '; |
|---|
| 15 | |
|---|
| 16 | $fdat = array( |
|---|
| 17 | 'two' => "new val 2", |
|---|
| 18 | 'three' => "new val 3", |
|---|
| 19 | ); |
|---|
| 20 | |
|---|
| 21 | $fif = new HTML_FillInForm; |
|---|
| 22 | $output = $fif->fill(array( |
|---|
| 23 | 'scalarref' => $form_in, |
|---|
| 24 | 'fdat' => $fdat, |
|---|
| 25 | 'ignore_fields' => 'one' |
|---|
| 26 | )); |
|---|
| 27 | |
|---|
| 28 | is( |
|---|
| 29 | $output, |
|---|
| 30 | ' |
|---|
| 31 | <form action=""> |
|---|
| 32 | <input type="text" name="one" value="not disturbed"> |
|---|
| 33 | <input type="text" name="two" value="new val 2"> |
|---|
| 34 | <input type="text" name="three" value="new val 3"> |
|---|
| 35 | </form> |
|---|
| 36 | ' |
|---|
| 37 | ); |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | $form_in = ' |
|---|
| 42 | <form action=""> |
|---|
| 43 | <input type="text" name="one" value="not disturbed"> |
|---|
| 44 | <input type="text" name="two" value="not disturbed"> |
|---|
| 45 | </form> |
|---|
| 46 | '; |
|---|
| 47 | |
|---|
| 48 | $fif = new HTML_FillInForm; |
|---|
| 49 | $output = $fif->fill(array( |
|---|
| 50 | 'scalar' => $form_in, |
|---|
| 51 | 'fdat' => $fdat, |
|---|
| 52 | 'ignore_fields' => 'one' |
|---|
| 53 | )); |
|---|
| 54 | |
|---|
| 55 | is( |
|---|
| 56 | $output, |
|---|
| 57 | ' |
|---|
| 58 | <form action=""> |
|---|
| 59 | <input type="text" name="one" value="not disturbed"> |
|---|
| 60 | <input type="text" name="two" value="new val 2"> |
|---|
| 61 | </form> |
|---|
| 62 | ' |
|---|
| 63 | ); |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | $form_in = ' |
|---|
| 68 | <form action=""> |
|---|
| 69 | <input type="text" name="one" value="not disturbed"> |
|---|
| 70 | <input type="text" name="two" value="not disturbed"> |
|---|
| 71 | </form> |
|---|
| 72 | '; |
|---|
| 73 | $html_array = preg_split('/\n/',$form_in); |
|---|
| 74 | |
|---|
| 75 | $fif = new HTML_FillInForm; |
|---|
| 76 | $output = $fif->fill(array( |
|---|
| 77 | 'arrayref' => $html_array, |
|---|
| 78 | 'fdat' => $fdat, |
|---|
| 79 | 'ignore_fields' => 'one' |
|---|
| 80 | )); |
|---|
| 81 | |
|---|
| 82 | is( |
|---|
| 83 | $output, |
|---|
| 84 | '<form action=""><input type="text" name="one" value="not disturbed"><input type="text" name="two" value="new val 2"></form>' |
|---|
| 85 | ); |
|---|
| 86 | |
|---|
| 87 | $output = $fif->fill(array( |
|---|
| 88 | 'array' => $html_array, |
|---|
| 89 | 'fdat' => $fdat, |
|---|
| 90 | 'ignore_fields' => 'one' |
|---|
| 91 | )); |
|---|
| 92 | |
|---|
| 93 | is( |
|---|
| 94 | $output, |
|---|
| 95 | '<form action=""><input type="text" name="one" value="not disturbed"><input type="text" name="two" value="new val 2"></form>' |
|---|
| 96 | ); |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | $output = $fif->fill(array( |
|---|
| 101 | 'file' => 'data/form1.html', |
|---|
| 102 | 'fdat' => $fdat, |
|---|
| 103 | 'ignore_fields' => 'one' |
|---|
| 104 | )); |
|---|
| 105 | |
|---|
| 106 | is( |
|---|
| 107 | $output, |
|---|
| 108 | ' |
|---|
| 109 | <form action=""> |
|---|
| 110 | <input type="text" name="one" value="not disturbed"> |
|---|
| 111 | <input type="text" name="two" value="new val 2"> |
|---|
| 112 | </form> |
|---|
| 113 | ' |
|---|
| 114 | ); |
|---|