* Copyright 2005-2008, Cake Software Foundation, Inc. * 1785 E. Sahara Avenue, Suite 490-204 * Las Vegas, Nevada 89104 * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package cake.tests * @subpackage cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { define('CAKEPHP_UNIT_TEST_EXECUTION', 1); } uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'ajax', 'view'.DS.'helpers'.DS.'html', 'view'.DS.'helpers'.DS.'form', 'view'.DS.'helpers'.DS.'javascript'); class AjaxTestController extends Controller { var $name = 'AjaxTest'; var $uses = null; } class PostAjaxTest extends Model { var $primaryKey = 'id'; var $useTable = false; 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) ); } } class TestAjaxHelper extends AjaxHelper { function stop() { } } class TestJavascriptHelper extends JavascriptHelper { var $codeBlocks; function codeBlock($parameter) { if (empty($this->codeBlocks)) { $this->codeBlocks = array(); } $this->codeBlocks[] = $parameter; } } /** * Short description for class. * * @package cake.tests * @subpackage cake.tests.cases.libs.view.helpers */ class AjaxTest extends CakeTestCase { 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()); } function testEvalScripts() { $result = $this->Ajax->link('Test Link', 'http://www.cakephp.org', array('id' => 'link1', 'update' => 'content', 'evalScripts' => false)); $this->assertPattern('/^]+>Test Link<\/a>]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); $this->assertPattern('/^]*href="http:\/\/www.cakephp.org"[^<>]*>/', $result); $this->assertPattern('/^]*id="link1"[^<>]*>/', $result); $this->assertPattern('/^]*onclick="\s*' . str_replace('/', '\\/', preg_quote('event.returnValue = false; return false;')) . '\s*"[^<>]*>/', $result); $result = $this->Ajax->link('Test Link', 'http://www.cakephp.org', array('id' => 'link1', 'update' => 'content')); $this->assertPattern('/^]+>Test Link<\/a>]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); $this->assertPattern('/^]*href="http:\/\/www.cakephp.org"[^<>]*>/', $result); $this->assertPattern('/^]*id="link1"[^<>]*>/', $result); $this->assertPattern('/^]*onclick="\s*' . str_replace('/', '\\/', preg_quote('event.returnValue = false; return false;')) . '\s*"[^<>]*>/', $result); } function testAutoComplete() { $result = $this->Ajax->autoComplete('PostAjaxTest.title' , '/posts', array('minChars' => 2)); $this->assertPattern('/^]+name="data\[PostAjaxTest\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result); $this->assertPattern('/]+id="PostAjaxTestTitle_autoComplete"[^<>]*><\/div>/', $result); $this->assertPattern('/]+class="auto_complete"[^<>]*><\/div>/', $result); $this->assertPattern('/<\/div>\s+