| 25 | | |
|---|
| | 25 | |
|---|
| | 26 | function test_link_to_remote() |
|---|
| | 27 | { |
|---|
| | 28 | $this->assertEqual( |
|---|
| | 29 | $this->PrototypeHelper->link_to_remote('test', array('url' => 'http://www.akelos.org', 'update' => 'listing')), |
|---|
| | 30 | '<a href="#" onclick="new Ajax.Updater(\'listing\', \'http://www.akelos.org\', {}); return false;">test</a>' |
|---|
| | 31 | ); |
|---|
| | 32 | $this->assertEqual( |
|---|
| | 33 | $this->PrototypeHelper->link_to_remote('test', array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'listing')), |
|---|
| | 34 | '<a href="#" onclick="new Ajax.Updater(\'listing\', \'/foo/bar/\', {}); return false;">test</a>' |
|---|
| | 35 | ); |
|---|
| | 36 | |
|---|
| | 37 | $this->assertEqual( |
|---|
| | 38 | $this->PrototypeHelper->link_to_remote('test', array('url' => array('controller' => 'foo', 'action' => 'bar', 'm' => 'ore', 'b' => 'eer'), 'update' => 'listing')), |
|---|
| | 39 | '<a href="#" onclick="new Ajax.Updater(\'listing\', \'/foo/bar/?m=ore&b=eer\', {}); return false;">test</a>' |
|---|
| | 40 | ); |
|---|
| | 41 | |
|---|
| | 42 | } |
|---|
| | 43 | |
|---|
| | 44 | function test_periodically_call_remote() |
|---|
| | 45 | { |
|---|
| | 46 | $this->assertEqual( |
|---|
| | 47 | $this->PrototypeHelper->periodically_call_remote(array('url' => 'http://localhost', 'update' => 'listing', 'frequency' => 1)), |
|---|
| | 48 | "<script type=\"text/javascript\">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('listing', 'http://localhost', {})}, 1)\n//]]>\n</script>" |
|---|
| | 49 | ); |
|---|
| | 50 | |
|---|
| | 51 | $this->assertEqual( |
|---|
| | 52 | $this->PrototypeHelper->periodically_call_remote(array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'listing', 'frequency' => 1)), |
|---|
| | 53 | "<script type=\"text/javascript\">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('listing', '/foo/bar/', {})}, 1)\n//]]>\n</script>" |
|---|
| | 54 | ); |
|---|
| | 55 | } |
|---|
| | 56 | |
|---|
| | 57 | function test_form_remote_tag() |
|---|
| | 58 | { |
|---|
| | 59 | $this->assertEqual( |
|---|
| | 60 | $this->PrototypeHelper->form_remote_tag(array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'div_to_update', 'html' => array('id' => 'form_id'))), |
|---|
| | 61 | '<form action="/foo/bar/" id="form_id" method="post" onsubmit="new Ajax.Updater(\'div_to_update\', \'/foo/bar/\', {parameters:Form.serialize(this)}); return false;">' |
|---|
| | 62 | ); |
|---|
| | 63 | $this->assertEqual( |
|---|
| | 64 | $this->PrototypeHelper->form_remote_tag(array('url' => 'http://www.akelos.org', 'update' => 'div_to_update', 'html' => array('id' => 'form_id'))), |
|---|
| | 65 | '<form action="http://www.akelos.org" id="form_id" method="post" onsubmit="new Ajax.Updater(\'div_to_update\', \'http://www.akelos.org\', {parameters:Form.serialize(this)}); return false;">' |
|---|
| | 66 | ); |
|---|
| | 67 | $this->assertEqual( |
|---|
| | 68 | $this->PrototypeHelper->form_remote_tag(array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'div_to_update', 'html' => array('id' => 'form_id', 'action' => $this->controller->url_helper->url_for(array('controller' => 'some', 'action' => 'place'))))), |
|---|
| | 69 | '<form action="/some/place/" id="form_id" method="post" onsubmit="new Ajax.Updater(\'div_to_update\', \'/foo/bar/\', {parameters:Form.serialize(this)}); return false;">' |
|---|
| | 70 | ); |
|---|
| | 71 | } |
|---|
| | 72 | |
|---|
| | 73 | function test_remote_form_for() |
|---|
| | 74 | { |
|---|
| | 75 | } |
|---|
| | 76 | |
|---|
| | 77 | function test_form_remote_for() |
|---|
| | 78 | { |
|---|
| | 79 | } |
|---|
| | 80 | |
|---|
| 30 | | $this->PrototypeHelper->submit_to_remote("More beer!", "1000000", array('update' => 'empty_bottle','url'=>'http://www.example.com/'))); |
|---|
| | 88 | $this->assertEqual( |
|---|
| | 89 | $this->PrototypeHelper->submit_to_remote("More beer!", "1000000", array('update' => 'empty_bottle', 'url' => array('controller' => 'foo', 'action' => 'bar'))), |
|---|
| | 90 | '<input name="More beer!" onclick="new Ajax.Updater(\'empty_bottle\', \'/foo/bar/\', {parameters:Form.serialize(this.form)}); return false;" type="button" value="1000000" />' |
|---|
| | 91 | ); |
|---|
| | 92 | } |
|---|
| | 93 | |
|---|
| | 94 | function test_update_element_function() |
|---|
| | 95 | { |
|---|
| | 96 | $this->assertEqual( |
|---|
| | 97 | $this->PrototypeHelper->update_element_function('products', array('position' => 'bottom'), array('content' => '<p>New product!</p>')), |
|---|
| | 98 | "new Insertion.Bottom('products','Array');\n" |
|---|
| | 99 | ); |
|---|
| | 100 | } |
|---|
| | 101 | |
|---|
| | 102 | function test_evaluate_remote_response() |
|---|
| | 103 | { |
|---|
| | 104 | $this->assertEqual($this->PrototypeHelper->evaluate_remote_response(), 'eval(request.responseText)'); |
|---|
| | 105 | } |
|---|
| | 106 | |
|---|
| | 107 | function test_remote_function() |
|---|
| | 108 | { |
|---|
| | 109 | $this->assertEqual( |
|---|
| | 110 | $this->PrototypeHelper->remote_function(array('url' => 'http://akelos.org', 'update' => 'div_update')), |
|---|
| | 111 | 'new Ajax.Updater(\'div_update\', \'http://akelos.org\', {})' |
|---|
| | 112 | ); |
|---|
| | 113 | } |
|---|
| | 114 | |
|---|
| | 115 | function test_observe_field() |
|---|
| | 116 | { |
|---|
| | 117 | $this->assertEqual( |
|---|
| | 118 | $this->PrototypeHelper->observe_field('form_id', array('url' => 'http://akelos.org', 'frequency' => 2, 'update' => 'div_update')), |
|---|
| | 119 | "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('form_id', 2, function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" |
|---|
| | 120 | ); |
|---|
| | 121 | $this->assertEqual( |
|---|
| | 122 | $this->PrototypeHelper->observe_field('form_id', array('url' => 'http://akelos.org', 'update' => 'div_update')), |
|---|
| | 123 | "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.EventObserver('form_id', function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" |
|---|
| | 124 | ); |
|---|
| | 125 | } |
|---|
| | 126 | |
|---|
| | 127 | function test_observe_form() |
|---|
| | 128 | { |
|---|
| | 129 | $this->assertEqual( |
|---|
| | 130 | $this->PrototypeHelper->observe_form('form_id', array('url' => 'http://akelos.org', 'frequency' => 2, 'update' => 'div_update')), |
|---|
| | 131 | "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('form_id', 2, function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" |
|---|
| | 132 | ); |
|---|
| | 133 | $this->assertEqual( |
|---|
| | 134 | $this->PrototypeHelper->observe_form('form_id', array('url' => 'http://akelos.org', 'update' => 'div_update')), |
|---|
| | 135 | "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.EventObserver('form_id', function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" |
|---|
| | 136 | ); |
|---|