Correcting duplicate class defines in the test cases that was causing tests to fail.

Added Router::reload(); to ViewTest::setUp()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5341 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-06-23 07:44:39 +00:00
parent 90299c0d0e
commit 65cdc377a6
3 changed files with 174 additions and 289 deletions

View file

@ -26,42 +26,38 @@
* @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);
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
require_once LIBS.'../app_helper.php';
require_once LIBS.DS.'model'.DS.'model.php';
require_once LIBS.DS.'view'.DS.'helper.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'ajax.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'html.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'form.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'javascript.php';
require_once LIBS.DS.'controller'.DS.'controller.php';
class AjaxTestController extends Controller {
var $name = 'AjaxTest';
var $uses = null;
}
class PostAjaxTest extends Model {
var $primaryKey = 'id';
var $useTable = false;
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)));
}
}
require_once LIBS.'../app_helper.php';
require_once LIBS.DS.'model'.DS.'model.php';
require_once LIBS.DS.'view'.DS.'helper.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'ajax.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'html.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'form.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'javascript.php';
require_once LIBS.DS.'controller'.DS.'controller.php';
if (!class_exists('TheTestController')) {
class TheTestController extends Controller {
var $name = 'TheTest';
var $uses = null;
}
}
if (!class_exists('Post')) {
class Post extends Model {
var $primaryKey = 'id';
var $useTable = false;
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
));
}
}
}
/**
* Short description for class.
@ -77,9 +73,9 @@ class AjaxTest extends UnitTestCase {
$this->Ajax->Form = new FormHelper();
$this->Ajax->Javascript = new JavascriptHelper();
$this->Ajax->Form->Html =& $this->Ajax->Html;
$view = new View(new TheTestController());
$view = new View(new AjaxTestController());
ClassRegistry::addObject('view', $view);
ClassRegistry::addObject('Post', new Post());
ClassRegistry::addObject('PostAjaxTest', new PostAjaxTest());
}
function testEvalScripts() {
@ -93,12 +89,12 @@ class AjaxTest extends UnitTestCase {
}
function testAutoComplete() {
$result = $this->Ajax->autoComplete('Post/title' , '/posts', array('minChars' => 2));
$result = $this->Ajax->autoComplete('PostAjaxTest/title' , '/posts', array('minChars' => 2));
$this->assertPattern('/^<input[^<>]+name="data\[Post\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result);
$this->assertPattern('/<div[^<>]+id="PostTitle_autoComplete"[^<>]*><\/div>/', $result);
$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">new Ajax\.Autocompleter\(\'PostTitle\', \'PostTitle_autoComplete\', \'\/posts\',/', $result);
$this->assertPattern('/<\/div>\s+<script type="text\/javascript">new Ajax\.Autocompleter\(\'PostAjaxTestTitle\', \'PostAjaxTestTitle_autoComplete\', \'\/posts\',/', $result);
$this->assertPattern('/<script(.*)>(.*) {minChars:2}\);/', $result);
$this->assertPattern('/<\/script>$/', $result);
}

View file

@ -26,204 +26,139 @@
* @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);
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
require_once LIBS.'../app_helper.php';
require_once LIBS.'class_registry.php';
require_once LIBS.DS.'view'.DS.'view.php';
require_once LIBS.DS.'view'.DS.'helper.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'html.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'form.php';
require_once LIBS.DS.'controller'.DS.'controller.php';
require_once LIBS.DS.'model'.DS.'model.php';
class ContactTestController extends Controller {
var $name = 'ContactTest';
var $uses = null;
}
class Contact extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'Contact';
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'published', 'type' => 'date', 'null' => true, 'default' => null, 'length' => null),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)));
}
}
class UserForm extends Model {
var $useTable = false;
var $primaryKey = 'id';
var $name = 'UserForm';
var $hasMany = array('OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id'));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)));
}
}
class OpenidUrl extends Model {
var $useTable = false;
var $primaryKey = 'id';
var $name = 'OpenidUrl';
var $belongsTo = array('UserForm' => array('className' => 'UserForm', 'foreignKey' => 'user_form_id'));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'user_form_id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'url', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),));
}
require_once LIBS.'../app_helper.php';
require_once LIBS.'class_registry.php';
require_once LIBS.DS.'view'.DS.'view.php';
require_once LIBS.DS.'view'.DS.'helper.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'html.php';
require_once LIBS.DS.'view'.DS.'helpers'.DS.'form.php';
require_once LIBS.DS.'controller'.DS.'controller.php';
require_once LIBS.DS.'model'.DS.'model.php';
function beforeValidate() {
$this->invalidate('openid_not_registered');
return true;
}
}
if (!class_exists('TheTestController')) {
class TheTestController extends Controller {
var $name = 'TheTest';
var $uses = null;
}
class ValidateUser extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'ValidateUser';
var $hasOne = array('ValidateProfile' => array('className' => 'ValidateProfile', 'foreignKey' => 'user_id'));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'email', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)));
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
*/
class Contact extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'Contact';
function beforeValidate() {
$this->invalidate('email');
return false;
}
}
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'published', 'type' => 'date', 'null' => true, 'default' => null, 'length' => null),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
));
}
class ValidateProfile extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'ValidateProfile';
var $hasOne = array('ValidateItem' => array('className' => 'ValidateItem', 'foreignKey' => 'profile_id'));
var $belongsTo = array('ValidateUser' => array('className' => 'ValidateUser', 'foreignKey' => 'user_id'));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'user_id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'full_name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'city', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)));
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
*/
class UserForm extends Model {
var $useTable = false;
var $primaryKey = 'id';
var $name = 'UserForm';
function beforeValidate() {
$this->invalidate('full_name');
$this->invalidate('city');
return false;
}
}
var $hasMany = array('OpenidUrl' => array(
'className' => 'OpenidUrl',
'foreignKey' => 'user_form_id'
));
class ValidateItem extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'ValidateItem';
var $belongsTo = array('ValidateProfile' => array('className' => 'ValidateProfile', 'foreignKey' => 'profile_id'));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
));
}
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'profile_id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'description', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)));
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
*/
class OpenidUrl extends Model {
var $useTable = false;
var $primaryKey = 'id';
var $name = 'OpenidUrl';
var $belongsTo = array('UserForm' => array(
'className' => 'UserForm',
'foreignKey' => 'user_form_id'
));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'user_form_id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'url', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
));
}
function beforeValidate() {
$this->invalidate('openid_not_registered');
return true;
}
function beforeValidate() {
$this->invalidate('description');
return false;
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
*/
class ValidateUser extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'ValidateUser';
var $hasOne = array('ValidateProfile' => array(
'className' => 'ValidateProfile',
'foreignKey' => 'user_id'
));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'email', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
));
}
function beforeValidate() {
$this->invalidate('email');
return false;
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
*/
class ValidateProfile extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'ValidateProfile';
var $hasOne = array('ValidateItem' => array(
'className' => 'ValidateItem',
'foreignKey' => 'profile_id'
));
var $belongsTo = array('ValidateUser' => array(
'className' => 'ValidateUser',
'foreignKey' => 'user_id'
));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'user_id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'full_name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'city', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
));
}
function beforeValidate() {
$this->invalidate('full_name');
$this->invalidate('city');
return false;
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
*/
class ValidateItem extends Model {
var $primaryKey = 'id';
var $useTable = false;
var $name = 'ValidateItem';
var $belongsTo = array('ValidateProfile' => array(
'className' => 'ValidateProfile',
'foreignKey' => 'profile_id'
));
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'profile_id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'description', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
array('name' => 'created', 'type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
array('name' => 'updated', 'type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
));
}
function beforeValidate() {
$this->invalidate('description');
return false;
}
}
}
/**
* Short description for class.
*
@ -235,7 +170,7 @@ class FormHelperTest extends CakeTestCase {
function startTest($method) {
$this->Form =& new FormHelper();
$this->Form->Html =& new HtmlHelper();
$this->Controller =& new TheTestController();
$this->Controller =& new ContactTestController();
$this->View =& new View($this->Controller);
ClassRegistry::addObject('view', $view);
ClassRegistry::addObject('Contact', new Contact());
@ -254,14 +189,8 @@ class FormHelperTest extends CakeTestCase {
$this->UserForm =& new UserForm();
$this->UserForm->OpenidUrl =& new OpenidUrl();
$data = array(
'UserForm' => array(
'name' => 'user'
),
'OpenidUrl' => array(
'url' => 'http://www.cricava.com'
)
);
$data = array('UserForm' => array('name' => 'user'),
'OpenidUrl' => array('url' => 'http://www.cakephp.org'));
$result = $this->UserForm->OpenidUrl->create($data);
$this->assertTrue($result);
@ -272,12 +201,7 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/user_forms\/login\/"[^>]*>$/', $result);
$expected = array(
'OpenidUrl' => array(
'openid_not_registered' => 1
)
);
$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));
@ -291,14 +215,8 @@ class FormHelperTest extends CakeTestCase {
$this->ValidateUser =& new ValidateUser();
$this->ValidateUser->ValidateProfile =& new ValidateProfile();
$data = array(
'ValidateUser' => array(
'name' => 'mariano'
),
'ValidateProfile' => array(
'full_name' => 'Mariano Iglesias'
)
);
$data = array('ValidateUser' => array('name' => 'mariano'),
'ValidateProfile' => array('full_name' => 'Mariano Iglesias'));
$result = $this->ValidateUser->create($data);
$this->assertTrue($result);
@ -312,18 +230,9 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*>$/', $result);
$expected = array(
'OpenidUrl' => array(
'openid_not_registered' => 1
),
'ValidateUser' => array(
'email' => 1
),
'ValidateProfile' => array(
'full_name' => 1,
'city' => 1
)
);
$expected = array('OpenidUrl' => array('openid_not_registered' => 1),
'ValidateUser' => array('email' => 1),
'ValidateProfile' => array('full_name' => 1, 'city' => 1));
$this->assertEqual($this->Form->validationErrors, $expected);
@ -336,17 +245,9 @@ class FormHelperTest extends CakeTestCase {
$this->ValidateUser->ValidateProfile =& new ValidateProfile();
$this->ValidateUser->ValidateProfile->ValidateItem =& new ValidateItem();
$data = array(
'ValidateUser' => array(
'name' => 'mariano'
),
'ValidateProfile' => array(
'full_name' => 'Mariano Iglesias'
),
'ValidateItem' => array(
'name' => 'Item'
)
);
$data = array('ValidateUser' => array('name' => 'mariano'),
'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
'ValidateItem' => array('name' => 'Item'));
$result = $this->ValidateUser->create($data);
$this->assertTrue($result);
@ -363,21 +264,10 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*>$/', $result);
$expected = array(
'OpenidUrl' => array(
'openid_not_registered' => 1
),
'ValidateUser' => array(
'email' => 1
),
'ValidateProfile' => array(
'full_name' => 1,
'city' => 1
),
'ValidateItem' => array(
'description' => 1
)
);
$expected = array('OpenidUrl' => array('openid_not_registered' => 1),
'ValidateUser' => array('email' => 1),
'ValidateProfile' => array('full_name' => 1, 'city' => 1),
'ValidateItem' => array('description' => 1));
$this->assertEqual($this->Form->validationErrors, $expected);
@ -853,5 +743,4 @@ class FormHelperTest extends CakeTestCase {
unset($this->Form);
}
}
?>
?>

View file

@ -48,6 +48,7 @@
class ViewTest extends UnitTestCase {
function setUp() {
Router::reload();
$this->PostsController = new PostsController();
$this->PostsController->index();
$this->view = new View($this->PostsController);
@ -80,5 +81,4 @@ class ViewTest extends UnitTestCase {
unset($this->PostsController);
}
}
?>