Skip to content
Browse files

Working on making the plugin 2.0 ready.

  • Loading branch information...
1 parent 2dc4a3c commit 92c2060c497f4de3e9d2fcb9adbccaa4ed319122 @burzum burzum committed Jul 29, 2011
View
67 Controller/Component/RatingsComponent.php
@@ -17,6 +17,8 @@
* @package ratings
* @subpackage ratings.controllers.components
*/
+App::uses('Component', 'Controller');
+
class RatingsComponent extends Component {
/**
@@ -72,25 +74,25 @@ class RatingsComponent extends Component {
*
* @param object Controller object
*/
- public function initialize(&$controller, $settings = array()) {
- $this->controller = $controller;
+ public function initialize(&$Controller, $settings = array()) {
+ $this->Controller = $Controller;
if ($this->enabled == true) {
foreach ($settings as $setting => $value) {
if (isset($this->{$setting})) {
$this->{$setting} = $value;
}
}
- $this->controller->params['isJson'] = (isset($this->controller->params['url']['ext']) && $this->controller->params['url']['ext'] === 'json');
- if ($this->controller->params['isJson']) {
+ $this->Controller->request->params['isJson'] = (isset($this->Controller->request->params['url']['ext']) && $this->Controller->request->params['url']['ext'] === 'json');
+ if ($this->Controller->request->params['isJson']) {
Configure::write('debug', 0);
}
if (empty($this->modelName)) {
- $this->modelName = $controller->modelClass;
+ $this->modelName = $Controller->modelClass;
}
- if (!$controller->{$this->modelName}->Behaviors->attached('Ratable')) {
- $controller->{$this->modelName}->Behaviors->attach('Ratings.Ratable', $settings);
+ if (!$Controller->{$this->modelName}->Behaviors->attached('Ratable')) {
+ $Controller->{$this->modelName}->Behaviors->load('Ratings.Ratable', $settings);
}
- $controller->helpers[] = 'Ratings.Rating';
+ $Controller->helpers[] = 'Ratings.Rating';
}
}
@@ -99,15 +101,14 @@ public function initialize(&$controller, $settings = array()) {
*
* @param object Controller object
*/
- public function startup(&$controller) {
+ public function startup(&$Controller) {
$message = '';
$rating = null;
- $params = $controller->params['named'];
- if (empty($params['rating']) && !empty($controller->data[$controller->modelClass]['rating'])) {
- $params['rating'] = $controller->data[$controller->modelClass]['rating'];
-
+ $params = $Controller->request->params['named'];
+ if (empty($params['rating']) && !empty($Controller->request->data[$Controller->modelClass]['rating'])) {
+ $params['rating'] = $Controller->request->data[$Controller->modelClass]['rating'];
}
- if (!method_exists($controller, 'rate')) {
+ if (!method_exists($Controller, 'rate')) {
if (isset($params['rate']) && isset($params['rating']) && $this->enabled == true) {
$this->rate($params['rate'], $params['rating'], $this->Auth->user('id'), !empty($params['redirect']));
}
@@ -122,11 +123,11 @@ public function startup(&$controller) {
* @param mixed $redirect boolean to redirect to same url or string or array to use it for Router::url()
*/
public function rate($rate, $rating, $user, $redirect = false) {
- $controller = $this->controller;
- $controller->{$this->modelName}->id = $rate;
- if ($controller->{$this->modelName}->exists(true)) {
- if ($controller->{$this->modelName}->saveRating($rate, $user, $rating)) {
- $rating = round($controller->{$this->modelName}->newRating);
+ $Controller = $this->Controller;
+ $Controller->{$this->modelName}->id = $rate;
+ if ($Controller->{$this->modelName}->exists(true)) {
+ if ($Controller->{$this->modelName}->saveRating($rate, $user, $rating)) {
+ $rating = round($Controller->{$this->modelName}->newRating);
$message = __d('ratings', 'Your rate was successfull.');
$status = 'success';
} else {
@@ -138,7 +139,7 @@ public function rate($rate, $rating, $user, $redirect = false) {
$status = 'error';
}
$result = compact('status', 'message', 'rating');
- $this->controller->set($result);
+ $this->Controller->set($result);
if (!empty($redirect)) {
if (is_bool($redirect)) {
$this->redirect($this->buildUrl());
@@ -156,9 +157,9 @@ public function rate($rate, $rating, $user, $redirect = false) {
* @return array
*/
public function buildUrl() {
- $params = array('plugin' => $this->controller->params['plugin'], 'controller' => $this->controller->params['controller'], 'action' => $this->controller->params['action']);
- $params = array_merge($params, $this->controller->params['pass']);
- foreach ($this->controller->params['named'] as $name => $value) {
+ $params = array('plugin' => $this->Controller->request->params['plugin'], 'controller' => $this->Controller->request->params['controller'], 'action' => $this->Controller->request->params['action']);
+ $params = array_merge($params, $this->Controller->request->params['pass']);
+ foreach ($this->Controller->request->params['named'] as $name => $value) {
if (!isset($this->parameters[$name])) {
$params[$name] = $value;
}
@@ -176,22 +177,22 @@ public function buildUrl() {
* @return void
*/
public function redirect($url, $code = null, $exit = true) {
- if (!empty($this->controller->viewVars['authMessage']) && !empty($this->controller->params['isJson'])) {
- $this->RequestHandler->renderAs($this->controller, 'json');
- $this->set('message', $this->controller->viewVars['authMessage']);
+ if (!empty($this->Controller->viewVars['authMessage']) && !empty($this->Controller->request->params['isJson'])) {
+ $this->RequestHandler->renderAs($this->Controller, 'json');
+ $this->set('message', $this->Controller->viewVars['authMessage']);
$this->set('status', 'error');
- echo $this->controller->render('rate');
+ echo $this->Controller->render('rate');
$this->_stop();
} elseif (!empty($this->viewVars['authMessage'])) {
$this->Session->setFlash($this->viewVars['authMessage']);
}
- if (!empty($this->controller->params['isAjax']) || !empty($this->controller->params['isJson'])) {
- $this->controller->setAction('rated', $this->controller->params['named']['rate']);
- return $this->controller->render('rated');
- } else if (isset($this->controller->viewVars['status']) && isset($this->controller->viewVars['message'])) {
- $this->controller->Session->setFlash($this->controller->viewVars['message'], 'default', array(), $this->controller->viewVars['status']);
+ if (!empty($this->Controller->request->params['isAjax']) || !empty($this->Controller->request->params['isJson'])) {
+ $this->Controller->setAction('rated', $this->Controller->request->params['named']['rate']);
+ return $this->Controller->render('rated');
+ } else if (isset($this->Controller->viewVars['status']) && isset($this->Controller->viewVars['message'])) {
+ $this->Controller->Session->setFlash($this->Controller->viewVars['message'], 'default', array(), $this->Controller->viewVars['status']);
}
- $this->controller->redirect($url, $code, $exit);
+ $this->Controller->redirect($url, $code, $exit);
}
}
View
36 Model/Behavior/RatableBehavior.php
@@ -313,8 +313,6 @@ public function incrementRating(Model $Model, $foreignKey = null, $value, $saveT
* and SUM(). Please note that this is relativly slow compared to incrementing
* the values, see Ratable::incrementRating()
*
- *
- *
* @param AppModel $Model
* @param string $foreignKey
* @param mixed $saveToField boolean or fieldname
@@ -326,25 +324,33 @@ public function calculateRating(Model $Model, $foreignKey = null, $saveToField =
throw new InvalidArgumentException(sprintf(__d('ratings', 'Invalid rating mode %s.'),$mode));
}
- $result = $Model->Rating->find(
- array('Rating.foreign_key' => $foreignKey, 'Rating.model' => $Model->alias),
- array($this->modes[$mode] . '(Rating.value) AS rating'));
- if (empty($result[0]['rating'])) {
- $result[0]['rating'] = 0;
+ $result = $Model->Rating->find('all', array(
+ 'contain' => array($Model->alias),
+ 'fields' => array(
+ $this->modes[$mode] . '(Rating.value) AS rating'),
+ 'conditions' => array(
+ 'Rating.foreign_key' => $foreignKey,
+ 'Rating.model' => $Model->alias)));
+
+ if (empty($result[0][0]['rating'])) {
+ $result[0][0]['rating'] = 0;
}
- $Model->newRating = $result[0]['rating'];
+
+ $Model->newRating = $result[0][0]['rating'];
if ($saveToField || is_string($saveToField)) {
if (is_string($saveToField)) {
- $data[$Model->alias][$saveToField] = $result[0]['rating'];
+ $data[$Model->alias][$saveToField] = $result[0][0]['rating'];
} else {
- $data[$Model->alias][$this->settings[$Model->alias]['field']] = $result[0]['rating'];
+ $data[$Model->alias][$this->settings[$Model->alias]['field']] = $result[0][0]['rating'];
}
$data[$Model->alias][$Model->primaryKey] = $foreignKey;
+
return $Model->save($data, array(
'validate' => $this->settings[$Model->alias]['modelValidate'],
'callbacks' => $this->settings[$Model->alias]['modelCallbacks']));
}
- return $result[0]['rating'];
+
+ return $result[0][0]['rating'];
}
/**
@@ -362,7 +368,7 @@ public function isRatedBy(Model $Model, $foreignKey = null, $userId = null) {
}
$entry = $Model->Rating->find($findMethod, array(
- 'recursive'-1,
+ 'recursive' => -1,
'conditions' => array(
'Rating.foreign_key' => $foreignKey,
'Rating.user_id' => $userId,
@@ -466,6 +472,7 @@ public function cacheRatingStatistics(Model $Model, $data = array()) {
if ($type == 'removeRating') {
$value = $oldRating['Rating']['value'];
}
+
if ($Model->getColumnType($this->_fieldName(round($value, 0)))) {
$data = $Model->find('first', array(
'conditions' => array(
@@ -476,10 +483,12 @@ public function cacheRatingStatistics(Model $Model, $data = array()) {
$oldId = round($oldRating['Rating']['value']);
$data[$Model->alias][$this->_fieldName($oldId)] -= 1;
}
+
if ($type == 'saveRating') {
$newId = round($value);
$data[$Model->alias][$this->_fieldName($newId)] += 1;
}
+
return $Model->save($data, array(
'validate' => $this->settings[$Model->alias]['modelValidate'],
'callbacks' => $this->settings[$Model->alias]['modelCallbacks']));
@@ -501,4 +510,5 @@ protected function _fieldName($value, $prefix = 'rating_') {
}
return $prefix . $postfix;
}
-}
+
+}
View
62 Test/Case/Behavior/RatableTest.php → Test/Case/Behavior/RatableBehaviorTest.php
@@ -9,7 +9,6 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-//App::import('Core', array('AppModel', 'Model'));
App::uses('Model', 'Model');
/**
@@ -73,13 +72,13 @@ public function testCalculateRating() {
$this->Article->Behaviors->load('Ratings.Ratable', array());
$result = $this->Article->calculateRating(1);
$this->assertEqual($result['Article']['rating'], '1.0000');
-
+
$result = $this->Article->calculateRating(1, false);
$this->assertEqual($result, '1.0000');
-
+
$result = $this->Article->calculateRating(1, 'title');
$this->assertEqual($result['Article']['title'], '1.0000');
-
+
$result = $this->Article->calculateRating(2);
$this->assertEqual($result['Article']['rating'], '0');
@@ -93,42 +92,41 @@ public function testCalculateRating() {
$this->Article->Rating->save($data);
$result = $this->Article->calculateRating(1);
$this->assertEqual($result['Article']['rating'], '1.75000000');
-
+
$this->expectException('InvalidArgumentException');
$this->Article->calculateRating(1, true, 'pow');
}
-
-
+
/**
* Testing update of the rating
*
* @return void
*/
public function testIncrementRating() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->IncrementRating(1, 1);
+ $result = $this->Post->incrementRating(1, 1);
$this->assertEqual($result['Post']['rating'], '1.0000');
$this->assertEqual($result['Post']['rating_count'], 2);
$this->assertEqual($result['Post']['rating_sum'], 2);
}
public function testIncrementRatingCalc() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->IncrementRating(1, 1, false);
+ $result = $this->Post->incrementRating(1, 1, false);
$this->assertEqual($result, '1.0000');
}
public function testIncrementRatingOtherField() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->IncrementRating(1, 1, 'title');
+ $result = $this->Post->incrementRating(1, 1, 'title');
$this->assertEqual($result['Post']['title'], '1.0000');
$this->assertEqual($result['Post']['rating_count'], 2);
$this->assertEqual($result['Post']['rating_sum'], 2);
}
public function testIncrementRatingCalc2() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->IncrementRating(2, 1);
+ $result = $this->Post->incrementRating(2, 1);
$this->assertEqual($result['Post']['rating'], '2');
}
@@ -142,41 +140,41 @@ public function testIncrementRatingNewRating() {
'value' => 2.5000));
$this->Post->Rating->create();
$this->Post->Rating->save($data);
- $result = $this->Post->IncrementRating(1, 2.5);
+ $result = $this->Post->incrementRating(1, 2.5);
$this->assertEqual($result['Post']['rating'], '1.75000000');
$this->expectException('InvalidArgumentException');
- $this->Post->IncrementRating(1, 1, true, 'pow');
+ $this->Post->incrementRating(1, 1, true, 'pow');
}
public function testDecrementRating() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->DecrementRating(1, 1);
+ $result = $this->Post->decrementRating(1, 1);
$this->assertEqual($result['Post']['rating'], '0.0000');
$this->assertEqual($result['Post']['rating_count'], 0);
$this->assertEqual($result['Post']['rating_sum'], 0);
}
public function testDecrementRatingCalc() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->DecrementRating(1, 1, false);
+ $result = $this->Post->decrementRating(1, 1, false);
$this->assertEqual($result, '0.0000');
}
public function testDecrementRatingOtherField() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->DecrementRating(1, 1, 'title');
+ $result = $this->Post->decrementRating(1, 1, 'title');
$this->assertEqual($result['Post']['title'], '0.0000');
$this->assertEqual($result['Post']['rating_count'], 0);
$this->assertEqual($result['Post']['rating_sum'], 0);
}
public function testDecrementRatingCalc2() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
- $result = $this->Post->DecrementRating(2, 1);
+ $result = $this->Post->decrementRating(2, 1);
$this->assertEqual($result['Post']['rating'], '0');
}
@@ -190,14 +188,14 @@ public function testDecrementRatingNewRating() {
'value' => 2.5000));
$this->Post->Rating->create();
$this->Post->Rating->save($data);
- $result = $this->Post->IncrementRating(1, 2.5);
+ $result = $this->Post->incrementRating(1, 2.5);
$this->assertEqual($result['Post']['rating'], '1.75000000');
- $result = $this->Post->DecrementRating(1, 2.5);
+ $result = $this->Post->decrementRating(1, 2.5);
$this->assertEqual($result['Post']['rating'], '1.50000000');
$this->expectException('InvalidArgumentException');
- $this->Post->DecrementRating(1, 1, true, 'pow');
+ $this->Post->decrementRating(1, 1, true, 'pow');
}
/**
@@ -209,7 +207,7 @@ public function testSaveRating() {
$this->Article->Behaviors->load('Ratings.Ratable', array());
$userId = '2'; // floriank
$result = $this->Article->saveRating(1, $userId, 4);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Article']['rating'], '2.5000');
$userId = '1'; // phpnut
@@ -225,7 +223,7 @@ public function testSaveRatingWithAdditionalFields() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
$userId = '2'; // floriank
$result = $this->Post->saveRating(1, $userId, 4);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '2.5000');
$this->assertEqual($result['Post']['rating_count'], 2);
$this->assertEqual($result['Post']['rating_sum'], 5);
@@ -245,7 +243,7 @@ public function testSaveUpdatedRating() {
$userId = '1'; // phpnut
$result = $this->Post->saveRating(1, $userId, 3);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '3');
$this->assertEqual($result['Post']['rating_count'], 1);
$this->assertEqual($result['Post']['rating_sum'], 3);
@@ -257,7 +255,7 @@ public function testSaveUpdatedRatingForNewRating() {
$userId = '1'; // phpnut
$result = $this->Post->saveRating(3, $userId, 5);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '5');
$this->assertEqual($result['Post']['rating_count'], 1);
$this->assertEqual($result['Post']['rating_sum'], 5);
@@ -272,11 +270,11 @@ public function testRemoveRating() {
$this->Article->Behaviors->load('Ratings.Ratable', array());
$userId = '2'; // floriank
$result = $this->Article->saveRating(1, $userId, 4);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Article']['rating'], '2.5000');
$result = $this->Article->removeRating(1, $userId);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Article']['rating'], '1.0000');
$userId = '1'; // phpnut
@@ -292,13 +290,13 @@ public function testRemoveRatingWithAdditionalFields() {
$this->Post->Behaviors->load('Ratings.Ratable', array());
$userId = '2'; // floriank
$result = $this->Post->saveRating(1, $userId, 4);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '2.5000');
$this->assertEqual($result['Post']['rating_count'], 2);
$this->assertEqual($result['Post']['rating_sum'], 5);
$result = $this->Post->removeRating(1, $userId);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '1.0000');
$this->assertEqual($result['Post']['rating_count'], 1);
$this->assertEqual($result['Post']['rating_sum'], 1);
@@ -318,14 +316,14 @@ public function testRemoveUpdatedRating() {
$userId = '1'; // phpnut
$result = $this->Post->saveRating(1, $userId, 3);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '3');
$this->assertEqual($result['Post']['rating_count'], 1);
$this->assertEqual($result['Post']['rating_sum'], 3);
$result = $this->Post->removeRating(1, $userId);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '0');
$this->assertEqual($result['Post']['rating_count'], 0);
$this->assertEqual($result['Post']['rating_sum'], 0);
@@ -337,13 +335,13 @@ public function testRemoveUpdatedRatingForNewRating() {
$userId = '1'; // phpnut
$result = $this->Post->saveRating(3, $userId, 5);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '5');
$this->assertEqual($result['Post']['rating_count'], 1);
$this->assertEqual($result['Post']['rating_sum'], 5);
$result = $this->Post->removeRating(3, $userId);
- $this->assertIsA($result, 'array');
+ $this->assertType('array', $result);
$this->assertEqual($result['Post']['rating'], '0');
$this->assertEqual($result['Post']['rating_count'], 0);
$this->assertEqual($result['Post']['rating_sum'], 0);
View
55 Test/Case/Component/RatingsTest.php → Test/Case/Component/RatingsComponentTest.php
@@ -9,10 +9,10 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::import('Controller', 'Controller', false);
-App::import('Component', array('Ratings.Ratings', 'Session', 'Auth'));
-Mock::generate('AuthComponent');
-Mock::generate('SessionComponent');
+App::uses('Controller', 'Controller');
+App::uses('Ratings.Ratings', 'Controller/Component');
+App::uses('Session', 'Controller/Component');
+App::uses('Auth', 'Controller/Component');
/**
* Test Article Model
@@ -130,11 +130,15 @@ function startTest() {
$this->Controller->modelClass = 'Article';
$this->Controller->constructClasses();
- $this->AuthComponent = new MockAuthComponent();
+ $this->Collection = $this->getMock('ComponentCollection');
+
+ $this->AuthComponent = $this->getMock('AuthComponent', array(), array($this->Collection));
+ //$this->AuthComponent = new MockAuthComponent();
$this->AuthComponent->enabled = true;
$this->Controller->Auth = $this->AuthComponent;
- $this->SessionComponent = new MockSessionComponent();
+ //$this->SessionComponent = new MockSessionComponent();
+ $this->SessionComponent = $this->getMock('AuthComponent', array(), array($this->Collection));
$this->SessionComponent->enabled = true;
$this->Controller->Session = $this->SessionComponent;
}
@@ -169,7 +173,12 @@ public function testInitialize() {
* @return void
*/
public function testInitializeWithParamsForBehavior() {
- $this->Controller->components = array('Ratings.Ratings' => array('update' => true), 'Session', 'Auth');
+ $this->Controller->components = array(
+ 'Ratings.Ratings' => array(
+ 'update' => true),
+ 'Session',
+ 'Auth');
+
$this->__initControllerAndRatings(array(), false);
$this->assertEqual($this->Controller->helpers, array(
'Session', 'Html', 'Form', 'Ratings.Rating'));
@@ -199,7 +208,10 @@ public function testInitializeWithParamsForComponent() {
* @return void
*/
public function testStartup() {
- $this->AuthComponent->setReturnValue('user', '1', array('id'));
+ //$this->AuthComponent->setReturnValue('user', '1', array('id'));
+ $this->AuthComponent->expects($this->any())->method('user')
+ ->with('1')
+ ->will($this->returnValue(array('id')));
$params = array(
'plugin' => null,
@@ -214,23 +226,23 @@ public function testStartup() {
'plugin' => null,
'controller' => 'articles',
'action' => 'test');
-
+/*
$this->Controller->Session->expectCallCount('setFlash', 3);
$this->Controller->Session->expectAt(0, 'setFlash', array('Your rate was successfull.', 'default', array(), 'success'));
$this->Controller->Session->expectAt(1, 'setFlash', array('You have already rated.', 'default', array(), 'error'));
$this->Controller->Session->expectAt(2, 'setFlash', array('Invalid rate.', 'default', array(), 'error'));
-
- $this->Controller->Session->write('Message', null);
+*/
+// $this->Controller->Session->write('Message', null);
$this->__initControllerAndRatings($params);
$this->assertEqual($this->Controller->redirect, $expectedRedirect);
- $this->Controller->Session->write('Message', null);
+// $this->Controller->Session->write('Message', null);
$params['named']['rate'] = '1';
$this->__initControllerAndRatings($params);
$this->assertEqual($this->Controller->redirect, $expectedRedirect);
- $this->Controller->Session->write('Message', null);
+// $this->Controller->Session->write('Message', null);
$params['named']['rate'] = 'invalid-record!';
$this->__initControllerAndRatings($params);
$this->assertEqual($this->Controller->redirect, $expectedRedirect);
@@ -242,7 +254,11 @@ public function testStartup() {
* @return void
*/
public function testStartupAcceptPost() {
- $this->AuthComponent->setReturnValue('user', '1', array('id'));
+ //$this->AuthComponent->setReturnValue('user', '1', array('id'));
+ $this->AuthComponent->expects($this->any())->method('user')
+ ->with('1')
+ ->will($this->returnValue(array('id')));
+
$params = array(
'plugin' => null,
'controller' => 'articles',
@@ -257,8 +273,9 @@ public function testStartupAcceptPost() {
'action' => 'test');
$this->Controller->data = array('Article' => array('rating' => 2));
- $this->Controller->Session->write('Message', null);
- $this->Controller->Session->expectOnce('setFlash');
+ //$this->Controller->Session->write('Message', null);
+
+ $this->Controller->Session->expects($this->any())->method('setFlash');
$this->__initControllerAndRatings($params);
$this->assertEqual($this->Controller->redirect, $expectedRedirect);
}
@@ -299,8 +316,10 @@ public function testBuildUrl() {
private function __initControllerAndRatings($params = array(), $doStartup = true) {
$_default = array('named' => array(), 'pass' => array());
$this->Controller->params = array_merge($_default, $params);
- $this->Controller->Component->init($this->Controller);
- $this->Controller->Component->initialize($this->Controller);
+ $this->Controller->Components->init($this->Controller);
+ //$this->Controller->Components->initialize($this->Controller);
+ $this->Controller->Components->trigger('initialize', array(&$this->Controller));
$this->Controller->Ratings->startup($this->Controller);
}
+
}
View
10 Test/Case/Helper/RatingHelperTest.php
@@ -9,9 +9,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-//App::import('Core', array('ClassRegistry', 'Controller', 'View', 'Model', 'Security'));
App::import('Helper', array('Html', 'Ratings.Rating', 'Form'));
-
App::uses('Controller', 'Controller');
@@ -133,8 +131,8 @@ public function testDisplay() {
'stars' => 2);
$result = $this->Rating->display($options);
- $expected ='<div class="input radio"><input type="radio" name="data[rating]" id="Rating1" value="1" /><label for="Rating1">1</label><input type="radio" name="data[rating]" id="Rating2" value="2" /><label for="Rating2">2</label></div>';
- $this->assertEqual($result, $expected);
+ $expected ='<div class="input radio"><input type="radio" name="data[rating]" id="Rating1" value="1" /><label for="Rating1">1</label><input type="radio" name="data[rating]" id="Rating2" value="2" /><label for="Rating2">2</label></div>';
+ $this->assertEqual($result, $expected);
$options = array(
'item' => '42',
@@ -143,8 +141,8 @@ public function testDisplay() {
'stars' => 2);
$result = $this->Rating->display($options);
- $expected ='<div class="input radio"><input type="radio" name="data[rating]" id="Rating1" value="1" /><label for="Rating1">1</label><input type="radio" name="data[rating]" id="Rating2" value="2" /><label for="Rating2">2</label></div>';
- $this->assertEqual($result, $expected);
+ $expected ='<div class="input radio"><input type="radio" name="data[rating]" id="Rating1" value="1" /><label for="Rating1">1</label><input type="radio" name="data[rating]" id="Rating2" value="2" /><label for="Rating2">2</label></div>';
+ $this->assertEqual($result, $expected);
}
/**
View
1 View/Helper/RatingHelper.php
@@ -164,6 +164,7 @@ public function starForm($options = array(), $urlHtmlAttributes = array()) {
}
$result .= $this->Form->input($inputField, array(
'type' => 'radio',
+ 'legend' => false,
'value' => isset($options['value']) ? round($options['value']) : 0,
'options' => array_combine(range(1, $options['stars']), range(1, $options['stars']))));
if ($options['createForm']) {

0 comments on commit 92c2060

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