Permalink
Browse files

Applying patch from 'mete0r', adding tests for Scaffold variable sett…

…ing. Fixes #6361

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8172 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent cd90f8c commit 8c243ee7312067f82077908e88fb3a7b8a4696ce @markstory markstory committed May 13, 2009
Showing with 48 additions and 9 deletions.
  1. +2 −2 cake/libs/controller/scaffold.php
  2. +46 −7 cake/tests/cases/libs/controller/scaffold.test.php
@@ -161,8 +161,8 @@ function __construct(&$controller, $params) {
$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 @@ function testIndexScaffold() {
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 @@ function testViewScaffold() {
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 @@ function testAdminIndexScaffold() {
$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 @@ function testScaffoldParams() {
$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'));
+ }
}
?>

0 comments on commit 8c243ee

Please sign in to comment.