Skip to content
This repository
Browse code

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...
commit 8c243ee7312067f82077908e88fb3a7b8a4696ce 1 parent cd90f8c
Mark Story authored May 13, 2009
4  cake/libs/controller/scaffold.php
@@ -161,8 +161,8 @@ function __construct(&$controller, $params) {
161 161
 		$displayField = $this->ScaffoldModel->displayField;
162 162
 		$singularVar = Inflector::variable($modelClass);
163 163
 		$pluralVar = Inflector::variable($this->controller->name);
164  
-		$singularHumanName = Inflector::humanize($modelClass);
165  
-		$pluralHumanName = Inflector::humanize($this->controller->name);
  164
+		$singularHumanName = Inflector::humanize(Inflector::underscore($modelClass));
  165
+		$pluralHumanName = Inflector::humanize(Inflector::underscore($this->controller->name));
166 166
 		$scaffoldFields = array_keys($this->ScaffoldModel->schema());
167 167
 		$associations = $this->__associations();
168 168
 
53  cake/tests/cases/libs/controller/scaffold.test.php
@@ -332,11 +332,11 @@ function testIndexScaffold() {
332 332
 		new Scaffold($this->Controller, $params);
333 333
 		$result = ob_get_clean();
334 334
 
335  
-		$this->assertPattern('#<h2>ScaffoldMock</h2>#', $result);
  335
+		$this->assertPattern('#<h2>Scaffold Mock</h2>#', $result);
336 336
 		$this->assertPattern('#<table cellpadding="0" cellspacing="0">#', $result);
337 337
 		//TODO: add testing for table generation
338 338
 		$this->assertPattern('#<a href="/scaffold_users/view/1">1</a>#', $result); //belongsTo links
339  
-		$this->assertPattern('#<li><a href="/scaffold_mock/add/">New ScaffoldMock</a></li>#', $result);
  339
+		$this->assertPattern('#<li><a href="/scaffold_mock/add/">New Scaffold Mock</a></li>#', $result);
340 340
 		$this->assertPattern('#<li><a href="/scaffold_users/">List Scaffold Users</a></li>#', $result);
341 341
 		$this->assertPattern('#<li><a href="/scaffold_comments/add/">New Comment</a></li>#', $result);
342 342
 	}
@@ -371,12 +371,12 @@ function testViewScaffold() {
371 371
 		new Scaffold($this->Controller, $params);
372 372
 		$result = ob_get_clean();
373 373
 
374  
-		$this->assertPattern('/<h2>View ScaffoldMock<\/h2>/', $result);
  374
+		$this->assertPattern('/<h2>View Scaffold Mock<\/h2>/', $result);
375 375
 		$this->assertPattern('/<dl>/', $result);
376 376
 		//TODO: add specific tests for fields.
377 377
 		$this->assertPattern('/<a href="\/scaffold_users\/view\/1">1<\/a>/', $result); //belongsTo links
378  
-		$this->assertPattern('/<li><a href="\/scaffold_mock\/edit\/1">Edit ScaffoldMock<\/a>\s<\/li>/', $result);
379  
-		$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete ScaffoldMock<\/a>\s*<\/li>/', $result);
  378
+		$this->assertPattern('/<li><a href="\/scaffold_mock\/edit\/1">Edit Scaffold Mock<\/a>\s<\/li>/', $result);
  379
+		$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete Scaffold Mock<\/a>\s*<\/li>/', $result);
380 380
 		//check related table
381 381
 		$this->assertPattern('/<div class="related">\s*<h3>Related Scaffold Comments<\/h3>\s*<table cellpadding="0" cellspacing="0">/', $result);
382 382
 		$this->assertPattern('/<li><a href="\/scaffold_comments\/add\/">New Comment<\/a><\/li>/', $result);
@@ -459,10 +459,10 @@ function testAdminIndexScaffold() {
459 459
 		$Scaffold = new Scaffold($this->Controller, $params);
460 460
 		$result = ob_get_clean();
461 461
 
462  
-		$this->assertPattern('/<h2>ScaffoldMock<\/h2>/', $result);
  462
+		$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
463 463
 		$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
464 464
 		//TODO: add testing for table generation
465  
-		$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add\/">New ScaffoldMock<\/a><\/li>/', $result);
  465
+		$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add\/">New Scaffold Mock<\/a><\/li>/', $result);
466 466
 
467 467
 		Configure::write('Routing.admin', $_backAdmin);
468 468
 	}
@@ -580,5 +580,44 @@ function testScaffoldParams() {
580 580
 		$result = $Scaffold->getParams();
581 581
 		$this->assertEqual($result['action'], 'admin_edit');
582 582
 	}
  583
+
  584
+/**
  585
+ * test that the proper names and variable values are set by Scaffold
  586
+ *
  587
+ * @return void
  588
+ **/
  589
+	function testScaffoldVariableSetting() {
  590
+		$this->Controller->action = 'admin_edit';
  591
+		$this->Controller->here = '/admin/scaffold_mock/edit';
  592
+		$this->Controller->webroot = '/';
  593
+		$params = array(
  594
+			'plugin' => null,
  595
+			'pass' => array(),
  596
+			'form' => array(),
  597
+			'named' => array(),
  598
+			'url' => array('url' =>'admin/scaffold_mock/edit'),
  599
+			'controller' => 'scaffold_mock',
  600
+			'action' => 'admin_edit',
  601
+			'admin' => true,
  602
+		);
  603
+		//set router.
  604
+		Router::setRequestInfo(array($params, array('base' => '/', 'here' => 'admin/scaffold_mock', 'webroot' => '/')));
  605
+
  606
+		$this->Controller->params = $params;
  607
+		$this->Controller->controller = 'scaffold_mock';
  608
+		$this->Controller->base = '/';
  609
+		$this->Controller->constructClasses();
  610
+		$Scaffold =& new TestScaffoldMock($this->Controller, $params);
  611
+		$result = $this->Controller->viewVars;
  612
+
  613
+		$this->assertEqual($result['singularHumanName'], 'Scaffold Mock');
  614
+		$this->assertEqual($result['pluralHumanName'], 'Scaffold Mock');
  615
+		$this->assertEqual($result['modelClass'], 'ScaffoldMock');
  616
+		$this->assertEqual($result['primaryKey'], 'id');
  617
+		$this->assertEqual($result['displayField'], 'title');
  618
+		$this->assertEqual($result['singularVar'], 'scaffoldMock');
  619
+		$this->assertEqual($result['pluralVar'], 'scaffoldMock');
  620
+		$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
  621
+	}
583 622
 }
584 623
 ?>

0 notes on commit 8c243ee

Please sign in to comment.
Something went wrong with that request. Please try again.