Adding unique fixtures to ControllerTaskTest and updating the test cases.

This commit is contained in:
mark_story 2010-07-08 23:25:39 -04:00
parent 82ae533f2a
commit a3bf367929
5 changed files with 288 additions and 56 deletions

View file

@ -39,18 +39,18 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
$imported = App::import('Model', 'Article');
$imported = $imported || App::import('Model', 'Comment');
$imported = $imported || App::import('Model', 'Tag');
$imported = App::import('Model', 'BakeArticle');
$imported = $imported || App::import('Model', 'BakeComment');
$imported = $imported || App::import('Model', 'BakeTag');
if (!$imported) {
define('ARTICLE_MODEL_CREATED', true);
App::import('Core', 'Model');
class Article extends Model {
public $name = 'Article';
public $hasMany = array('Comment');
public $hasAndBelongsToMany = array('Tag');
class BakeArticle extends Model {
public $name = 'BakeArticle';
public $hasMany = array('BakeComment');
public $hasAndBelongsToMany = array('BakeTag');
}
}
@ -69,7 +69,7 @@ class ControllerTaskTest extends CakeTestCase {
* @var array
* @access public
*/
public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
public $fixtures = array('core.bake_article', 'core.bake_articles_bake_tag', 'core.bake_comment', 'core.bake_tag');
/**
* startTest method
@ -118,19 +118,19 @@ class ControllerTaskTest extends CakeTestCase {
public function testListAll() {
$this->Task->connection = 'test_suite';
$this->Task->interactive = true;
$this->Task->expects($this->at(1))->method('out')->with('1. Articles');
$this->Task->expects($this->at(2))->method('out')->with('2. ArticlesTags');
$this->Task->expects($this->at(3))->method('out')->with('3. Comments');
$this->Task->expects($this->at(4))->method('out')->with('4. Tags');
$this->Task->expects($this->at(1))->method('out')->with('1. BakeArticles');
$this->Task->expects($this->at(2))->method('out')->with('2. BakeArticlesBakeTags');
$this->Task->expects($this->at(3))->method('out')->with('3. BakeComments');
$this->Task->expects($this->at(4))->method('out')->with('4. BakeTags');
$expected = array('Articles', 'ArticlesTags', 'Comments', 'Tags');
$expected = array('BakeArticles', 'BakeArticlesBakeTags', 'BakeComments', 'BakeTags');
$result = $this->Task->listAll('test_suite');
$this->assertEqual($result, $expected);
$this->Task->interactive = false;
$result = $this->Task->listAll();
$expected = array('articles', 'articles_tags', 'comments', 'tags');
$expected = array('bake_articles', 'bake_articles_bake_tags', 'bake_comments', 'bake_tags');
$this->assertEqual($result, $expected);
}
@ -143,12 +143,12 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->interactive = true;
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue(3));
$result = $this->Task->getName('test_suite');
$expected = 'Comments';
$expected = 'BakeComments';
$this->assertEqual($result, $expected);
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue(1));
$result = $this->Task->getName('test_suite');
$expected = 'Articles';
$expected = 'BakeArticles';
$this->assertEqual($result, $expected);
}
@ -330,29 +330,29 @@ class ControllerTaskTest extends CakeTestCase {
if ($skip) {
return;
}
$result = $this->Task->bakeActions('Articles', null, true);
$result = $this->Task->bakeActions('BakeArticles', null, true);
$this->assertTrue(strpos($result, 'function index() {') !== false);
$this->assertTrue(strpos($result, '$this->Article->recursive = 0;') !== false);
$this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false);
$this->assertTrue(strpos($result, '$this->BakeArticle->recursive = 0;') !== false);
$this->assertTrue(strpos($result, "\$this->set('bakeArticles', \$this->paginate());") !== false);
$this->assertTrue(strpos($result, 'function view($id = null)') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Invalid article'));") !== false);
$this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Invalid bake article'));") !== false);
$this->assertTrue(strpos($result, "\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)") !== false);
$this->assertTrue(strpos($result, 'function add()') !== false);
$this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article has been saved'));") !== false);
$this->assertTrue(strpos($result, 'if ($this->BakeArticle->save($this->data))') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The bake article has been saved'));") !== false);
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article could not be saved. Please, try again.'));") !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));") !== false);
$this->assertTrue(strpos($result, 'function delete($id = null)') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Article deleted'));") !== false);
$this->assertTrue(strpos($result, 'if ($this->BakeArticle->delete($id))') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Bake article deleted'));") !== false);
$result = $this->Task->bakeActions('Articles', 'admin_', true);
$result = $this->Task->bakeActions('BakeArticles', 'admin_', true);
$this->assertTrue(strpos($result, 'function admin_index() {') !== false);
$this->assertTrue(strpos($result, 'function admin_add()') !== false);
@ -372,29 +372,29 @@ class ControllerTaskTest extends CakeTestCase {
if ($skip) {
return;
}
$result = $this->Task->bakeActions('Articles', null, false);
$result = $this->Task->bakeActions('BakeArticles', null, false);
$this->assertTrue(strpos($result, 'function index() {') !== false);
$this->assertTrue(strpos($result, '$this->Article->recursive = 0;') !== false);
$this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false);
$this->assertTrue(strpos($result, '$this->BakeArticle->recursive = 0;') !== false);
$this->assertTrue(strpos($result, "\$this->set('bakeArticles', \$this->paginate());") !== false);
$this->assertTrue(strpos($result, 'function view($id = null)') !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('Invalid article'), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('Invalid bake article'), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, "\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)") !== false);
$this->assertTrue(strpos($result, 'function add()') !== false);
$this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false);
$this->assertTrue(strpos($result, 'if ($this->BakeArticle->save($this->data))') !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('The article has been saved.'), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
$this->assertTrue(strpos($result, "\$this->Article->Tag->find('list')") !== false);
$this->assertTrue(strpos($result, "\$this->set(compact('tags'))") !== false);
$this->assertTrue(strpos($result, "\$this->BakeArticle->BakeTag->find('list')") !== false);
$this->assertTrue(strpos($result, "\$this->set(compact('bakeTags'))") !== false);
$this->assertTrue(strpos($result, 'function delete($id = null)') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('Article deleted'), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, 'if ($this->BakeArticle->delete($id))') !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('Bake article deleted'), array('action' => 'index'))") !== false);
}
/**
@ -407,8 +407,8 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->connection = 'test_suite';
$this->Task->interactive = false;
$this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'Articles');
$this->Task->bakeTest('Articles');
$this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'BakeArticles');
$this->Task->bakeTest('BakeArticles');
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
$this->assertEqual($this->Task->connection, $this->Task->Test->connection);
@ -437,10 +437,10 @@ class ControllerTaskTest extends CakeTestCase {
'y' // looks good?
));
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesController/')
);
$this->Task->execute();
}
@ -473,10 +473,10 @@ class ControllerTaskTest extends CakeTestCase {
->method('getPrefix')
->will($this->returnValue('admin_'));
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesController/')
)->will($this->returnValue(true));
$result = $this->Task->execute();
@ -501,10 +501,10 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));
$this->Task->Test->expects($this->once())->method('bake');
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesController/')
)->will($this->returnValue(true));
$this->Task->execute();
@ -523,9 +523,9 @@ class ControllerTaskTest extends CakeTestCase {
}
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('Articles');
$this->Task->args = array('BakeArticles');
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
@ -541,7 +541,7 @@ class ControllerTaskTest extends CakeTestCase {
*/
static function nameVariations() {
return array(
array('Articles'), array('Article'), array('article'), array('articles')
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
);
}
@ -561,7 +561,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->path = '/my/path/';
$this->Task->args = array($name);
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
);
@ -581,9 +581,9 @@ class ControllerTaskTest extends CakeTestCase {
}
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('Articles', 'public');
$this->Task->args = array('BakeArticles', 'public');
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$expected = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/'));
$this->Task->expects($this->once())->method('createFile')->with(
$filename, $expected
@ -605,9 +605,9 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('Articles', 'public', 'admin');
$this->Task->args = array('BakeArticles', 'public', 'admin');
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
);
@ -628,9 +628,9 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('Articles', 'admin');
$this->Task->args = array('BakeArticles', 'admin');
$filename = '/my/path/articles_controller.php';
$filename = '/my/path/bake_articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
);

View file

@ -0,0 +1,59 @@
<?php
/**
* BakeArticleFixture
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 2.0
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/**
* Short description for class.
*
* @package cake
* @subpackage cake.tests.fixtures
*/
class BakeArticleFixture extends CakeTestFixture {
/**
* name property
*
* @var string
*/
public $name = 'BakeArticle';
/**
* fields property
*
* @var array
* @access public
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'bake_user_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => 'text',
'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
* @access public
*/
public $records = array();
}

View file

@ -0,0 +1,56 @@
<?php
/**
* BakeCommentFixture
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package cake
* @subpackage cake.tests.fixtures
*/
class BakeArticlesBakeTagFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'ArticlesTag'
* @access public
*/
public $name = 'BakeArticlesBakeTag';
/**
* fields property
*
* @var array
* @access public
*/
public $fields = array(
'bake_article_id' => array('type' => 'integer', 'null' => false),
'bake_tag_id' => array('type' => 'integer', 'null' => false),
'indexes' => array('UNIQUE_TAG' => array('column'=> array('bake_article_id', 'bake_tag_id'), 'unique'=>1))
);
/**
* records property
*
* @var array
* @access public
*/
public $records = array();
}

View file

@ -0,0 +1,60 @@
<?php
/**
* BakeCommentFixture
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* BakeCommentFixture fixture for testing bake
*
* @package cake
* @subpackage cake.tests.fixtures
*/
class BakeCommentFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Comment'
* @access public
*/
public $name = 'BakeComment';
/**
* fields property
*
* @var array
* @access public
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'bake_article_id' => array('type' => 'integer', 'null'=>false),
'bake_user_id' => array('type' => 'integer', 'null'=>false),
'comment' => 'text',
'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
* @access public
*/
public $records = array();
}

View file

@ -0,0 +1,57 @@
<?php
/**
* BakeTagFixture
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Short description for class.
*
* @package cake
* @subpackage cake.tests.fixtures
*/
class BakeTagFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'Tag'
* @access public
*/
public $name = 'BakeTag';
/**
* fields property
*
* @var array
* @access public
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'tag' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
* @access public
*/
public $records = array();
}