diff --git a/lib/Cake/Test/TestApp/Controller/ScaffoldArticlesController.php b/lib/Cake/Test/TestApp/Controller/ScaffoldArticlesController.php new file mode 100644 index 00000000000..31b13528151 --- /dev/null +++ b/lib/Cake/Test/TestApp/Controller/ScaffoldArticlesController.php @@ -0,0 +1,38 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @since CakePHP(tm) v 3.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +namespace TestApp\Controller; + +use Cake\Controller\Controller; + +/** + * ScaffoldArticlesController class + * + * @package TestApp.Controller + */ +class ScaffoldArticlesController extends Controller { + +/** + * name property + * + * @var string + */ + public $name = 'Articles'; + +/** + * scaffold property + * + * @var mixed + */ + public $scaffold; +} diff --git a/lib/Cake/Test/TestApp/Model/Article.php b/lib/Cake/Test/TestApp/Model/Article.php new file mode 100644 index 00000000000..3b100b205c3 --- /dev/null +++ b/lib/Cake/Test/TestApp/Model/Article.php @@ -0,0 +1,93 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @since CakePHP(tm) v 3.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +namespace TestApp\Model; + +use Cake\TestSuite\Fixture\TestModel; + +/** + * Article class + * + * @package TestApp.Model + */ +class Article extends TestModel { + +/** + * name property + * + * @var string 'Article' + */ + public $name = 'Article'; + +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); + +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Comment' => array('dependent' => true)); + +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Tag'); + +/** + * validate property + * + * @var array + */ + public $validate = array( + 'user_id' => 'numeric', + 'title' => array('required' => false, 'rule' => 'notEmpty'), + 'body' => array('required' => false, 'rule' => 'notEmpty'), + ); + +/** + * beforeSaveReturn property + * + * @var bool true + */ + public $beforeSaveReturn = true; + +/** + * beforeSave method + * + * @return void + */ + public function beforeSave($options = array()) { + return $this->beforeSaveReturn; + } + +/** + * titleDuplicate method + * + * @param string $title + * @return void + */ + public static function titleDuplicate($title) { + if ($title === 'My Article Title') { + return false; + } + return true; + } + +} diff --git a/lib/Cake/Test/TestCase/View/ScaffoldViewTest.php b/lib/Cake/Test/TestCase/View/ScaffoldViewTest.php index 74e2c836838..15909eef75e 100644 --- a/lib/Cake/Test/TestCase/View/ScaffoldViewTest.php +++ b/lib/Cake/Test/TestCase/View/ScaffoldViewTest.php @@ -1,9 +1,5 @@ * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @@ -12,11 +8,11 @@ * * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @package Cake.Test.Case.Controller * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ namespace Cake\Test\TestCase\View; + use Cake\Controller\Controller; use Cake\Controller\Scaffold; use Cake\Core\App; @@ -26,8 +22,10 @@ use Cake\Routing\Router; use Cake\TestSuite\TestCase; use Cake\View\ScaffoldView; +use TestApp\Controller\ScaffoldArticlesController; require_once dirname(__DIR__) . DS . 'Model/models.php'; + if (!class_exists('Cake\Model\ScaffoldMock')) { class_alias('Cake\Test\TestCase\Model\ScaffoldMock', 'Cake\Model\ScaffoldMock'); } @@ -35,7 +33,7 @@ class_alias('Cake\Test\TestCase\Model\ScaffoldMock', 'Cake\Model\ScaffoldMock'); /** * TestScaffoldView class * - * @package Cake.Test.Case.Controller + * @package Cake.Test.TestCase.View */ class TestScaffoldView extends ScaffoldView { @@ -51,32 +49,11 @@ public function testGetFilename($action) { } -/** - * ScaffoldViewMockController class - * - * @package Cake.Test.Case.Controller - */ -class ScaffoldViewMockController extends Controller { - -/** - * name property - * - * @var string 'ScaffoldMock' - */ - public $name = 'ScaffoldMock'; - -/** - * scaffold property - * - * @var mixed - */ - public $scaffold; -} /** * ScaffoldViewTest class * - * @package Cake.Test.Case.Controller + * @package Cake.Test.TestCase.View */ class ScaffoldViewTest extends TestCase { @@ -85,7 +62,13 @@ class ScaffoldViewTest extends TestCase { * * @var array */ - public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag'); + public $fixtures = [ + 'core.article', + 'core.user', + 'core.comment', + 'core.articles_tag', + 'core.tag' + ]; /** * setUp method @@ -94,8 +77,13 @@ class ScaffoldViewTest extends TestCase { */ public function setUp() { parent::setUp(); + Configure::write('App.namespace', 'TestApp'); + + Router::connect('/:controller/:action/*'); + Router::connect('/:controller', ['action' => 'index']); + $this->request = new Request(); - $this->Controller = new ScaffoldViewMockController($this->request); + $this->Controller = new ScaffoldArticlesController($this->request); $this->Controller->response = $this->getMock('Cake\Network\Response', array('_sendHeader')); App::build(array( @@ -121,7 +109,6 @@ public function tearDown() { * @return void */ public function testGetViewFilename() { - $_admin = Configure::read('Routing.prefixes'); Configure::write('Routing.prefixes', array('admin')); $this->Controller->request->params['action'] = 'index'; @@ -162,7 +149,7 @@ public function testGetViewFilename() { $expected = CAKE . 'View/Errors/scaffold_error.ctp'; $this->assertEquals($expected, $result); - $Controller = new ScaffoldViewMockController($this->request); + $Controller = new ScaffoldArticlesController($this->request); $Controller->scaffold = 'admin'; $Controller->viewPath = 'Posts'; $Controller->request['action'] = 'admin_edit'; @@ -176,7 +163,7 @@ public function testGetViewFilename() { $expected = CAKE . 'Test/TestApp/View/Posts/scaffold.form.ctp'; $this->assertEquals($expected, $result); - $Controller = new ScaffoldViewMockController($this->request); + $Controller = new ScaffoldArticlesController($this->request); $Controller->scaffold = 'admin'; $Controller->viewPath = 'Tests'; $Controller->request->addParams(array( @@ -196,8 +183,6 @@ public function testGetViewFilename() { $expected = CAKE . 'Test/TestApp/Plugin' . DS . 'TestPlugin/View/Tests/scaffold.form.ctp'; $this->assertEquals($expected, $result); - - Configure::write('Routing.prefixes', $_admin); } /** @@ -223,20 +208,18 @@ public function testGetViewFileNameWithTheme() { * @return void */ public function testIndexScaffold() { - $params = array( + $params = [ 'plugin' => null, - 'pass' => array(), - 'controller' => 'scaffold_mock', + 'pass' => [], + 'controller' => 'articles', 'action' => 'index', - ); + ]; $this->Controller->request->addParams($params); $this->Controller->request->webroot = '/'; $this->Controller->request->base = ''; - $this->Controller->request->here = '/scaffold_mock/index'; + $this->Controller->request->here = '/articles/index'; - //set router. - Router::reload(); - Router::setRequestInfo($this->Controller->request); + Router::pushRequest($this->Controller->request); $this->Controller->constructClasses(); ob_start(); @@ -244,13 +227,13 @@ public function testIndexScaffold() { $this->Controller->response->send(); $result = ob_get_clean(); - $this->assertRegExp('#

Scaffold Mock

#', $result); + $this->assertRegExp('#

Articles

#', $result); $this->assertRegExp('##', $result); - $this->assertRegExp('#1#', $result); //belongsTo links - $this->assertRegExp('#
  • New Scaffold Mock
  • #', $result); - $this->assertRegExp('#
  • List Scaffold Users
  • #', $result); - $this->assertRegExp('#
  • New Comment
  • #', $result); + $this->assertRegExp('#1#', $result); //belongsTo links + $this->assertRegExp('#
  • New Article
  • #', $result); + $this->assertRegExp('#
  • List Users
  • #', $result); + $this->assertRegExp('#
  • New Comment
  • #', $result); } /** @@ -260,19 +243,17 @@ public function testIndexScaffold() { */ public function testViewScaffold() { $this->Controller->request->base = ''; - $this->Controller->request->here = '/scaffold_mock'; $this->Controller->request->webroot = '/'; - $params = array( + $params = [ 'plugin' => null, - 'pass' => array(1), - 'controller' => 'scaffold_mock', + 'pass' => [1], + 'controller' => 'articles', 'action' => 'view', - ); + ]; $this->Controller->request->addParams($params); //set router. - Router::reload(); - Router::setRequestInfo($this->Controller->request); + Router::pushRequest($this->Controller->request); $this->Controller->constructClasses(); ob_start(); @@ -280,39 +261,38 @@ public function testViewScaffold() { $this->Controller->response->send(); $result = ob_get_clean(); - $this->assertRegExp('/

    View Scaffold Mock<\/h2>/', $result); - $this->assertRegExp('/
    /', $result); - //TODO: add specific tests for fields. - $this->assertRegExp('/1<\/a>/', $result); //belongsTo links - $this->assertRegExp('/
  • Edit Scaffold Mock<\/a>\s<\/li>/', $result); - $this->assertRegExp('/1#', $result); //belongsTo links + $this->assertRegExp('#
  • Edit Article\s*
  • #', $result); + $this->assertRegExp('#\s*

    Related Scaffold Comments<\/h3>\s*

    /', $result); - $this->assertRegExp('/
  • New Comment<\/a><\/li>/', $result); - $this->assertNotRegExp('/
  • JoinThing<\/th>/', $result); + $this->assertRegExp('#