| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
include(dirname(__FILE__).'/../bootstrap/unit.php'); |
|---|
| 4 |
include(dirname(__FILE__).'/../../plugins/idProjectManagmentPlugin/lib/test/idDoctrineTestBrowser.class.php'); |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
$t = new lime_test(6, new lime_output_color()); |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
$t->diag('->click()'); |
|---|
| 14 |
class myClickBrowser extends idDoctrineTestBrowser |
|---|
| 15 |
{ |
|---|
| 16 |
public function setHtml($html) |
|---|
| 17 |
{ |
|---|
| 18 |
$this->dom = new DomDocument('1.0', 'UTF-8'); |
|---|
| 19 |
$this->dom->validateOnParse = true; |
|---|
| 20 |
$this->dom->loadHTML($html); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
public function getFiles() |
|---|
| 24 |
{ |
|---|
| 25 |
$f = $this->files; |
|---|
| 26 |
$this->files = array(); |
|---|
| 27 |
|
|---|
| 28 |
return $f; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
public function call($uri, $method = 'get', $parameters = array(), $changeStack = true) |
|---|
| 32 |
{ |
|---|
| 33 |
$uri = $this->fixUri($uri); |
|---|
| 34 |
|
|---|
| 35 |
$this->fields = array(); |
|---|
| 36 |
|
|---|
| 37 |
return array($method, $uri, $parameters); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
public function getDefaultServerArray($name) |
|---|
| 41 |
{ |
|---|
| 42 |
return isset($this->defaultServerArray[$name]) ? $this->defaultServerArray[$name] : false; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
$html = <<<EOF |
|---|
| 48 |
<html> |
|---|
| 49 |
<body> |
|---|
| 50 |
<form action="/myform" method="post"> |
|---|
| 51 |
<select name="select"> |
|---|
| 52 |
<option value="first">first</option> |
|---|
| 53 |
<option value="selected" selected="selected">selected</option> |
|---|
| 54 |
<option value="last">last</option> |
|---|
| 55 |
</select> |
|---|
| 56 |
<select name="select_multiple" multiple="multiple"> |
|---|
| 57 |
<option value="first">first</option> |
|---|
| 58 |
<option value="selected" selected="selected">selected</option> |
|---|
| 59 |
<option value="last" selected="selected">last</option> |
|---|
| 60 |
</select> |
|---|
| 61 |
<select name="article[category]" multiple="multiple"> |
|---|
| 62 |
<option value="1">1</option> |
|---|
| 63 |
<option value="2" selected="selected">2</option> |
|---|
| 64 |
<option value="3" selected="selected">3</option> |
|---|
| 65 |
</select> |
|---|
| 66 |
<input type="submit" name="submit" value="submit" /> |
|---|
| 67 |
</form> |
|---|
| 68 |
|
|---|
| 69 |
</body> |
|---|
| 70 |
</html> |
|---|
| 71 |
EOF; |
|---|
| 72 |
|
|---|
| 73 |
$b = new myClickBrowser(); |
|---|
| 74 |
$b->setHtml($html); |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
$t->diag('->deSelectOption()'); |
|---|
| 79 |
list($method, $uri, $parameters) = $b-> |
|---|
| 80 |
deSelectOption('select', 'selected')-> |
|---|
| 81 |
click('submit') |
|---|
| 82 |
; |
|---|
| 83 |
$t->ok( $parameters['select'] == 'first', '->deSelectOption() deselect the specified option'); |
|---|
| 84 |
|
|---|
| 85 |
$t->diag('->deSelectOption()'); |
|---|
| 86 |
list($method, $uri, $parameters) = $b-> |
|---|
| 87 |
deSelectOption('select_multiple', 'selected')-> |
|---|
| 88 |
deSelectOption('select_multiple', 'last')-> |
|---|
| 89 |
click('submit') |
|---|
| 90 |
; |
|---|
| 91 |
$t->is(isset($parameters['select_multiple']), 'first', '->deSelectOption() deselect the specified option'); |
|---|
| 92 |
|
|---|
| 93 |
$t->diag('->deSelectOption()'); |
|---|
| 94 |
list($method, $uri, $parameters) = $b-> |
|---|
| 95 |
deSelectOption('article[category]', '2')-> |
|---|
| 96 |
click('submit') |
|---|
| 97 |
; |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
$t->ok(array_search(3, $parameters['article']['category']) !== false, '->deSelectOption() leave selected option 3'); |
|---|
| 102 |
$t->is(array_search('2', $parameters['article']['category']), false, '->deSelectOption() deselect option 2'); |
|---|
| 103 |
|
|---|
| 104 |
try |
|---|
| 105 |
{ |
|---|
| 106 |
$t->diag('->deSelectOption() with empty value'); |
|---|
| 107 |
$b->deSelectOption('article[category]', null); |
|---|
| 108 |
$t->fail('->deselect() cannot deselect empty option'); |
|---|
| 109 |
} |
|---|
| 110 |
catch(Exception $e) |
|---|
| 111 |
{ |
|---|
| 112 |
$t->pass('->deselect() cannot deselect empty option'); |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
try |
|---|
| 116 |
{ |
|---|
| 117 |
$t->diag('->deSelectOption() with empty value'); |
|---|
| 118 |
$b->deSelectOption('article[category]', '5'); |
|---|
| 119 |
$t->fail('->deselect() cannot deselect not existent option'); |
|---|
| 120 |
} |
|---|
| 121 |
catch(Exception $e) |
|---|
| 122 |
{ |
|---|
| 123 |
$t->pass('->deselect() cannot deselect not existent option'); |
|---|
| 124 |
} |
|---|