* 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'); /** * AjaxTestController class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class AjaxTestController extends Controller { /** * name property * * @var string 'AjaxTest' * @access public */ var $name = 'AjaxTest'; /** * uses property * * @var mixed null * @access public */ var $uses = null; } /** * PostAjaxTest class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class PostAjaxTest extends Model { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * schema method * * @access public * @return void */ 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) ); } } /** * TestAjaxHelper class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class TestAjaxHelper extends AjaxHelper { /** * stop method * * @access public * @return void */ function stop() { } } /** * TestJavascriptHelper class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class TestJavascriptHelper extends JavascriptHelper { /** * codeBlocks property * * @var mixed * @access public */ var $codeBlocks; /** * codeBlock method * * @param mixed $parameter * @access public * @return void */ 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 { /** * setUp method * * @access public * @return void */ 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()); } /** * testEvalScripts method * * @access public * @return void */ 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); } /** * testAutoComplete method * * @access public * @return void */ 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+