mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Applying patch from 'mete0r', adding tests for Scaffold variable setting. Fixes #6361
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8172 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
cd90f8c74b
commit
8c243ee731
2 changed files with 48 additions and 9 deletions
|
@ -161,8 +161,8 @@ class Scaffold extends Object {
|
|||
$displayField = $this->ScaffoldModel->displayField;
|
||||
$singularVar = Inflector::variable($modelClass);
|
||||
$pluralVar = Inflector::variable($this->controller->name);
|
||||
$singularHumanName = Inflector::humanize($modelClass);
|
||||
$pluralHumanName = Inflector::humanize($this->controller->name);
|
||||
$singularHumanName = Inflector::humanize(Inflector::underscore($modelClass));
|
||||
$pluralHumanName = Inflector::humanize(Inflector::underscore($this->controller->name));
|
||||
$scaffoldFields = array_keys($this->ScaffoldModel->schema());
|
||||
$associations = $this->__associations();
|
||||
|
||||
|
|
|
@ -332,11 +332,11 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('#<h2>ScaffoldMock</h2>#', $result);
|
||||
$this->assertPattern('#<h2>Scaffold Mock</h2>#', $result);
|
||||
$this->assertPattern('#<table cellpadding="0" cellspacing="0">#', $result);
|
||||
//TODO: add testing for table generation
|
||||
$this->assertPattern('#<a href="/scaffold_users/view/1">1</a>#', $result); //belongsTo links
|
||||
$this->assertPattern('#<li><a href="/scaffold_mock/add/">New ScaffoldMock</a></li>#', $result);
|
||||
$this->assertPattern('#<li><a href="/scaffold_mock/add/">New Scaffold Mock</a></li>#', $result);
|
||||
$this->assertPattern('#<li><a href="/scaffold_users/">List Scaffold Users</a></li>#', $result);
|
||||
$this->assertPattern('#<li><a href="/scaffold_comments/add/">New Comment</a></li>#', $result);
|
||||
}
|
||||
|
@ -371,12 +371,12 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>View ScaffoldMock<\/h2>/', $result);
|
||||
$this->assertPattern('/<h2>View Scaffold Mock<\/h2>/', $result);
|
||||
$this->assertPattern('/<dl>/', $result);
|
||||
//TODO: add specific tests for fields.
|
||||
$this->assertPattern('/<a href="\/scaffold_users\/view\/1">1<\/a>/', $result); //belongsTo links
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/edit\/1">Edit ScaffoldMock<\/a>\s<\/li>/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete ScaffoldMock<\/a>\s*<\/li>/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/edit\/1">Edit Scaffold Mock<\/a>\s<\/li>/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete Scaffold Mock<\/a>\s*<\/li>/', $result);
|
||||
//check related table
|
||||
$this->assertPattern('/<div class="related">\s*<h3>Related Scaffold Comments<\/h3>\s*<table cellpadding="0" cellspacing="0">/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_comments\/add\/">New Comment<\/a><\/li>/', $result);
|
||||
|
@ -459,10 +459,10 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
$Scaffold = new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>ScaffoldMock<\/h2>/', $result);
|
||||
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
|
||||
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
|
||||
//TODO: add testing for table generation
|
||||
$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add\/">New ScaffoldMock<\/a><\/li>/', $result);
|
||||
$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add\/">New Scaffold Mock<\/a><\/li>/', $result);
|
||||
|
||||
Configure::write('Routing.admin', $_backAdmin);
|
||||
}
|
||||
|
@ -580,5 +580,44 @@ class ScaffoldTest extends CakeTestCase {
|
|||
$result = $Scaffold->getParams();
|
||||
$this->assertEqual($result['action'], 'admin_edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the proper names and variable values are set by Scaffold
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testScaffoldVariableSetting() {
|
||||
$this->Controller->action = 'admin_edit';
|
||||
$this->Controller->here = '/admin/scaffold_mock/edit';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'admin/scaffold_mock/edit'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'admin_edit',
|
||||
'admin' => true,
|
||||
);
|
||||
//set router.
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => 'admin/scaffold_mock', 'webroot' => '/')));
|
||||
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
$Scaffold =& new TestScaffoldMock($this->Controller, $params);
|
||||
$result = $this->Controller->viewVars;
|
||||
|
||||
$this->assertEqual($result['singularHumanName'], 'Scaffold Mock');
|
||||
$this->assertEqual($result['pluralHumanName'], 'Scaffold Mock');
|
||||
$this->assertEqual($result['modelClass'], 'ScaffoldMock');
|
||||
$this->assertEqual($result['primaryKey'], 'id');
|
||||
$this->assertEqual($result['displayField'], 'title');
|
||||
$this->assertEqual($result['singularVar'], 'scaffoldMock');
|
||||
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
|
||||
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue