Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Fully migrated plugin to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 12, 2012
1 parent 0d09a03 commit f892991
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 26 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 20 additions & 14 deletions models/problem.php → Model/Problem.php
Expand Up @@ -9,6 +9,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('AppModel', 'Model');

/**
* Problem Model
*
Expand Down Expand Up @@ -51,14 +53,28 @@ class Problem extends AppModel {
*
* @var array
*/
public $validate = array();
public $validate = array(
'user_id' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => 'Please enter a User')
),
'foreign_key' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => 'Please select item')
),
'type' => array(
'inList' => array('rule' => array('validType'), 'required' => false, 'allowEmpty' => true, 'message' => 'Please enter a valid problem type')
),
'description' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => 'Please enter a description of the problem.')
),
);


/**
* Custom find methods to use
*
* @var array
*/
public $_findMethods = array('totals' => true);
public $findMethods = array('totals' => true);

/**
* Constructor
Expand All @@ -69,16 +85,6 @@ class Problem extends AppModel {
*/
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->validate = array(
'user_id' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => __d('problems', 'Please enter a User'))),
'foreign_key' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => __d('problems', 'Please select item'))),
'type' => array(
'inList' => array('rule' => array('validType'), 'required' => false, 'allowEmpty' => true, 'message' => __d('problems', 'Please enter a valid problem type'))),
'description' => array(
'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => __d('problems', 'Please enter a description of the problem.'))),
);

$this->offensiveStatuses = array(
-1 => __d('problems', 'Ignore'),
Expand Down Expand Up @@ -230,7 +236,7 @@ public function validateAndDelete($id = null, $userId = null, $data = array()) {
}
}
$this->validate = $tmp;
throw new Exception(__d('problems', 'You need to confirm to delete this Problem'));
throw new BadMethodCallException(__d('problems', 'You need to confirm to delete this Problem'));
}
}

Expand Down Expand Up @@ -303,7 +309,7 @@ public function validType($check) {
* @param array $results
* @return mixed array for $state before containning the query, results when state is after
*/
public function _findTotals($state, $query, $results = array()) {
protected function _findTotals($state, $query, $results = array()) {
if ($state == 'before') {
if (!empty($query['operation']) && $query['operation'] === 'count') {
unset($query['limit']);
Expand Down
Expand Up @@ -14,7 +14,8 @@
* @package plugins.problems.tests.cases.behaviors
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Behavior', 'Problems.Reportable');

App::uses('ReportableBehavior', 'Problem.Model/Behavior');

class ProblematicArticle extends CakeTestModel {
public $name = 'ProblematicArticle';
Expand Down Expand Up @@ -105,20 +106,19 @@ public function testReport() {
unset($this->Article->mockAfterReport['savedData']['Problem']['modified']);

$expected = array(
'id' => 1,
'originalData' => $data,
'savedData' => array(
'Problem' => array(
'model' => 'ProblematicArticle',
'offensive' => 0,
'request_to_edit' => 0,
'offensive' => '0',
'request_to_edit' => '0',
'user_id' => 1,
'foreign_key' => 1,
'description' => 'My problem'
)
)
);

unset($this->Article->mockAfterReport['id'], $this->Article->mockAfterReport['savedData']['Problem']['id']);
$this->assertEquals($expected, $this->Article->mockAfterReport);
$this->assertFalse(empty($this->Article->Problem->id));
}
Expand Down
Expand Up @@ -14,8 +14,8 @@
* @package plugins.problems.test.cases.models
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Behavior', 'Problem.Reportable');

App::uses('ReportableBehavior', 'Problem.Model/Behavior');

class ProblematicArticle extends CakeTestModel {
public $name = 'ProblematicArticle';
Expand All @@ -28,7 +28,7 @@ class ProblemModelUser extends CakeTestModel {
}
/* Problem Test cases generated on: 2010-03-10 12:03:14 : 1268219054*/

class ProblemTestCase extends CakeTestCase {
class ProblemTest extends CakeTestCase {

/**
* Fixtures
Expand Down Expand Up @@ -157,7 +157,7 @@ public function testValidateAndDeleteInvalid() {
/**
* Test validateAndDelete with no confirmation sent by the user
*
* @expectedException Exception
* @expectedException BadMethodCallException
*/
public function testValidateAndDeleteNoConfirmation() {
$userId = '1';
Expand Down
Expand Up @@ -79,5 +79,4 @@ class ProblemFixture extends CakeTestFixture {
),
);

}
?>
}
Expand Up @@ -62,5 +62,4 @@ class ProblematicArticleFixture extends CakeTestFixture {
),
);

}
?>
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f892991

Please sign in to comment.