code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function testElementCache() {
$writable = is_writable(CACHE . 'views' . DS);
if ($this->skipIf(!$writable, 'CACHE/views dir is not writable, cannot test elementCache. %s')) {
return;
}
$View = new TestView($this->PostsController);
$element = 'test_element';
$expected = 'this is the test element';
$result = $View->element($element);
$this->assertEqual($result, $expected);
$cached = false;
$result = $View->element($element, array('cache'=>'+1 second'));
if (file_exists(CACHE . 'views' . DS . 'element_cache_'.$element)) {
$cached = true;
unlink(CACHE . 'views' . DS . 'element_cache_'.$element);
}
$this->assertTrue($cached);
$cached = false;
$result = $View->element($element, array('cache' => true, 'param' => 'val'));
if (file_exists(CACHE . 'views' . DS . 'element_cache_param_'.$element)) {
$cached = true;
unlink(CACHE . 'views' . DS . 'element_cache_param_'.$element);
}
$this->assertTrue($cached);
$cached = false;
$result = $View->element($element, array('cache'=>'+1 second', 'other_param'=> true, 'anotherParam'=> true));
if (file_exists(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_'.$element)) {
$cached = true;
unlink(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_'.$element);
}
$this->assertTrue($cached);
$cached = false;
$result = $View->element($element, array('cache'=>array('time'=>'+1 second', 'key'=>'/whatever/here')));
if (file_exists(CACHE . 'views' . DS . 'element_'.Inflector::slug('/whatever/here').'_'.$element)) {
$cached = true;
unlink(CACHE . 'views' . DS . 'element_'.Inflector::slug('/whatever/here').'_'.$element);
}
$this->assertTrue($cached);
$cached = false;
$result = $View->element($element, array('cache'=>array('time'=>'+1 second', 'key'=>'whatever_here')));
if (file_exists(CACHE . 'views' . DS . 'element_whatever_here_'.$element)) {
$cached = true;
unlink(CACHE . 'views' . DS . 'element_whatever_here_'.$element);
}
$this->assertTrue($cached);
$this->assertEqual($result, $expected);
} | testElementCache method
@access public
@return void | testElementCache | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testElementCtpFallback() {
$View = new TestView($this->PostsController);
$View->ext = '.missing';
$element = 'test_element';
$expected = 'this is the test element';
$result = $View->element($element);
$this->assertEqual($expected, $result);
} | test that ctp is used as a fallback file extension for elements
@return void | testElementCtpFallback | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testLoadHelpers() {
$View = new TestView($this->PostsController);
$loaded = array();
$result = $View->loadHelpers($loaded, array('Html', 'Form', 'Ajax'));
$this->assertTrue(is_object($result['Html']));
$this->assertTrue(is_object($result['Form']));
$this->assertTrue(is_object($result['Form']->Html));
$this->assertTrue(is_object($result['Ajax']->Html));
$View->plugin = 'test_plugin';
$result = $View->loadHelpers($loaded, array('TestPlugin.PluggedHelper'));
$this->assertTrue(is_object($result['PluggedHelper']));
$this->assertTrue(is_object($result['PluggedHelper']->OtherHelper));
} | testLoadHelpers method
@access public
@return void | testLoadHelpers | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testHelperCallbackTriggering() {
$this->PostsController->helpers = array('Session', 'Html', 'CallbackMock');
$View =& new TestView($this->PostsController);
$loaded = array();
$View->loaded = $View->loadHelpers($loaded, $this->PostsController->helpers);
$View->loaded['CallbackMock']->expectOnce('beforeRender');
$View->loaded['CallbackMock']->expectOnce('afterRender');
$View->loaded['CallbackMock']->expectOnce('beforeLayout');
$View->loaded['CallbackMock']->expectOnce('afterLayout');
$View->render('index');
} | test the correct triggering of helper callbacks
@return void | testHelperCallbackTriggering | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testBeforeLayout() {
$this->PostsController->helpers = array('Session', 'TestAfter', 'Html');
$View =& new View($this->PostsController);
$out = $View->render('index');
$this->assertEqual($View->loaded['testAfter']->property, 'Valuation');
} | testBeforeLayout method
@access public
@return void | testBeforeLayout | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testAfterLayout() {
$this->PostsController->helpers = array('Session', 'TestAfter', 'Html');
$this->PostsController->set('variable', 'values');
$View =& new View($this->PostsController);
ClassRegistry::addObject('afterView', $View);
$content = 'This is my view output';
$result = $View->renderLayout($content, 'default');
$this->assertPattern('/modified in the afterlife/', $result);
$this->assertPattern('/This is my view output/', $result);
} | testAfterLayout method
@access public
@return void | testAfterLayout | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testRenderLoadHelper() {
$this->PostsController->helpers = array('Session', 'Html', 'Form', 'Ajax');
$View =& new TestView($this->PostsController);
$result = $View->_render($View->getViewFileName('index'), array());
$this->assertEqual($result, 'posts index');
$helpers = $View->loaded;
$this->assertTrue(is_object($helpers['html']));
$this->assertTrue(is_object($helpers['form']));
$this->assertTrue(is_object($helpers['form']->Html));
$this->assertTrue(is_object($helpers['ajax']->Html));
$this->PostsController->helpers = array('Html', 'Form', 'Ajax', 'TestPlugin.PluggedHelper');
$View =& new TestView($this->PostsController);
$result = $View->_render($View->getViewFileName('index'), array());
$this->assertEqual($result, 'posts index');
$helpers = $View->loaded;
$this->assertTrue(is_object($helpers['html']));
$this->assertTrue(is_object($helpers['form']));
$this->assertTrue(is_object($helpers['form']->Html));
$this->assertTrue(is_object($helpers['ajax']->Html));
$this->assertTrue(is_object($helpers['pluggedHelper']->OtherHelper));
$this->assertTrue(is_object($View->Html));
$this->assertTrue(is_object($View->Form));
$this->assertTrue(is_object($View->Form->Html));
$this->assertTrue(is_object($View->PluggedHelper->OtherHelper));
$this->assertReference($View->Form, $View->loaded['form']);
$this->assertReference($View->Html, $View->loaded['html']);
$this->assertReference($View->PluggedHelper->OtherHelper, $View->loaded['otherHelper']);
} | testRenderLoadHelper method
@access public
@return void | testRenderLoadHelper | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testRender() {
$View =& new TestView($this->PostsController);
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render('index'));
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->PostsController->set('url', 'flash');
$this->PostsController->set('message', 'yo what up');
$this->PostsController->set('pause', 3);
$this->PostsController->set('page_title', 'yo what up');
$View =& new TestView($this->PostsController);
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render(false, 'flash'));
$this->assertPattern("/<title>yo what up<\/title>/", $result);
$this->assertPattern("/<p><a href=\"flash\">yo what up<\/a><\/p>/", $result);
$this->assertTrue($View->render(false, 'flash'));
$this->PostsController->helpers = array('Session', 'Cache', 'Html');
$this->PostsController->constructClasses();
$this->PostsController->cacheAction = array('index' => 3600);
$this->PostsController->params['action'] = 'index';
Configure::write('Cache.check', true);
$View =& new TestView($this->PostsController);
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render('index'));
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
} | testRender method
@access public
@return void | testRender | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testRenderLayoutWithMockCacheHelper() {
$_check = Configure::read('Cache.check');
Configure::write('Cache.check', true);
$Controller =& new ViewPostsController();
$Controller->cacheAction = '+1 day';
$View =& new View($Controller);
$View->loaded['cache'] = new ViewTestMockCacheHelper();
$View->loaded['cache']->expectCallCount('cache', 2);
$View->render('index');
Configure::write('Cache.check', $_check);
} | test rendering layout with cache helper loaded
@return void | testRenderLayoutWithMockCacheHelper | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testViewVarOverwritingLocalHelperVar() {
$Controller =& new ViewPostsController();
$Controller->helpers = array('Session', 'Html');
$Controller->set('html', 'I am some test html');
$View =& new View($Controller);
$result = $View->render('helper_overwrite', false);
$this->assertPattern('/I am some test html/', $result);
$this->assertPattern('/Test link/', $result);
} | test that view vars can replace the local helper variables
and not overwrite the $this->Helper references
@return void | testViewVarOverwritingLocalHelperVar | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testViewFileName() {
$View =& new TestView($this->PostsController);
$result = $View->getViewFileName('index');
$this->assertPattern('/posts(\/|\\\)index.ctp/', $result);
$result = $View->getViewFileName('/pages/home');
$this->assertPattern('/pages(\/|\\\)home.ctp/', $result);
$result = $View->getViewFileName('../elements/test_element');
$this->assertPattern('/elements(\/|\\\)test_element.ctp/', $result);
$result = $View->getViewFileName('../themed/test_theme/posts/index');
$this->assertPattern('/themed(\/|\\\)test_theme(\/|\\\)posts(\/|\\\)index.ctp/', $result);
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'posts' . DS .'index.ctp';
$result = $View->getViewFileName('../posts/index');
$this->assertEqual($result, $expected);
} | testGetViewFileName method
@access public
@return void | testViewFileName | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testRenderCache() {
$writable = is_writable(CACHE . 'views' . DS);
if ($this->skipIf(!$writable, 'CACHE/views dir is not writable, cannot test renderCache. %s')) {
return;
}
$view = 'test_view';
$View =& new View($this->PostsController);
$path = CACHE . 'views' . DS . 'view_cache_'.$view;
$cacheText = '<!--cachetime:'.time().'-->some cacheText';
$f = fopen($path, 'w+');
fwrite($f, $cacheText);
fclose($f);
$result = $View->renderCache($path, '+1 second');
$this->assertFalse($result);
@unlink($path);
$cacheText = '<!--cachetime:'.(time() + 10).'-->some cacheText';
$f = fopen($path, 'w+');
fwrite($f, $cacheText);
fclose($f);
ob_start();
$View->renderCache($path, '+1 second');
$result = ob_get_clean();
$expected = 'some cacheText';
$this->assertPattern('/^some cacheText/', $result);
@unlink($path);
} | testRenderCache method
@access public
@return void | testRenderCache | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testRenderStrippingNoCacheTagsOnlyCacheHelper() {
Configure::write('Cache.check', false);
$View =& new View($this->PostsController);
$View->set(array('superman' => 'clark', 'variable' => 'var'));
$View->helpers = array('Html', 'Form', 'Cache');
$View->layout = 'cache_layout';
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
} | Test that render() will remove the cake:nocache tags when only the cachehelper is present.
@return void | testRenderStrippingNoCacheTagsOnlyCacheHelper | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testRenderStrippingNoCacheTagsOnlyCacheCheck() {
Configure::write('Cache.check', true);
$View =& new View($this->PostsController);
$View->set(array('superman' => 'clark', 'variable' => 'var'));
$View->helpers = array('Html', 'Form');
$View->layout = 'cache_layout';
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
} | Test that render() will remove the cake:nocache tags when only the Cache.check is true.
@return void | testRenderStrippingNoCacheTagsOnlyCacheCheck | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testSet() {
$View =& new TestView($this->PostsController);
$View->viewVars = array();
$View->set('somekey', 'someValue');
$this->assertIdentical($View->viewVars, array('somekey' => 'someValue'));
$this->assertIdentical($View->getVars(), array('somekey'));
$View->viewVars = array();
$keys = array('key1', 'key2');
$values = array('value1', 'value2');
$View->set($keys, $values);
$this->assertIdentical($View->viewVars, array('key1' => 'value1', 'key2' => 'value2'));
$this->assertIdentical($View->getVars(), array('key1', 'key2'));
$this->assertIdentical($View->getVar('key1'), 'value1');
$this->assertNull($View->getVar('key3'));
$View->set(array('key3' => 'value3'));
$this->assertIdentical($View->getVar('key3'), 'value3');
$View->viewVars = array();
$View->set(array(3 => 'three', 4 => 'four'));
$View->set(array(1 => 'one', 2 => 'two'));
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
$this->assertEqual($View->viewVars, $expected);
} | testSet method
@access public
@return void | testSet | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testEntityReference() {
$View =& new TestView($this->PostsController);
$View->model = 'Post';
$View->field = 'title';
$this->assertEqual($View->entity(), array('Post', 'title'));
$View->association = 'Comment';
$View->field = 'user_id';
$this->assertEqual($View->entity(), array('Comment', 'user_id'));
$View->model = 0;
$View->association = null;
$View->field = 'Node';
$View->fieldSuffix = 'title';
$View->entityPath = '0.Node.title';
$expected = array(0, 'Node', 'title');
$this->assertEqual($View->entity(), $expected);
$View->model = 'HelperTestTag';
$View->field = 'HelperTestTag';
$View->modelId = null;
$View->association = null;
$View->fieldSuffix = null;
$View->entityPath = 'HelperTestTag';
$expected = array('HelperTestTag', 'HelperTestTag');
$this->assertEqual($View->entity(), $expected);
} | testEntityReference method
@access public
@return void | testEntityReference | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function testBadExt() {
$this->PostsController->action = 'something';
$this->PostsController->ext = '.whatever';
restore_error_handler();
ob_start();
$View = new TestView($this->PostsController);
$View->render('this_is_missing');
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
set_error_handler('simpleTestErrorHandler');
$this->assertPattern("/<em>PostsController::<\/em><em>something\(\)<\/em>/", $result);
$this->assertPattern("/posts(\/|\\\)this_is_missing.whatever/", $result);
$this->PostsController->ext = ".bad";
$View =& new TestView($this->PostsController);
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render('index'));
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
} | testBadExt method
@access public
@return void | testBadExt | php | Datawalke/Coordino | cake/tests/cases/libs/view/view.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/view.test.php | MIT |
function schema() {
return array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
} | schema method
@access public
@return void | schema | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function codeBlock($parameter) {
if (empty($this->codeBlocks)) {
$this->codeBlocks = array();
}
$this->codeBlocks[] = $parameter;
} | codeBlock method
@param mixed $parameter
@access public
@return void | codeBlock | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function setUp() {
Router::reload();
$this->Ajax =& new TestAjaxHelper();
$this->Ajax->Html =& new HtmlHelper();
$this->Ajax->Form =& new FormHelper();
$this->Ajax->Javascript =& new JavascriptHelper();
$this->Ajax->Form->Html =& $this->Ajax->Html;
$view =& new View(new AjaxTestController());
ClassRegistry::addObject('view', $view);
ClassRegistry::addObject('PostAjaxTest', new PostAjaxTest());
$this->Ajax->Form->params = array(
'plugin' => null,
'action' => 'view',
'controller' => 'users'
);
} | setUp method
@access public
@return void | setUp | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function tearDown() {
unset($this->Ajax);
ClassRegistry::flush();
} | tearDown method
@access public
@return void | tearDown | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testEvalScripts() {
$result = $this->Ajax->link('Test Link', 'http://www.cakephp.org', array('id' => 'link1', 'update' => 'content', 'evalScripts' => false));
$expected = array(
'a' => array('id' => 'link1', 'onclick' => ' event.returnValue = false; return false;', 'href' => 'http://www.cakephp.org'),
'Test Link',
'/a',
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Event.observe('link1', 'click', function(event) { new Ajax.Updater('content','http://www.cakephp.org', {asynchronous:true, evalScripts:false, requestHeaders:['X-Update', 'content']}) }, false);",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->link('Test Link', 'http://www.cakephp.org', array('id' => 'link1', 'update' => 'content'));
$expected = array(
'a' => array('id' => 'link1', 'onclick' => ' event.returnValue = false; return false;', 'href' => 'http://www.cakephp.org'),
'Test Link',
'/a',
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Event.observe('link1', 'click', function(event) { new Ajax.Updater('content','http://www.cakephp.org', {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'content']}) }, false);",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
} | testEvalScripts method
@access public
@return void | testEvalScripts | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testAutoComplete() {
$result = $this->Ajax->autoComplete('PostAjaxTest.title' , '/posts', array('minChars' => 2));
$this->assertPattern('/^<input[^<>]+name="data\[PostAjaxTest\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result);
$this->assertPattern('/<div[^<>]+id="PostAjaxTestTitle_autoComplete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<div[^<>]+class="auto_complete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<\/div>\s+<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\',')) . '/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\', {minChars:2});')) . '/', $result);
$this->assertPattern('/<\/script>$/', $result);
$result = $this->Ajax->autoComplete('PostAjaxTest.title' , '/posts', array('paramName' => 'parameter'));
$this->assertPattern('/^<input[^<>]+name="data\[PostAjaxTest\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result);
$this->assertPattern('/<div[^<>]+id="PostAjaxTestTitle_autoComplete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<div[^<>]+class="auto_complete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<\/div>\s+<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\',')) . '/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\', {paramName:\'parameter\'});')) . '/', $result);
$this->assertPattern('/<\/script>$/', $result);
$result = $this->Ajax->autoComplete('PostAjaxTest.title' , '/posts', array('paramName' => 'parameter', 'updateElement' => 'elementUpdated', 'afterUpdateElement' => 'function (input, element) { alert("updated"); }'));
$this->assertPattern('/^<input[^<>]+name="data\[PostAjaxTest\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result);
$this->assertPattern('/<div[^<>]+id="PostAjaxTestTitle_autoComplete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<div[^<>]+class="auto_complete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<\/div>\s+<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\',')) . '/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\', {paramName:\'parameter\', updateElement:elementUpdated, afterUpdateElement:function (input, element) { alert("updated"); }});')) . '/', $result);
$this->assertPattern('/<\/script>$/', $result);
$result = $this->Ajax->autoComplete('PostAjaxTest.title' , '/posts', array('callback' => 'function (input, queryString) { alert("requesting"); }'));
$this->assertPattern('/^<input[^<>]+name="data\[PostAjaxTest\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result);
$this->assertPattern('/<div[^<>]+id="PostAjaxTestTitle_autoComplete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<div[^<>]+class="auto_complete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<\/div>\s+<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\',')) . '/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Autocompleter(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'/posts\', {callback:function (input, queryString) { alert("requesting"); }});')) . '/', $result);
$this->assertPattern('/<\/script>$/', $result);
$result = $this->Ajax->autoComplete("PostAjaxText.title", "/post", array("parameters" => "'key=value&key2=value2'"));
$this->assertPattern('/{parameters:\'key=value&key2=value2\'}/', $result);
$result = $this->Ajax->autoComplete("PostAjaxText.title", "/post", array("with" => "'key=value&key2=value2'"));
$this->assertPattern('/{parameters:\'key=value&key2=value2\'}/', $result);
} | testAutoComplete method
@access public
@return void | testAutoComplete | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testAsynchronous() {
$result = $this->Ajax->link('Test Link', '/', array('id' => 'link1', 'update' => 'content', 'type' => 'synchronous'));
$expected = array(
'a' => array('id' => 'link1', 'onclick' => ' event.returnValue = false; return false;', 'href' => '/'),
'Test Link',
'/a',
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Event.observe('link1', 'click', function(event) { new Ajax.Updater('content','/', {asynchronous:false, evalScripts:true, requestHeaders:['X-Update', 'content']}) }, false);",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
} | testAsynchronous method
@access public
@return void | testAsynchronous | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testDraggable() {
$result = $this->Ajax->drag('id', array('handle' => 'other_id'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Draggable('id', {handle:'other_id'});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->drag('id', array('onDrag' => 'doDrag', 'onEnd' => 'doEnd'));
$this->assertPattern('/onDrag:doDrag/', $result);
$this->assertPattern('/onEnd:doEnd/', $result);
} | testDraggable method
@access public
@return void | testDraggable | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testDroppable() {
$result = $this->Ajax->drop('droppable', array('accept' => 'crap'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Droppables.add('droppable', {accept:'crap'});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->dropRemote('droppable', array('accept' => 'crap'), array('url' => '/posts'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Droppables.add('droppable', {accept:'crap', onDrop:function(element, droppable, event) {new Ajax.Request('/posts', {asynchronous:true, evalScripts:true})}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->dropRemote('droppable', array('accept' => array('crap1', 'crap2')), array('url' => '/posts'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Droppables.add('droppable', {accept:[\"crap1\",\"crap2\"], onDrop:function(element, droppable, event) {new Ajax.Request('/posts', {asynchronous:true, evalScripts:true})}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->dropRemote('droppable', array('accept' => 'crap'), array('url' => '/posts', 'with' => '{drag_id:element.id,drop_id:dropon.id,event:event.whatever_you_want}'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Droppables.add('droppable', {accept:'crap', onDrop:function(element, droppable, event) {new Ajax.Request('/posts', {asynchronous:true, evalScripts:true, parameters:{drag_id:element.id,drop_id:dropon.id,event:event.whatever_you_want}})}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
} | testDroppable method
@access public
@return void | testDroppable | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testForm() {
$result = $this->Ajax->form('showForm', 'post', array('model' => 'Form', 'url' => array('action' => 'showForm', 'controller' => 'forms'), 'update' => 'form_box'));
$this->assertNoPattern('/model=/', $result);
$result = $this->Ajax->form('showForm', 'post', array('name'=> 'SomeFormName', 'id' => 'MyFormID', 'url' => array('action' => 'showForm', 'controller' => 'forms'), 'update' => 'form_box'));
$this->assertPattern('/id="MyFormID"/', $result);
$this->assertPattern('/name="SomeFormName"/', $result);
} | testForm method
@access public
@return void | testForm | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testSortable() {
$result = $this->Ajax->sortable('ull', array('constraint' => false, 'ghosting' => true));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Sortable.create('ull', {constraint:false, ghosting:true});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->sortable('ull', array('constraint' => 'false', 'ghosting' => 'true'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Sortable.create('ull', {constraint:false, ghosting:true});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->sortable('ull', array('constraint'=>'false', 'ghosting'=>'true', 'update' => 'myId'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Sortable.create('ull', {constraint:false, ghosting:true, update:'myId'});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->sortable('faqs', array('url'=>'http://www.cakephp.org',
'update' => 'faqs',
'tag' => 'tbody',
'handle' => 'grip',
'before' => "Element.hide('message')",
'complete' => "Element.show('message');"
));
$expected = 'Sortable.create(\'faqs\', {update:\'faqs\', tag:\'tbody\', handle:\'grip\', onUpdate:function(sortable) {Element.hide(\'message\'); new Ajax.Updater(\'faqs\',\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, onComplete:function(request, json) {Element.show(\'message\');}, parameters:Sortable.serialize(\'faqs\'), requestHeaders:[\'X-Update\', \'faqs\']})}});';
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*' . str_replace('/', '\\/', preg_quote($expected)) . '\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$result = $this->Ajax->sortable('div', array('overlap' => 'foo'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"Sortable.create('div', {overlap:'foo'});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->sortable('div', array('block' => false));
$expected = "Sortable.create('div', {});";
$this->assertEqual($result, $expected);
$result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => 'someID'));
$expected = "Sortable.create('div', {scroll:'someID'});";
$this->assertEqual($result, $expected);
$result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => 'window'));
$expected = "Sortable.create('div', {scroll:window});";
$this->assertEqual($result, $expected);
$result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => "$('someElement')"));
$expected = "Sortable.create('div', {scroll:$('someElement')});";
$this->assertEqual($result, $expected);
} | testSortable method
@access public
@return void | testSortable | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testLink() {
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads');
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+id="link\d+"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'link\d+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Request\(\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('confirm' => 'Are you sure & positive?'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+id="link\d+"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'link\d+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*if \(confirm\(\'Are you sure & positive\?\'\)\) {\s*new Ajax\.Request\(\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true}\);\s*}\s*else\s*{\s*event.returnValue = false;\s*return false;\s*}\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('update' => 'myDiv'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+id="link\d+"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'link\d+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('update' => 'myDiv', 'id' => 'myLink'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+id="myLink"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'myLink\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('update' => 'myDiv', 'id' => 'myLink', 'complete' => 'myComplete();'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+id="myLink"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'myLink\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, onComplete:function\(request, json\) {myComplete\(\);}, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('update' => 'myDiv', 'id' => 'myLink', 'loading' => 'myLoading();', 'complete' => 'myComplete();'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+id="myLink"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'myLink\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, onComplete:function\(request, json\) {myComplete\(\);}, onLoading:function\(request\) {myLoading\(\);}, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('update' => 'myDiv', 'encoding' => 'utf-8'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'\w+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, encoding:\'utf-8\', requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('update' => 'myDiv', 'success' => 'success();'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'\w+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, onSuccess:function\(request\) {success\(\);}, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', 'http://www.cakephp.org/downloads', array('update' => 'myDiv', 'failure' => 'failure();'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/^<a[^<>]+href="http:\/\/www.cakephp.org\/downloads"[^<>]*>/', $result);
$this->assertPattern('/^<a[^<>]+onclick="\s*event.returnValue = false;\s*return false;"[^<>]*>/', $result);
$this->assertPattern('/<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'\w+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, onFailure:function\(request\) {failure\(\);}, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', '/test', array('complete' => 'test'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern("/Event.observe\('link[0-9]+', [\w\d,'\(\)\s{}]+Ajax\.Request\([\w\d\s,'\(\){}:\/]+onComplete:function\(request, json\) {test}/", $result);
$this->assertNoPattern('/^<a[^<>]+complete="test"[^<>]*>Ajax Link<\/a>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$result = $this->Ajax->link(
'Ajax Link',
array('controller' => 'posts', 'action' => 'index', '?' => array('one' => '1', 'two' => '2')),
array('update' => 'myDiv', 'id' => 'myLink')
);
$this->assertPattern('#/posts\?one\=1\&two\=2#', $result);
} | testLink method
@access public
@return void | testLink | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testRemoteTimer() {
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 10\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true})')) . '/', $result);
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org', 'frequency' => 25));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 25\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true})')) . '/', $result);
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org', 'complete' => 'complete();'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 10\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, onComplete:function(request, json) {complete();}})')) . '/', $result);
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org', 'complete' => 'complete();', 'create' => 'create();'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 10\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, onComplete:function(request, json) {complete();}, onCreate:function(request, xhr) {create();}})')) . '/', $result);
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org', 'exception' => 'alert(exception);'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 10\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, onException:function(request, exception) {alert(exception);}})')) . '/', $result);
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org', 'contentType' => 'application/x-www-form-urlencoded'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 10\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, contentType:\'application/x-www-form-urlencoded\'})')) . '/', $result);
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org', 'method' => 'get', 'encoding' => 'utf-8'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 10\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, method:\'get\', encoding:\'utf-8\'})')) . '/', $result);
$result = $this->Ajax->remoteTimer(array('url' => 'http://www.cakephp.org', 'postBody' => 'var1=value1'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new PeriodicalExecuter\(function\(pe\) {.+}, 10\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, postBody:\'var1=value1\'})')) . '/', $result);
} | testRemoteTimer method
@access public
@return void | testRemoteTimer | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testObserveField() {
$result = $this->Ajax->observeField('field', array('url' => 'http://www.cakephp.org'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new Form.Element.EventObserver\(\'field\', function\(element, value\) {.+}\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, parameters:Form.Element.serialize(\'field\')})')) . '/', $result);
$result = $this->Ajax->observeField('field', array('url' => 'http://www.cakephp.org', 'frequency' => 15));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new Form.Element.Observer\(\'field\', 15, function\(element, value\) {.+}\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Request(\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, parameters:Form.Element.serialize(\'field\')})')) . '/', $result);
$result = $this->Ajax->observeField('field', array('url' => 'http://www.cakephp.org', 'update' => 'divId'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new Form.Element.EventObserver\(\'field\', function\(element, value\) {.+}\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Updater(\'divId\',\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, parameters:Form.Element.serialize(\'field\'), requestHeaders:[\'X-Update\', \'divId\']})')) . '/', $result);
$result = $this->Ajax->observeField('field', array('url' => 'http://www.cakephp.org', 'update' => 'divId', 'with' => 'Form.Element.serialize(\'otherField\')'));
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>.+<\/script>$/s', $result);
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/^<script[^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*new Form.Element.EventObserver\(\'field\', function\(element, value\) {.+}\)\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/' . str_replace('/', '\\/', preg_quote('new Ajax.Updater(\'divId\',\'http://www.cakephp.org\', {asynchronous:true, evalScripts:true, parameters:Form.Element.serialize(\'otherField\'), requestHeaders:[\'X-Update\', \'divId\']})')) . '/', $result);
} | testObserveField method
@access public
@return void | testObserveField | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testObserveForm() {
$result = $this->Ajax->observeForm('form', array('url' => 'http://www.cakephp.org'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Form.EventObserver('form', function(element, value) {new Ajax.Request('http://www.cakephp.org', {asynchronous:true, evalScripts:true, parameters:Form.serialize('form')})})",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->observeForm('form', array('url' => 'http://www.cakephp.org', 'frequency' => 15));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Form.Observer('form', 15, function(element, value) {new Ajax.Request('http://www.cakephp.org', {asynchronous:true, evalScripts:true, parameters:Form.serialize('form')})})",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->observeForm('form', array('url' => 'http://www.cakephp.org', 'update' => 'divId'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Form.EventObserver('form', function(element, value) {new Ajax.Updater('divId','http://www.cakephp.org', {asynchronous:true, evalScripts:true, parameters:Form.serialize('form'), requestHeaders:['X-Update', 'divId']})}",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->observeForm('form', array('url' => 'http://www.cakephp.org', 'update' => 'divId', 'with' => "Form.serialize('otherForm')"));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Form.EventObserver('form', function(element, value) {new Ajax.Updater('divId','http://www.cakephp.org', {asynchronous:true, evalScripts:true, parameters:Form.serialize('otherForm'), requestHeaders:['X-Update', 'divId']})}",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
} | testObserveForm method
@access public
@return void | testObserveForm | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testSlider() {
$result = $this->Ajax->slider('sliderId', 'trackId');
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var sliderId = new Control.Slider('sliderId', 'trackId', {});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->slider('sliderId', 'trackId', array('axis' => 'vertical'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var sliderId = new Control.Slider('sliderId', 'trackId', {axis:'vertical'});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->slider('sliderId', 'trackId', array('axis' => 'vertical', 'minimum' => 60, 'maximum' => 288, 'alignX' => -28, 'alignY' => -5, 'disabled' => true));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var sliderId = new Control.Slider('sliderId', 'trackId', {axis:'vertical', minimum:60, maximum:288, alignX:-28, alignY:-5, disabled:true});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->slider('sliderId', 'trackId', array('change' => "alert('changed');"));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var sliderId = new Control.Slider('sliderId', 'trackId', {onChange:function(value) {alert('changed');}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->slider('sliderId', 'trackId', array('change' => "alert('changed');", 'slide' => "alert('sliding');"));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var sliderId = new Control.Slider('sliderId', 'trackId', {onChange:function(value) {alert('changed');}, onSlide:function(value) {alert('sliding');}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->slider('sliderId', 'trackId', array('values' => array(10, 20, 30)));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var sliderId = new Control.Slider('sliderId', 'trackId', {values:[10,20,30]});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->slider('sliderId', 'trackId', array('range' => '$R(10, 30)'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var sliderId = new Control.Slider('sliderId', 'trackId', {range:\$R(10, 30)});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
} | testSlider method
@access public
@return void | testSlider | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testRemoteFunction() {
$result = $this->Ajax->remoteFunction(array('complete' => 'testComplete();'));
$expected = "new Ajax.Request('/', {asynchronous:true, evalScripts:true, onComplete:function(request, json) {testComplete();}})";
$this->assertEqual($result, $expected);
$result = $this->Ajax->remoteFunction(array('update' => 'myDiv'));
$expected = "new Ajax.Updater('myDiv','/', {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'myDiv']})";
$this->assertEqual($result, $expected);
$result = $this->Ajax->remoteFunction(array('update' => array('div1', 'div2')));
$expected = "new Ajax.Updater(document.createElement('div'),'/', {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'div1 div2']})";
$this->assertEqual($result, $expected);
$result = $this->Ajax->remoteFunction(array('update' => 'myDiv', 'confirm' => 'Are you sure?'));
$expected = "if (confirm('Are you sure?')) { new Ajax.Updater('myDiv','/', {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'myDiv']}); } else { event.returnValue = false; return false; }";
$this->assertEqual($result, $expected);
} | testRemoteFunction method
@access public
@return void | testRemoteFunction | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testDiv() {
ob_start();
$oldXUpdate = env('HTTP_X_UPDATE');
$result = $this->Ajax->div('myDiv');
$this->assertTags($result, array('div' => array('id' => 'myDiv')));
$_SERVER['HTTP_X_UPDATE'] = null;
$result = $this->Ajax->divEnd('myDiv');
$this->assertTags($result, '/div');
$_SERVER['HTTP_X_UPDATE'] = 'secondDiv';
$result = $this->Ajax->div('myDiv');
$this->assertTags($result, array('div' => array('id' => 'myDiv')));
$result = $this->Ajax->divEnd('myDiv');
$this->assertTags($result, '/div');
$_SERVER['HTTP_X_UPDATE'] = 'secondDiv myDiv anotherDiv';
$result = $this->Ajax->div('myDiv');
$this->assertTrue(empty($result));
$result = $this->Ajax->divEnd('myDiv');
$this->assertTrue(empty($result));
$_SERVER['HTTP_X_UPDATE'] = $oldXUpdate;
} | testDiv method
@access public
@return void | testDiv | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testAfterRender() {
ob_start();
$oldXUpdate = env('HTTP_X_UPDATE');
$this->Ajax->Javascript =& new TestJavascriptHelper();
$_SERVER['HTTP_X_UPDATE'] = 'secondDiv myDiv anotherDiv';
$result = $this->Ajax->div('myDiv');
$this->assertTrue(empty($result));
echo 'Contents of myDiv';
$result = $this->Ajax->divEnd('myDiv');
$this->assertTrue(empty($result));
ob_start();
$this->Ajax->afterRender();
$result = array_shift($this->Ajax->Javascript->codeBlocks);
$this->assertPattern('/^\s*' . str_replace('/', '\\/', preg_quote('var __ajaxUpdater__ = {myDiv:"Contents%20of%20myDiv"};')) . '\s*' . str_replace('/', '\\/', preg_quote('for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == "string" && $(n)) Element.update($(n), unescape(decodeURIComponent(__ajaxUpdater__[n]))); }')) . '\s*$/s', $result);
$_SERVER['HTTP_X_UPDATE'] = $oldXUpdate;
} | testAfterRender method
@access public
@return void | testAfterRender | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function testEditor() {
$result = $this->Ajax->editor('myDiv', '/');
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Ajax.InPlaceEditor('myDiv', '/', {ajaxOptions:{asynchronous:true, evalScripts:true}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->editor('myDiv', '/', array('complete' => 'testComplete();'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Ajax.InPlaceEditor('myDiv', '/', {ajaxOptions:{asynchronous:true, evalScripts:true, onComplete:function(request, json) {testComplete();}}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->editor('myDiv', '/', array('callback' => 'callback();'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Ajax.InPlaceEditor('myDiv', '/', {callback:function(form, value) {callback();}, ajaxOptions:{asynchronous:true, evalScripts:true}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->editor('myDiv', '/', array('collection' => array(1 => 'first', 2 => 'second')));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"new Ajax.InPlaceCollectionEditor('myDiv', '/', {collection:{\"1\":\"first\",\"2\":\"second\"}, ajaxOptions:{asynchronous:true, evalScripts:true}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$result = $this->Ajax->editor('myDiv', '/', array('var' => 'myVar'));
$expected = array(
array('script' => array('type' => 'text/javascript')),
$this->cDataStart,
"var myVar = new Ajax.InPlaceEditor('myDiv', '/', {ajaxOptions:{asynchronous:true, evalScripts:true}});",
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
} | testEditor method
@access public
@return void | testEditor | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/ajax.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/ajax.test.php | MIT |
function skip() {
$this->skipUnless(is_writable(TMP . 'cache' . DS . 'views' . DS), 'TMP/views is not writable %s');
} | Checks if TMP/views is writable, and skips the case if it is not.
@return void | skip | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function setUp() {
$this->Controller = new CacheTestController();
$this->Cache = new CacheHelper();
$this->_cacheSettings = Configure::read('Cache');
Configure::write('Cache.check', true);
Configure::write('Cache.disable', false);
} | setUp method
@access public
@return void | setUp | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function startCase() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
), true);
} | Start Case - switch view paths
@access public
@return void | startCase | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function tearDown() {
clearCache();
unset($this->Cache);
Configure::write('Cache', $this->_cacheSettings);
} | tearDown method
@access public
@return void | tearDown | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testLayoutCacheParsingNoTagsInView() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/php echo \$variable/', $contents);
$this->assertPattern('/php echo microtime()/', $contents);
$this->assertPattern('/clark kent/', $result);
@unlink($filename);
} | test cache parsing with no cake:nocache tags in view file.
@access public
@return void | testLayoutCacheParsingNoTagsInView | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testLayoutCacheParsingWithTagsInView() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('test_nocache_tags');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/if \(is_writable\(TMP\)\)\:/', $contents);
$this->assertPattern('/php echo \$variable/', $contents);
$this->assertPattern('/php echo microtime()/', $contents);
$this->assertNoPattern('/cake:nocache/', $contents);
@unlink($filename);
} | Test cache parsing with cake:nocache tags in view file.
@access public
@return void | testLayoutCacheParsingWithTagsInView | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testMultipleNoCacheTagsInViewfile() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('multiple_nocache');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertNoPattern('/cake:nocache/', $contents);
@unlink($filename);
} | test that multiple <cake:nocache> tags function with multiple nocache tags in the layout.
@return void | testMultipleNoCacheTagsInViewfile | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testComplexNoCache () {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_complex',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array('cache_complex' => 21600);
$this->Controller->here = '/cacheTest/cache_complex';
$this->Controller->action = 'cache_complex';
$this->Controller->layout = 'multi_cache';
$this->Controller->viewPath = 'posts';
$View = new View($this->Controller);
$result = $View->render('sequencial_nocache');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$this->assertPattern('/A\. Layout Before Content/', $result);
$this->assertPattern('/B\. In Plain Element/', $result);
$this->assertPattern('/C\. Layout After Test Element/', $result);
$this->assertPattern('/D\. In View File/', $result);
$this->assertPattern('/E\. Layout After Content/', $result);
//$this->assertPattern('/F\. In Element With No Cache Tags/', $result);
$this->assertPattern('/G\. Layout After Content And After Element With No Cache Tags/', $result);
$this->assertNoPattern('/1\. layout before content/', $result);
$this->assertNoPattern('/2\. in plain element/', $result);
$this->assertNoPattern('/3\. layout after test element/', $result);
$this->assertNoPattern('/4\. in view file/', $result);
$this->assertNoPattern('/5\. layout after content/', $result);
//$this->assertNoPattern('/6\. in element with no cache tags/', $result);
$this->assertNoPattern('/7\. layout after content and after element with no cache tags/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_complex.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
@unlink($filename);
$this->assertPattern('/A\. Layout Before Content/', $contents);
$this->assertNoPattern('/B\. In Plain Element/', $contents);
$this->assertPattern('/C\. Layout After Test Element/', $contents);
$this->assertPattern('/D\. In View File/', $contents);
$this->assertPattern('/E\. Layout After Content/', $contents);
//$this->assertPattern('/F\. In Element With No Cache Tags/', $contents);
$this->assertPattern('/G\. Layout After Content And After Element With No Cache Tags/', $contents);
$this->assertPattern('/1\. layout before content/', $contents);
$this->assertNoPattern('/2\. in plain element/', $contents);
$this->assertPattern('/3\. layout after test element/', $contents);
$this->assertPattern('/4\. in view file/', $contents);
$this->assertPattern('/5\. layout after content/', $contents);
//$this->assertPattern('/6\. in element with no cache tags/', $contents);
$this->assertPattern('/7\. layout after content and after element with no cache tags/', $contents);
} | testComplexNoCache method
@return void
@access public | testComplexNoCache | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testCacheViewVars() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/\$this\-\>viewVars/', $contents);
$this->assertPattern('/extract\(\$this\-\>viewVars, EXTR_SKIP\);/', $contents);
$this->assertPattern('/php echo \$variable/', $contents);
@unlink($filename);
} | test cache of view vars
@access public
@return void | testCacheViewVars | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testCacheActionArray() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->here = '/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
$this->Controller->cache_parsing();
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array(
'some_other_action' => 21600
);
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertFalse(file_exists($filename));
} | test cacheAction set to a boolean
@return void | testCacheActionArray | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testCacheWithNamedAndPassedArgs() {
Router::reload();
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(1, 2),
'named' => array(
'name' => 'mark',
'ice' => 'cream'
)
);
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->here = '/cache_test/cache_parsing/1/2/name:mark/ice:cream';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing_1_2_name_mark_ice_cream.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
} | test with named and pass args.
@return void | testCacheWithNamedAndPassedArgs | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testCacheWithCustomRoutes() {
Router::reload();
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
$this->Controller->cache_parsing();
$this->Controller->params = array(
'lang' => 'en',
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->here = '/en/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'en_cache_test_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
} | test that custom routes are respected when generating cache files.
@return void | testCacheWithCustomRoutes | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testCacheBaseNameControllerName() {
$this->Controller->cache_parsing();
$this->Controller->cacheAction = array(
'cache_name' => 21600
);
$this->Controller->params = array(
'controller' => 'cacheTest',
'action' => 'cache_name',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->here = '/cache/cacheTest/cache_name';
$this->Controller->action = 'cache_name';
$this->Controller->base = '/cache';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cache_cachetest_cache_name.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
} | test ControllerName contains AppName
This test verifys view cache is created correctly when the app name is contained in part of the controller name.
(webapp Name) base name is 'cache' controller is 'cacheTest' action is 'cache_name'
apps url would look somehing like http://localhost/cache/cacheTest/cache_name
@return void | testCacheBaseNameControllerName | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function testCacheEmptySections() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cacheTest',
'action' => 'cache_empty_sections',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array('cache_empty_sections' => 21600);
$this->Controller->here = '/cacheTest/cache_empty_sections';
$this->Controller->action = 'cache_empty_sections';
$this->Controller->layout = 'cache_empty_sections';
$this->Controller->viewPath = 'posts';
$View = new View($this->Controller);
$result = $View->render('cache_empty_sections');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$this->assertPattern(
'@</title>\s*</head>\s*' .
'<body>\s*' .
'View Content\s*' .
'cached count is: 3\s*' .
'</body>@', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_empty_sections.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertNoPattern('/cake:nocache/', $contents);
$this->assertPattern(
'@<head>\s*<title>Posts</title>\s*' .
'<\?php \$x \= 1; \?>\s*' .
'</head>\s*' .
'<body>\s*' .
'<\?php \$x\+\+; \?>\s*' .
'<\?php \$x\+\+; \?>\s*' .
'View Content\s*' .
'<\?php \$y = 1; \?>\s*' .
'<\?php echo \'cached count is: \' . \$x; \?>\s*' .
'@', $contents);
@unlink($filename);
} | testCacheEmptySections method
This test must be uncommented/fixed in next release (1.2+)
@return void | testCacheEmptySections | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/cache.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/cache.test.php | MIT |
function setSchema($schema) {
$this->_schema = $schema;
} | schema method
@access public
@return void | setSchema | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function setSchema($schema) {
$this->_schema = $schema;
} | schema method
@access public
@return void | setSchema | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function schema() {
$this->_schema = parent::schema();
$this->_schema['pk'] = $this->_schema['id'];
unset($this->_schema['id']);
return $this->_schema;
} | schema method
@access public
@return void | schema | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function beforeValidate() {
$this->invalidate('openid_not_registered');
return true;
} | beforeValidate method
@access public
@return void | beforeValidate | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function beforeValidate() {
$this->invalidate('email');
return false;
} | beforeValidate method
@access public
@return void | beforeValidate | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function beforeValidate() {
$this->invalidate('full_name');
$this->invalidate('city');
return false;
} | beforeValidate method
@access public
@return void | beforeValidate | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function beforeValidate() {
$this->invalidate('description');
return false;
} | beforeValidate method
@access public
@return void | beforeValidate | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function setUp() {
parent::setUp();
Router::reload();
$this->Form =& new FormHelper();
$this->Form->Html =& new HtmlHelper();
$this->Controller =& new ContactTestController();
$this->View =& new View($this->Controller);
$this->Form->params['action'] = 'add';
ClassRegistry::addObject('view', $view);
ClassRegistry::addObject('Contact', new Contact());
ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk());
ClassRegistry::addObject('OpenidUrl', new OpenidUrl());
ClassRegistry::addObject('UserForm', new UserForm());
ClassRegistry::addObject('ValidateItem', new ValidateItem());
ClassRegistry::addObject('ValidateUser', new ValidateUser());
ClassRegistry::addObject('ValidateProfile', new ValidateProfile());
$this->oldSalt = Configure::read('Security.salt');
$this->dateRegex = array(
'daysRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
'monthsRegex' => 'preg:/(?:<option value="[\d]+">[\w]+<\/option>[\r\n]*)*/',
'yearsRegex' => 'preg:/(?:<option value="([\d]+)">\\1<\/option>[\r\n]*)*/',
'hoursRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
'minutesRegex' => 'preg:/(?:<option value="([\d]+)">0?\\1<\/option>[\r\n]*)*/',
'meridianRegex' => 'preg:/(?:<option value="(am|pm)">\\1<\/option>[\r\n]*)*/',
);
Configure::write('Security.salt', 'foo!');
} | setUp method
@access public
@return void | setUp | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function tearDown() {
ClassRegistry::removeObject('view');
ClassRegistry::removeObject('Contact');
ClassRegistry::removeObject('ContactNonStandardPk');
ClassRegistry::removeObject('ContactTag');
ClassRegistry::removeObject('OpenidUrl');
ClassRegistry::removeObject('UserForm');
ClassRegistry::removeObject('ValidateItem');
ClassRegistry::removeObject('ValidateUser');
ClassRegistry::removeObject('ValidateProfile');
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
Configure::write('Security.salt', $this->oldSalt);
} | tearDown method
@access public
@return void | tearDown | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testCreateWithSecurity() {
$this->Form->params['_Token'] = array('key' => 'testKey');
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testKey', 'id'
)),
'/div'
);
$this->assertTags($result, $expected,true);
$result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
$expected['form']['id'] = 'MyForm';
$this->assertTags($result, $expected);
} | testFormCreateWithSecurity method
Test form->create() with security key.
@access public
@return void | testCreateWithSecurity | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testCreateClearingFields() {
$this->Form->fields = array('model_id');
$this->Form->create('Contact');
$this->assertEqual($this->Form->fields, array());
} | test that create() clears the fields property so it starts fresh
@return void | testCreateClearingFields | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testValidateHashNoModel() {
$this->Form->params['_Token'] = array('key' => 'foo');
$result = $this->Form->secure(array('anything'));
$this->assertPattern('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
} | Tests form hash generation with model-less data
@access public
@return void | testValidateHashNoModel | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testDuplicateFieldNameResolution() {
$result = $this->Form->create('ValidateUser');
$this->assertEqual($this->View->entity(), array('ValidateUser'));
$result = $this->Form->input('ValidateItem.name');
$this->assertEqual($this->View->entity(), array('ValidateItem', 'name'));
$result = $this->Form->input('ValidateUser.name');
$this->assertEqual($this->View->entity(), array('ValidateUser', 'name'));
$this->assertPattern('/name="data\[ValidateUser\]\[name\]"/', $result);
$this->assertPattern('/type="text"/', $result);
$result = $this->Form->input('ValidateItem.name');
$this->assertEqual($this->View->entity(), array('ValidateItem', 'name'));
$this->assertPattern('/name="data\[ValidateItem\]\[name\]"/', $result);
$this->assertPattern('/<textarea/', $result);
$result = $this->Form->input('name');
$this->assertEqual($this->View->entity(), array('ValidateUser', 'name'));
$this->assertPattern('/name="data\[ValidateUser\]\[name\]"/', $result);
$this->assertPattern('/type="text"/', $result);
} | Tests that models with identical field names get resolved properly
@access public
@return void | testDuplicateFieldNameResolution | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testNoCheckboxLocking() {
$this->Form->params['_Token'] = array('key' => 'foo');
$this->assertIdentical($this->Form->fields, array());
$this->Form->checkbox('check', array('value' => '1'));
$this->assertIdentical($this->Form->fields, array('check'));
} | Tests that hidden fields generated for checkboxes don't get locked
@access public
@return void | testNoCheckboxLocking | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecurityFields() {
$key = 'testKey';
$fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
$this->Form->params['_Token']['key'] = $key;
$result = $this->Form->secure($fields);
$expected = Security::hash(serialize($fields) . Configure::read('Security.salt'));
$expected .= ':' . 'Model.valid';
$expected = array(
'div' => array('style' => 'display:none;'),
'input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => urlencode($expected), 'id' => 'preg:/TokenFields\d+/'
),
'/div'
);
$this->assertTags($result, $expected);
} | testFormSecurityFields method
Test generation of secure form hash generation.
@access public
@return void | testFormSecurityFields | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testTextFieldGenerationForFloats() {
$model = ClassRegistry::getObject('Contact');
$model->setSchema(array('foo' => array(
'type' => 'float',
'null' => false,
'default' => null,
'length' => null
)));
$this->Form->create('Contact');
$result = $this->Form->input('foo');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][foo]',
'id' => 'ContactFoo'
)),
'/div'
);
} | Tests correct generation of text fields for double and float fields
@access public
@return void | testTextFieldGenerationForFloats | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecurityMultipleFields() {
$key = 'testKey';
$fields = array(
'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
);
$this->Form->params['_Token']['key'] = $key;
$result = $this->Form->secure($fields);
$hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
$hash .= '%7CModel.1.hidden%7CModel.1.valid';
$expected = array(
'div' => array('style' => 'display:none;'),
'input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
),
'/div'
);
$this->assertTags($result, $expected);
} | testFormSecurityMultipleFields method
Test secure() with multiple row form. Ensure hash is correct.
@access public
@return void | testFormSecurityMultipleFields | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecurityMultipleInputFields() {
$key = 'testKey';
$this->Form->params['_Token']['key'] = $key;
$this->Form->create('Addresses');
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
$this->Form->input('Addresses.0.title');
$this->Form->input('Addresses.0.first_name');
$this->Form->input('Addresses.0.last_name');
$this->Form->input('Addresses.0.address');
$this->Form->input('Addresses.0.city');
$this->Form->input('Addresses.0.phone');
$this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
$this->Form->input('Addresses.1.title');
$this->Form->input('Addresses.1.first_name');
$this->Form->input('Addresses.1.last_name');
$this->Form->input('Addresses.1.address');
$this->Form->input('Addresses.1.city');
$this->Form->input('Addresses.1.phone');
$this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
$result = $this->Form->secure($this->Form->fields);
$hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
$expected = array(
'div' => array('style' => 'display:none;'),
'input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
),
'/div'
);
$this->assertTags($result, $expected);
} | testFormSecurityMultipleInputFields method
Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
@access public
@return void | testFormSecurityMultipleInputFields | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecurityArrayFields() {
$key = 'testKey';
$this->Form->params['_Token']['key'] = $key;
$this->Form->create('Address');
$this->Form->input('Address.primary.1');
$this->assertEqual('Address.primary', $this->Form->fields[0]);
} | Test form security with Model.field.0 style inputs
@return void | testFormSecurityArrayFields | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecurityMultipleInputDisabledFields() {
$key = 'testKey';
$this->Form->params['_Token']['key'] = $key;
$this->Form->params['_Token']['disabledFields'] = array('first_name', 'address');
$this->Form->create();
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
$this->Form->input('Addresses.0.title');
$this->Form->input('Addresses.0.first_name');
$this->Form->input('Addresses.0.last_name');
$this->Form->input('Addresses.0.address');
$this->Form->input('Addresses.0.city');
$this->Form->input('Addresses.0.phone');
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
$this->Form->input('Addresses.1.title');
$this->Form->input('Addresses.1.first_name');
$this->Form->input('Addresses.1.last_name');
$this->Form->input('Addresses.1.address');
$this->Form->input('Addresses.1.city');
$this->Form->input('Addresses.1.phone');
$result = $this->Form->secure($this->Form->fields);
$hash = '774df31936dc850b7d8a5277dc0b890123788b09%3AAddresses.0.id%7CAddresses.1.id';
$expected = array(
'div' => array('style' => 'display:none;'),
'input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
),
'/div'
);
$this->assertTags($result, $expected);
} | testFormSecurityMultipleInputDisabledFields method
test secure form generation with multiple records and disabled fields.
@access public
@return void | testFormSecurityMultipleInputDisabledFields | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecurityInputDisabledFields() {
$key = 'testKey';
$this->Form->params['_Token']['key'] = $key;
$this->Form->params['_Token']['disabledFields'] = array('first_name', 'address');
$this->Form->create();
$this->Form->hidden('Addresses.id', array('value' => '123456'));
$this->Form->input('Addresses.title');
$this->Form->input('Addresses.first_name');
$this->Form->input('Addresses.last_name');
$this->Form->input('Addresses.address');
$this->Form->input('Addresses.city');
$this->Form->input('Addresses.phone');
$result = $this->Form->fields;
$expected = array(
'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
'Addresses.city', 'Addresses.phone'
);
$this->assertEqual($result, $expected);
$result = $this->Form->secure($expected);
$hash = '449b7e889128e8e52c5e81d19df68f5346571492%3AAddresses.id';
$expected = array(
'div' => array('style' => 'display:none;'),
'input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
),
'/div'
);
$this->assertTags($result, $expected);
} | testFormSecurityInputDisabledFields method
Test single record form with disabled fields.
@access public
@return void | testFormSecurityInputDisabledFields | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecureWithCustomNameAttribute() {
$this->Form->params['_Token']['key'] = 'testKey';
$this->Form->text('UserForm.published', array('name' => 'data[User][custom]'));
$this->assertEqual('User.custom', $this->Form->fields[0]);
$this->Form->text('UserForm.published', array('name' => 'data[User][custom][another][value]'));
$this->assertEqual('User.custom.another.value', $this->Form->fields[1]);
} | test securing inputs with custom name attributes.
@return void | testFormSecureWithCustomNameAttribute | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecuredInput() {
$this->Form->params['_Token']['key'] = 'testKey';
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][key]',
'value' => 'testKey', 'id' => 'preg:/Token\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('UserForm.published', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserFormPublished'),
'Published',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[UserForm][published]',
'id' => 'UserFormPublished'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('UserForm.other', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserFormOther'),
'Other',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[UserForm][other]',
'id' => 'UserFormOther'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->hidden('UserForm.stuff');
$expected = array('input' => array(
'type' => 'hidden', 'name' => 'data[UserForm][stuff]',
'id' => 'UserFormStuff'
));
$this->assertTags($result, $expected);
$result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
$expected = array('input' => array(
'type' => 'hidden', 'name' => 'data[UserForm][hidden]',
'value' => '0', 'id' => 'UserFormHidden'
));
$this->assertTags($result, $expected);
$result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
$expected = array(
'div' => array('class' => 'input checkbox'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[UserForm][something]',
'value' => '0', 'id' => 'UserFormSomething_'
)),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
'value' => '1', 'id' => 'UserFormSomething'
)),
'label' => array('for' => 'UserFormSomething'),
'Something',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->fields;
$expected = array(
'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
'UserForm.hidden' => '0', 'UserForm.something'
);
$this->assertEqual($result, $expected);
$hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff';
$result = $this->Form->secure($this->Form->fields);
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
)),
'/div'
);
$this->assertTags($result, $expected);
} | testFormSecuredInput method
Test generation of entire secure form, assertions made on input() output.
@access public
@return void | testFormSecuredInput | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecuredFileInput() {
$this->Form->params['_Token']['key'] = 'testKey';
$this->assertEqual($this->Form->fields, array());
$result = $this->Form->file('Attachment.file');
$expected = array (
'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name',
'Attachment.file.error', 'Attachment.file.size'
);
$this->assertEqual($this->Form->fields, $expected);
} | Tests that the correct keys are added to the field hash index
@access public
@return void | testFormSecuredFileInput | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecuredMultipleSelect() {
$this->Form->params['_Token']['key'] = 'testKey';
$this->assertEqual($this->Form->fields, array());
$options = array('1' => 'one', '2' => 'two');
$this->Form->select('Model.select', $options);
$expected = array('Model.select');
$this->assertEqual($this->Form->fields, $expected);
$this->Form->fields = array();
$this->Form->select('Model.select', $options, null, array('multiple' => true));
$this->assertEqual($this->Form->fields, $expected);
} | test that multiple selects keys are added to field hash
@access public
@return void | testFormSecuredMultipleSelect | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormSecuredRadio() {
$this->Form->params['_Token']['key'] = 'testKey';
$this->assertEqual($this->Form->fields, array());
$options = array('1' => 'option1', '2' => 'option2');
$this->Form->radio('Test.test', $options);
$expected = array('Test.test');
$this->assertEqual($this->Form->fields, $expected);
} | testFormSecuredRadio method
@access public
@return void | testFormSecuredRadio | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testDisableSecurityUsingForm() {
$this->Form->params['_Token']['key'] = 'testKey';
$this->Form->params['_Token']['disabledFields'] = array();
$this->Form->create();
$this->Form->hidden('Addresses.id', array('value' => '123456'));
$this->Form->input('Addresses.title');
$this->Form->input('Addresses.first_name', array('secure' => false));
$this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
$this->Form->input('Addresses.zip', array(
'type' => 'select', 'options' => array(1,2), 'secure' => false
));
$result = $this->Form->fields;
$expected = array(
'Addresses.id' => '123456', 'Addresses.title',
);
$this->assertEqual($result, $expected);
} | testDisableSecurityUsingForm method
@access public
@return void | testDisableSecurityUsingForm | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testPasswordValidation() {
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'Please provide a password',
'/div',
'/div'
);
$this->assertTags($result, $expected);
} | testPasswordValidation method
test validation errors on password input.
@access public
@return void | testPasswordValidation | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testEmptyErrorValidation() {
$this->Form->validationErrors['Contact']['password'] = '';
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
array(),
'/div',
'/div'
);
$this->assertTags($result, $expected);
} | testEmptyErrorValidation method
test validation error div when validation message is an empty string
@access public
@return void | testEmptyErrorValidation | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testEmptyInputErrorValidation() {
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
$result = $this->Form->input('Contact.password', array('error' => ''));
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
array(),
'/div',
'/div'
);
$this->assertTags($result, $expected);
} | testEmptyInputErrorValidation method
test validation error div when validation message is overriden by an empty string when calling input()
@access public
@return void | testEmptyInputErrorValidation | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormValidationAssociated() {
$this->UserForm =& ClassRegistry::getObject('UserForm');
$this->UserForm->OpenidUrl =& ClassRegistry::getObject('OpenidUrl');
$data = array(
'UserForm' => array('name' => 'user'),
'OpenidUrl' => array('url' => 'http://www.cakephp.org')
);
$this->assertTrue($this->UserForm->OpenidUrl->create($data));
$this->assertFalse($this->UserForm->OpenidUrl->validates());
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$expected = array('OpenidUrl' => array('openid_not_registered' => 1));
$this->assertEqual($this->Form->validationErrors, $expected);
$result = $this->Form->error(
'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
);
$this->assertEqual($result, 'Error, not registered');
unset($this->UserForm->OpenidUrl, $this->UserForm);
} | testFormValidationAssociated method
test display of form errors in conjunction with model::validates.
@access public
@return void | testFormValidationAssociated | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormValidationAssociatedFirstLevel() {
$this->ValidateUser =& ClassRegistry::getObject('ValidateUser');
$this->ValidateUser->ValidateProfile =& ClassRegistry::getObject('ValidateProfile');
$data = array(
'ValidateUser' => array('name' => 'mariano'),
'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
);
$this->assertTrue($this->ValidateUser->create($data));
$this->assertFalse($this->ValidateUser->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id','accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$expected = array(
'ValidateUser' => array('email' => 1),
'ValidateProfile' => array('full_name' => 1, 'city' => 1)
);
$this->assertEqual($this->Form->validationErrors, $expected);
unset($this->ValidateUser->ValidateProfile);
unset($this->ValidateUser);
} | testFormValidationAssociatedFirstLevel method
test form error display with associated model.
@access public
@return void | testFormValidationAssociatedFirstLevel | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormValidationAssociatedSecondLevel() {
$this->ValidateUser =& ClassRegistry::getObject('ValidateUser');
$this->ValidateUser->ValidateProfile =& ClassRegistry::getObject('ValidateProfile');
$this->ValidateUser->ValidateProfile->ValidateItem =& ClassRegistry::getObject('ValidateItem');
$data = array(
'ValidateUser' => array('name' => 'mariano'),
'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
'ValidateItem' => array('name' => 'Item')
);
$this->assertTrue($this->ValidateUser->create($data));
$this->assertFalse($this->ValidateUser->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id','accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$expected = array(
'ValidateUser' => array('email' => 1),
'ValidateProfile' => array('full_name' => 1, 'city' => 1),
'ValidateItem' => array('description' => 1)
);
$this->assertEqual($this->Form->validationErrors, $expected);
unset($this->ValidateUser->ValidateProfile->ValidateItem);
unset($this->ValidateUser->ValidateProfile);
unset($this->ValidateUser);
} | testFormValidationAssociatedSecondLevel method
test form error display with associated model.
@access public
@return void | testFormValidationAssociatedSecondLevel | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormValidationMultiRecord() {
$this->Form->validationErrors['Contact'] = array(2 => array(
'name' => 'This field cannot be left blank'
));
$result = $this->Form->input('Contact.2.name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array(
'type' => 'text', 'name', 'id',
'class' => 'form-error', 'maxlength' => 255
),
array('div' => array('class' => 'error-message')),
'This field cannot be left blank',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->validationErrors['UserForm'] = array(
'OpenidUrl' => array('url' => 'You must provide a URL'
));
$this->Form->create('UserForm');
$result = $this->Form->input('OpenidUrl.url');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array(
'type' => 'text', 'name', 'id', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'You must provide a URL',
'/div',
'/div'
);
} | testFormValidationMultiRecord method
test form error display with multiple records.
@access public
@return void | testFormValidationMultiRecord | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testMultipleInputValidation() {
$this->Form->create();
$this->Form->validationErrors['Address'][0]['title'] = 'This field cannot be empty';
$this->Form->validationErrors['Address'][0]['first_name'] = 'This field cannot be empty';
$this->Form->validationErrors['Address'][1]['last_name'] = 'You must have a last name';
$result = $this->Form->input('Address.0.title');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array(
'type' => 'text', 'name', 'id', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'This field cannot be empty',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.0.first_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')),
'This field cannot be empty',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.0.last_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array('type' => 'text', 'name', 'id'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Address.1.last_name');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'preg:/[^<]+/',
'/label',
'input' => array(
'type' => 'text', 'name' => 'preg:/[^<]+/',
'id' => 'preg:/[^<]+/', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'You must have a last name',
'/div',
'/div'
);
$this->assertTags($result, $expected);
} | testMultipleInputValidation method
test multiple record form validation error display.
@access public
@return void | testMultipleInputValidation | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputCheckbox() {
$result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
} | test input() with checkbox creation
@return void | testInputCheckbox | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputTime() {
extract($this->dateRegex);
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
$result = explode(':', $result);
$this->assertPattern('/option value="23"/', $result[0]);
$this->assertNoPattern('/option value="24"/', $result[0]);
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
$result = explode(':', $result);
$this->assertPattern('/option value="23"/', $result[0]);
$this->assertNoPattern('/option value="24"/', $result[0]);
$result = $this->Form->input('Model.field', array(
'type' => 'time', 'timeFormat' => 24, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$result = $this->Form->input('Model.field', array(
'type' => 'time', 'timeFormat' => 12, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$result = $this->Form->input('prueba', array(
'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
'maxYear' => date('Y') + 1 ,'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
$result = $this->Form->input('Random.start_time', array(
'type' => 'time',
'selected' => '18:15'
));
$this->assertPattern('#<option value="06"[^>]*>6</option>#', $result);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result);
$this->assertPattern('#<option value="pm"[^>]*>pm</option>#', $result);
} | test form->input() with time types. | testInputTime | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputDatetime() {
extract($this->dateRegex);
$result = $this->Form->input('prueba', array(
'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
'maxYear' => date('Y') + 1 ,'interval' => 15
));
$result = explode(':', $result);
$this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
$this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
//related to ticket #5013
$result = $this->Form->input('Contact.date', array(
'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
));
$this->assertPattern('/class="customClass"/', $result);
$this->assertPattern('/onChange="function\(\)\{\}"/', $result);
$result = $this->Form->input('Contact.date', array(
'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
));
$this->assertPattern('/id="customIdDay"/', $result);
$this->assertPattern('/id="customIdMonth"/', $result);
$this->assertPattern('/onChange="function\(\)\{\}"/', $result);
$result = $this->Form->input('Model.field', array(
'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
));
$this->assertPattern('/id="customIDDay"/', $result);
$this->assertPattern('/id="customIDHour"/', $result);
$result = explode('</select><select', $result);
$result = explode(':', $result[1]);
$this->assertPattern('/option value="23"/', $result[0]);
$this->assertNoPattern('/option value="24"/', $result[0]);
$result = $this->Form->input('Model.field', array(
'type' => 'datetime', 'timeFormat' => 12
));
$result = explode('</select><select', $result);
$result = explode(':', $result[1]);
$this->assertPattern('/option value="12"/', $result[0]);
$this->assertNoPattern('/option value="13"/', $result[0]);
$this->Form->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
$expected = array(
'div' => array('class' => 'input date'),
'label' => array('for' => 'ContactCreatedMonth'),
'Created',
'/label',
array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')),
array('option' => array('value' => '')), 'Date Unknown', '/option',
$monthsRegex,
'/select', '-',
array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')),
array('option' => array('value' => '')), 'Date Unknown', '/option',
$daysRegex,
'/select', '-',
array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')),
array('option' => array('value' => '')), 'Date Unknown', '/option',
$yearsRegex,
'/select',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
$this->assertPattern('/for\="ContactCreatedHour"/', $result);
$this->Form->data = array('Contact' => array('created' => null));
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
$this->assertPattern('/for\="ContactCreatedMonth"/', $result);
$result = $this->Form->input('Contact.created', array(
'type' => 'date',
'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
'timeFormat' => 'NONE'
));
$this->assertPattern('/for\="created-month"/', $result);
} | test form->input() with datetime, date and time types
@return void | testInputDatetime | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputCheckboxesInLoop() {
for ($i = 1; $i < 5; $i++) {
$result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"),
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")),
'label' => array('for' => "Contact{$i}Email"),
'Email',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
} | Test generating checkboxes in a loop.
@return void | testInputCheckboxesInLoop | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputWithLeadingInteger() {
$result = $this->Form->text('0.Node.title');
$expected = array(
'input' => array('name' => 'data[0][Node][title]', 'id' => '0NodeTitle', 'type' => 'text')
);
$this->assertTags($result, $expected);
} | test input name with leading integer, ensure attributes are generated correctly.
@return void | testInputWithLeadingInteger | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputWithNonStandardPrimaryKeyMakesHidden() {
$this->Form->create('User');
$this->Form->fieldset = array(
'User' => array(
'fields' => array(
'model_id' => array('type' => 'integer')
),
'validates' => array(),
'key' => 'model_id'
)
);
$result = $this->Form->input('model_id');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[User][model_id]', 'id' => 'UserModelId'),
);
$this->assertTags($result, $expected);
} | test that input() and a non standard primary key makes a hidden input by default.
@return void | testInputWithNonStandardPrimaryKeyMakesHidden | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputOverridingMagicSelectType() {
$view =& ClassRegistry::getObject('view');
$view->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.user_id', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ModelUserId'), 'User', '/label',
'input' => array('name' => 'data[Model][user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
'/div'
);
$this->assertTags($result, $expected);
//Check that magic types still work for plural/singular vars
$view =& ClassRegistry::getObject('view');
$view->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.type');
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'ModelType'), 'Type', '/label',
'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'),
array('option' => array('value' => 'value')), 'good', '/option',
array('option' => array('value' => 'other')), 'bad', '/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
} | test that overriding the magic select type widget is possible
@return void | testInputOverridingMagicSelectType | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputMagicSelectChangeToRadio() {
$view =& ClassRegistry::getObject('view');
$view->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.user_id', array('type' => 'radio'));
$this->assertPattern('/input type="radio"/', $result);
} | Test that magic input() selects can easily be converted into radio types without error.
@return void | testInputMagicSelectChangeToRadio | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testInputWithMatchingFieldAndModelName() {
$this->Form->create('User');
$this->Form->fieldset = array(
'User' => array(
'fields' => array(
'User' => array('type' => 'text')
),
'validates' => array(),
'key' => 'id'
)
);
$this->Form->data['User']['User'] = 'ABC, Inc.';
$result = $this->Form->input('User', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserUser'), 'User', '/label',
'input' => array('name' => 'data[User][User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
'/div'
);
$this->assertTags($result, $expected);
} | fields with the same name as the model should work.
@return void | testInputWithMatchingFieldAndModelName | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testFormInputs() {
$this->Form->create('Contact');
$result = $this->Form->inputs('The Legend');
$expected = array(
'<fieldset',
'<legend',
'The Legend',
'/legend',
'*/fieldset',
);
$this->assertTags($result, $expected);
$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
$expected = array(
'fieldset' => array('class' => 'classy-stuff'),
'<legend',
'Field of Dreams',
'/legend',
'*/fieldset'
);
$this->assertTags($result, $expected);
$View = ClassRegistry::getObject('view');
$this->Form->create('Contact');
$this->Form->params['prefix'] = 'admin';
$this->Form->action = 'admin_edit';
$result = $this->Form->inputs();
$expected = array(
'<fieldset',
'<legend',
'Edit Contact',
'/legend',
'*/fieldset',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(false);
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
$expected = array(
'fieldset' => array(),
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
'/fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs('Hello');
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Hello',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
'/fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('legend' => 'Hello'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Hello',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input date')),
'*/div',
array('div' => array('class' => 'input datetime')),
'*/div',
array('div' => array('class' => 'input select')),
'*/div',
'/fieldset'
);
$this->assertTags($result, $expected);
} | testFormInputs method
test correct results from form::inputs().
@access public
@return void | testFormInputs | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testSelectAsCheckbox() {
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
'second',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
array('label' => array('for' => 'ModelMultiField2')),
'third',
'/label',
'/div',
);
$this->assertTags($result, $expected);
$result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), null, array('multiple' => 'checkbox'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField12')),
array('label' => array('for' => 'ModelMultiField12')),
'half',
'/label',
'/div',
);
$this->assertTags($result, $expected);
} | testSelectAsCheckbox method
test multi-select widget with checkbox formatting.
@access public
@return void | testSelectAsCheckbox | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testLabel() {
$this->Form->text('Person.name');
$result = $this->Form->label();
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
$this->Form->text('Person.name');
$result = $this->Form->label();
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
$result = $this->Form->label('Person.first_name');
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '/label'));
$result = $this->Form->label('Person.first_name', 'Your first name');
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'Your first name', '/label'));
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '/label'));
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
$result = $this->Form->label('Person.first_name', '');
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '/label'));
$result = $this->Form->label('Person.2.name', '');
$this->assertTags($result, array('label' => array('for' => 'Person2Name'), '/label'));
} | testLabel method
test label generation.
@access public
@return void | testLabel | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testTextbox() {
$result = $this->Form->text('Model.field');
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
$result = $this->Form->text('Model.field', array('type' => 'password'));
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
$result = $this->Form->text('Model.field', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'theID')));
$this->Form->data['Model']['text'] = 'test <strong>HTML</strong> values';
$result = $this->Form->text('Model.text');
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test <strong>HTML</strong> values', 'id' => 'ModelText')));
$this->Form->validationErrors['Model']['text'] = 1;
$this->Form->data['Model']['text'] = 'test';
$result = $this->Form->text('Model.text', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
$this->Form->data['Model']['0']['OtherModel']['field'] = 'My value';
$result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
$expected = array(
'input' => array('type' => 'text', 'name' => 'data[Model][0][OtherModel][field]', 'value' => 'My value', 'id' => 'myId')
);
$this->assertTags($result, $expected);
} | testTextbox method
test textbox element generation
@access public
@return void | testTextbox | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
function testDefaultValue() {
$this->Form->data['Model']['field'] = 'test';
$result = $this->Form->text('Model.field', array('default' => 'default value'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'test', 'id' => 'ModelField')));
unset($this->Form->data['Model']['field']);
$result = $this->Form->text('Model.field', array('default' => 'default value'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));
} | testDefaultValue method
Test default value setting
@access public
@return void | testDefaultValue | php | Datawalke/Coordino | cake/tests/cases/libs/view/helpers/form.test.php | https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.