Permalink
Browse files

Add documentation for tests.

  • Loading branch information...
1 parent e8a4add commit 4e81f8c210f8a75d600f83ecac89db4701bdf9e3 @predominant predominant committed Sep 23, 2010
View
18 tests/cases/behaviors/favorite.test.php
@@ -16,18 +16,21 @@
* @subpackage favorites.tests.cases.behaviors
*/
class FavoriteArticle extends CakeTestModel {
+
/**
* useTable
*
* @var string
*/
public $useTable = 'articles';
+
/**
* actsAs
*
* @var array
*/
public $actsAs = array('Favorites.Favorite');
+
/**
* belongsTo
*
@@ -41,7 +44,14 @@ class FavoriteArticle extends CakeTestModel {
);
}
+/**
+ * FavoriteUser
+ *
+ * @package favorites
+ * @subpackage favorites.tests.cases.behaviors
+ */
class FavoriteUser extends CakeTestModel {
+
/**
* useTable
*
@@ -50,7 +60,14 @@ class FavoriteUser extends CakeTestModel {
public $useTable = 'users';
}
+/**
+ * FavoriteBehaviorTestCase
+ *
+ * @package favorites
+ * @subpackage favorites.tests.cases.behaviors
+ */
class FavoriteBehaviorTestCase extends CakeTestCase {
+
/**
* fixtures
*
@@ -184,5 +201,4 @@ public function testIncrementingFavorites() {
$result = $this->FavoriteModel->read();
$this->assertEqual($result['Favorite']['position'], 0);
}
-
}
View
136 tests/cases/controllers/favorites_controller.test.php
@@ -9,29 +9,32 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::import('Controller', 'Favorites.Favorites');
+App::import('Component', array('Auth'));
+Mock::generate('AuthComponent', 'FavoritesControllerTestAuthComponent');
+
/**
* FavoritesController Test Case
*
* @package favorites
* @subpackage favorites.tests.cases.controllers
*/
-App::import('Controller', 'Favorites.Favorites');
-App::import('Component', array('Auth'));
-Mock::generate('AuthComponent', 'FavoritesControllerTestAuthComponent');
-
class FavoriteArticle extends CakeTestModel {
+
/**
* useTable
*
* @var string
*/
public $useTable = 'articles';
+
/**
* actsAs
*
* @var array
*/
public $actsAs = array('Favorites.Favorite');
+
/**
* belongsTo
*
@@ -45,7 +48,14 @@ class FavoriteArticle extends CakeTestModel {
);
}
+/**
+ * FavoriteUser
+ *
+ * @package favorites
+ * @subpackage favorites.tests.cases.controllers
+ */
class FavoriteUser extends CakeTestModel {
+
/**
* useTable
*
@@ -54,7 +64,14 @@ class FavoriteUser extends CakeTestModel {
public $useTable = 'users';
}
+/**
+ * TestFavoritesController
+ *
+ * @package favorites
+ * @subpackage favorites.tests.cases.controllers
+ */
class TestFavoritesController extends FavoritesController {
+
/**
* Auto render
*
@@ -93,12 +110,22 @@ public function redirect($url, $status = null, $exit = true) {
/**
* Override controller method for testing
*
+ * @param string $action
+ * @param string $layout
+ * @param string $file
+ * @return void
*/
public function render($action = null, $layout = null, $file = null) {
$this->renderedView = $action;
}
}
+/**
+ * FavoritesControllerTestCase
+ *
+ * @package favorites
+ * @subpackage favorites.tests.cases.controllers
+ */
class FavoritesControllerTestCase extends CakeTestCase {
/**
@@ -109,6 +136,11 @@ class FavoritesControllerTestCase extends CakeTestCase {
public $fixtures = array(
'plugin.favorites.favorite', 'core.article', 'core.user');
+/**
+ * startTest
+ *
+ * @return void
+ */
public function startTest() {
Configure::write('Favorites.types', array('like' => 'FavoriteArticle', 'dislike' => 'FavoriteArticle'));
Configure::write('Favorites.modelCategories', array('FavoriteArticle'));
@@ -121,12 +153,22 @@ public function startTest() {
'url' => array());
}
+/**
+ * endTest
+ *
+ * @return void
+ */
public function endTest() {
unset($this->Favorites);
ClassRegistry::flush();
}
-
+/**
+ * assertFlash
+ *
+ * @param string $message
+ * @return void
+ */
public function assertFlash($message) {
$flash = $this->Favorites->Session->read('Message.flash');
$this->assertEqual($flash['message'], $message);
@@ -165,6 +207,11 @@ public function testAdd() {
$this->assertEqual($this->Favorites->redirectUrl, '/articles/index');
}
+/**
+ * testAddJson
+ *
+ * @return void
+ */
public function testAddJson() {
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
$this->Favorites->beforeFilter();
@@ -175,6 +222,11 @@ public function testAddJson() {
$this->assertEqual($this->Favorites->viewVars['status'], 'success');
}
+/**
+ * testAddTwiceFailJson
+ *
+ * @return void
+ */
public function testAddTwiceFailJson() {
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
$this->Favorites->beforeFilter();
@@ -185,8 +237,13 @@ public function testAddTwiceFailJson() {
$this->assertEqual($this->Favorites->viewVars['message'], 'Record was not added. Already added.');
$this->assertEqual($this->Favorites->viewVars['status'], 'error');
}
-
- public function testAddTwiceDiferentTypes() {
+
+/**
+ * testAddTwiceDifferentTypes
+ *
+ * @return void
+ */
+ public function testAddTwiceDifferentTypes() {
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
$this->Favorites->beforeFilter();
$this->Favorites->params['isJson'] = true;
@@ -196,7 +253,12 @@ public function testAddTwiceDiferentTypes() {
$this->assertEqual($this->Favorites->viewVars['message'], 'Record was successfully added');
$this->assertEqual($this->Favorites->viewVars['status'], 'success');
}
-
+
+/**
+ * testAddUnexists
+ *
+ * @return void
+ */
public function testAddUnexists() {
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
$this->Favorites->beforeFilter();
@@ -206,7 +268,12 @@ public function testAddUnexists() {
$this->assertEqual($this->Favorites->viewVars['message'], 'Invalid identifier');
$this->assertEqual($this->Favorites->viewVars['status'], 'error');
}
-
+
+/**
+ * testAddWrongType
+ *
+ * @return void
+ */
public function testAddWrongType() {
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
$this->Favorites->beforeFilter();
@@ -233,6 +300,11 @@ public function testDelete() {
$this->assertEqual($this->Favorites->redirectUrl, '/articles/index');
}
+/**
+ * testDeleteNotExists
+ *
+ * @return void
+ */
public function testDeleteNotExists() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
@@ -243,7 +315,12 @@ public function testDeleteNotExists() {
$this->assertEqual($this->Favorites->viewVars['status'], 'error');
$this->assertEqual($this->Favorites->redirectUrl, '/articles/index');
}
-
+
+/**
+ * testDeleteOtherUsers
+ *
+ * @return void
+ */
public function testDeleteOtherUsers() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
$this->Favorites->Auth->setReturnValueAt(0, 'user', 1, array('id'));
@@ -275,7 +352,12 @@ public function testMove() {
$this->assertEqual($this->Favorites->viewVars['status'], 'success');
$this->assertEqual($this->Favorites->redirectUrl, '/articles/index');
}
-
+
+/**
+ * testMoveWrongDirection
+ *
+ * @return void
+ */
public function testMoveWrongDirection() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
@@ -287,8 +369,12 @@ public function testMoveWrongDirection() {
$this->assertEqual($this->Favorites->viewVars['status'], 'error');
$this->assertEqual($this->Favorites->redirectUrl, '/articles/index');
}
-
-
+
+/**
+ * testMoveWrongDirection
+ *
+ * @return void
+ */
public function _testMoveWrongDirection2() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
@@ -305,7 +391,11 @@ public function _testMoveWrongDirection2() {
}
/**
+ * testDeleteAjax
+ *
* Short list test
+ *
+ * @return void
*/
public function testDeleteAjax() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
@@ -322,11 +412,13 @@ public function testDeleteAjax() {
$this->assertEqual($this->Favorites->redirectUrl, null);
}
-
-
/**
+ * testListAll
+ *
* Full list test
- */
+ *
+ * @return void
+ */
public function testListAll() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
@@ -342,6 +434,11 @@ public function testListAll() {
$this->assertEqual($this->Favorites->viewVars['type'], 'like');
}
+/**
+ * testListAllDiferentType
+ *
+ * @return void
+ */
public function testListAllDiferentType() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
@@ -364,13 +461,16 @@ public function testListAllDiferentType() {
$this->assertEqual($this->Favorites->viewVars['type'], 'dislike');
}
+/**
+ * testListWrongType
+ *
+ * @return void
+ */
public function testListWrongType() {
$_SERVER['HTTP_REFERER'] = '/articles/index';
$this->Favorites->Auth->setReturnValue('user', 1, array('id'));
$this->Favorites->beforeFilter();
$this->Favorites->list_all('WRONGTYPE');
$this->assertFlash('Invalid object type.');
}
-
-
}
View
10 tests/cases/helpers/favorites.test.php
@@ -9,16 +9,15 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::import('Core', 'View');
+App::import('Helper', array('Favorites.Favorites', 'Html'));
+
/**
* Favorites Helper Test Case
*
* @package favorites
* @subpackage favorites.tests.cases.helpers
*/
-
-App::import('Core', 'View');
-App::import('Helper', array('Favorites.Favorites', 'Html'));
-
class FavoritesHelperTestCase extends CakeTestCase {
/**
@@ -42,7 +41,6 @@ public function startTest() {
));
$this->Favorites = new FavoritesHelper;
$this->Favorites->Html = new HtmlHelper;
-
}
/**
@@ -88,4 +86,4 @@ public function testToggleFavoriteWithRemove() {
$result = $this->Favorites->toggleFavorite('watch', 'my-thing-id', null, 'Stop watching');
$this->assertEqual($result, '<a href="/favorites/favorites/delete/0" class="remove-favorite watch">Stop watching</a>');
}
-}
+}
View
22 tests/cases/models/favorite.test.php
@@ -16,18 +16,21 @@
* @subpackage favorites.tests.cases.models
*/
class FavoriteArticle extends CakeTestModel {
+
/**
* useTable
*
* @var string
*/
public $useTable = 'articles';
+
/**
* actsAs
*
* @var array
*/
public $actsAs = array('Favorites.Favorite');
+
/**
* belongsTo
*
@@ -41,7 +44,14 @@ class FavoriteArticle extends CakeTestModel {
);
}
+/**
+ * FavoriteUser
+ *
+ * @package favorites
+ * @subpackage favorites.tests.cases.models
+ */
class FavoriteUser extends CakeTestModel {
+
/**
* useTable
*
@@ -50,7 +60,14 @@ class FavoriteUser extends CakeTestModel {
public $useTable = 'users';
}
+/**
+ * FavoriteTestCase
+ *
+ * @package favorites
+ * @subpackage favorites.tests.cases.models
+ */
class FavoriteTestCase extends CakeTestCase {
+
/**
* fixtures
*
@@ -80,6 +97,7 @@ public function endTest() {
unset($this->Article);
ClassRegistry::flush();
}
+
/**
* test that setup() binds all the models that are needed.
*
@@ -263,7 +281,7 @@ public function testGetFavoriteId() {
}
/**
- *
+ * testGetFavoriteLists
*
* @return void
*/
@@ -278,7 +296,5 @@ public function testGetFavoriteLists() {
array('id' => '2', 'title' => 'Second Article'),
array('id' => '3', 'title' => 'Third Article')));
$this->assertEqual($result, $expected);
-
}
}
-?>
View
8 tests/fixtures/favorite_fixture.php
@@ -16,18 +16,21 @@
* @subpackage favorites.tests.fixtures
*/
class FavoriteFixture extends CakeTestFixture {
+
/**
* Model name
*
* @var string $model
*/
public $name = 'Favorite';
+
/**
* Table name
*
* @var string $useTable
*/
public $table = 'favorites';
+
/**
* Fields definition
*
@@ -46,12 +49,11 @@ class FavoriteFixture extends CakeTestFixture {
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'UNIQUE_FAVORITES' => array('column' => array('foreign_key', 'model', 'type', 'user_id'), 'unique' => 1))
);
+
/**
* record set
*
* @var array $records
*/
- public $records = array(
- );
+ public $records = array();
}
-?>

0 comments on commit 4e81f8c

Please sign in to comment.