Permalink
Browse files

update tests (behavour passes completely few fails on controller and …

…one on comp and few on widget helper)
  • Loading branch information...
1 parent df41e0a commit 7791683e6e44714fcca49b0a4ac4b8427e63285e @sams committed Apr 30, 2012
@@ -9,8 +9,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::import('Controller', 'Comments.Comments');
-App::import('Model', 'Comments.Comment');
+App::uses('CommentsController', 'Comments.Controller');
+App::uses('Comment', 'Comments.Model');
if (!class_exists('User')) {
class User extends CakeTestModel {
@@ -30,6 +30,16 @@ class User extends CakeTestModel {
class TestCommentsController extends CommentsController {
/**
+ * Components
+ *
+ * @var array
+ */
+ public $components = array(
+ 'RequestHandler',
+ 'Paginator',
+ 'Session');
+
+/**
* Auto render
* @var boolean
*/
@@ -91,6 +101,13 @@ class CommentsControllerTest extends CakeTestCase {
*/
public $Comments = null;
+ public $paginate = array();
+
+ public $components = array(
+ 'RequestHandler',
+ 'Paginator',
+ 'Session');
+
/**
* Fixtures
*
@@ -105,14 +122,14 @@ class CommentsControllerTest extends CakeTestCase {
* (non-PHPdoc)
* @see cake/tests/lib/CakeTestCase#startTest($method)
*/
- public function startTest($method) {
+ public function setUp() {
$this->Request = new CakeRequest();
$this->Request->params = array(
'named' => array(),
'pass' => array(),
'url' => array());
$this->Comments = new TestCommentsController($this->Request);
- //$this->Comments->params = $this->Request->params;
+ $this->Comments->request->params = $this->Request->params;
$this->Comments->constructClasses();
}
@@ -148,7 +165,7 @@ public function testAdminIndex() {
* @return void
*/
public function _testAdminProcessDelete() {
- $this->Comments->data['Comment'] = array(
+ $this->Comments->request->data['Comment'] = array(
'1' => 1,
'2' => 0,
'3' => 0,
@@ -315,7 +332,7 @@ public function testRequestForUser() {
* (non-PHPdoc)
* @see cake/tests/lib/CakeTestCase#endTest($method)
*/
- public function endTest($method) {
+ public function tearDown() {
unset($this->Comments);
}
}
@@ -9,8 +9,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::import('Controller', 'Controller', false);
-App::import('Component', 'Comments.Comments');
+App::uses('Controller', 'Controller');
+App::uses('CommentsComponent', 'Comments.Controller/Component');
if (!class_exists('ArticlesTestController')) {
class ArticlesTestController extends Controller {
@@ -80,7 +80,8 @@ class CommentsComponentTest extends CakeTestCase {
*
* @return void
*/
- function startTest($method) {
+ function setUp() {
+ parent::setUp();
if (!defined('FULL_BASE_URL')) {
define('FULL_BASE_URL', 'http://');
}
@@ -90,9 +91,9 @@ function startTest($method) {
// $this->Collection = $this->getMock('ComponentCollection');
// if (!class_exists('MockAuthComponent2')) {
- // $this->getMock('AuthComponent', array('user'), array($this->Collection), 'MockAuthComponent2');
+ // $this->getMock('AuthComponent', array('user'), array(&$this->Collection), 'MockAuthComponent2');
// }
-
+ //
// $this->AuthComponent = new MockAuthComponent2($this->Collection);
// $this->AuthComponent->enabled = true;
// $this->Controller->Auth = $this->AuthComponent;
@@ -117,12 +118,12 @@ function tearDown() {
* @return void
*/
public function testInitialize() {
- // $this->Controller = new ArticlesTestController();
- // $this->Controller->constructClasses();
- // $this->Controller->Components->init($this->Controller);
+ $this->Controller = new ArticlesTestController();
+ $this->Controller->constructClasses();
+ $this->Controller->Components->init($this->Controller);
$this->Controller->Comments->initialize($this->Controller, array());
$this->assertEqual($this->Controller->helpers, array(
- 'Session', 'Html', 'Form', 'Comments.CommentWidget', 'Time', 'Comments.Cleaner', 'Comments.Tree'));
+ 'Comments.CommentWidget', 'Time', 'Comments.Cleaner', 'Comments.Tree'));
$this->assertTrue($this->Controller->Article->Behaviors->attached('Commentable'));
$this->assertEqual($this->Controller->Comments->modelName, 'Article');
}
@@ -134,13 +135,13 @@ public function testInitialize() {
*/
public function testStartup() {
$this->Controller->Comments->initialize($this->Controller, array());
- //debug($this->Controller->Article->hasMany);
- //$this->assertTrue(isset($this->Controller->Article->hasMany['Comment']));
+ // debug($this->Controller->Article->hasMany);
+ $this->assertTrue(isset($this->Controller->Article->hasMany['Comment']));
$this->Controller->Comments->unbindAssoc = true;
- //debug($this->Controller->Comments);
+ // debug($this->Controller->Comments);
$this->Controller->Comments->startup($this->Controller);
$this->assertFalse(isset($this->Controller->Article->hasMany['Comment']));
- //debug($this->Controller->Article->hasMany);
+ // debug($this->Controller->Article->hasMany);
$User = ClassRegistry::init('User');
@@ -442,7 +443,7 @@ public function testCallback_toggleApprove() {
$this->Controller->passedArgs['comment_action'] = 'toggle_approve';
$User = ClassRegistry::init('User');
- //$this->Controller->Session->write('Auth', $User->find('first', array('conditions' => array('id' => '47ea303a-3b2c-4251-b313-4816c0a800fa'))));
+ $this->Controller->Session->write('Auth', $User->find('first', array('conditions' => array('id' => '47ea303a-3b2c-4251-b313-4816c0a800fa'))));
$this->Controller->Comments->callback_toggleApprove(1, 1);
$comment = $this->Controller->Article->Comment->findById(1);
@@ -577,12 +578,29 @@ public function testRedirectPersistParams() {
* @return void
*/
public function testPermalink() {
- $this->Controller->params = array(
+ $this->Request = new CakeRequest('/articles/view/1');
+ $this->Controller = new ArticlesTestController($this->Request);
+ $this->Controller->constructClasses();
+ $this->__setupControllerData();
+ debug($this->Controller);
+ $this->Controller->request->params = array(
+ 'name' => array(
+ 'controller' => 'articles',
+ 'action' => 'view'),
'named' => array(
+ 'testnamed' => 'test'));
+ $this->Controller->params = array(
+ 'url' => '/articles/view/1',
+ 'name' => array(
'controller' => 'articles',
- 'action' => 'view',
+ 'action' => 'view'),
+ 'named' => array(
'testnamed' => 'test'));
- $this->assertEqual($this->Controller->Comments->permalink(), 'http://' . env('HTTP_HOST') . '/articles/view/testnamed:test');
+ $this->Controller->Comments->initialize($this->Controller, array());
+ $result = $this->Controller->Comments->permalink();
+ $expected = 'http://' . env('HTTP_HOST') . '/articles/view/testnamed:test';
+ debug(array($result, $expected));
+ $this->assertEqual($result, $expected);
}
/**
@@ -125,7 +125,7 @@ class CommentableTest extends CakeTestCase {
*
* @return void
*/
- public function startTest() {
+ public function setUp() {
$this->Model = Classregistry::init('Article');
$this->Model->Comment->bindModel(array(
'belongsTo' => array(
@@ -137,7 +137,7 @@ public function startTest() {
*
* @return void
*/
- public function endTest() {
+ public function tearDown() {
unset($this->Model);
ClassRegistry::flush();
}
@@ -265,9 +265,16 @@ public function testChangeCommentCount() {
$this->assertTrue($this->Model->changeCommentCount('1', 'down'));
$article = $this->Model->findById(1);
$this->assertEqual($article['Article']['comments'], 2);
+ }
+/**
+ * commentDelete
+ *
+ * @return void
+ */
+ public function testChangeCommentCountInvalid() {
$this->assertFalse($this->Model->changeCommentCount('1', 'invalid'));
- $this->assertFalse($this->Model->changeCommentCount('invalid!', 'up'));
+ $this->assertFalse($this->Model->changeCommentCount(null, 'up'));
}
/**
@@ -292,8 +299,8 @@ public function testCommentBeforeFind() {
$result = $this->Model->commentBeforeFind($options);
$expected = array(
'conditions' => array(
+ 'Comment.foreign_key' => 1,
'Comment.model' => 'Article',
- 'Article.id' => 1,
'Comment.is_spam' => array('clean', 'ham')));
$this->assertEqual($result, $expected);
$this->assertTrue($this->Model->Behaviors->enabled('Containable'));
@@ -9,7 +9,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::import('Core', 'ModelBehavior');
+App::uses('ModelBehavior', 'Model');
+App::uses('Comment', 'Comments.Model');
//Mock::generatePartial('ModelBehavior', 'AntispamableBehavior', array('isSpam', 'setSpam', 'setHam'));
/**
@@ -85,16 +86,16 @@ public function testCommentFind() {
'user_id' => null,
'model' => 'Article',
'foreign_key' => '1',
- 'parent_id' => '0',
- 'approved' => 1,
+ 'parent_id' => '0',
+ 'approved' => true,
'name' => null,
'title' => '-',
'slug' => '_',
'body' => 'This is a comment',
- 'lft' => 1,
- 'rght' => 2,
- 'modified' => '2008-12-22 16:39:19',
- 'created' => '2008-12-22 16:39:19',
+ 'lft' => '1',
+ 'rght' => '2',
+ 'modified' => '2008-12-22 16:39:19',
+ 'created' => '2008-12-22 16:39:19',
'author_name' => 'mark story',
'author_email' => 'example@example.com',
'author_url' => 'http://example.com',

0 comments on commit 7791683

Please sign in to comment.