diff --git a/.gitignore b/.gitignore index e753000..24ffaea 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ app/tmp/logs/*.log app/webroot/uploads /nbproject/private/ .idea +.DS_Store \ No newline at end of file diff --git a/app/Config/core.php b/app/Config/core.php index 96d8acb..efc216f 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -32,7 +32,7 @@ * In production mode, flash messages redirect after a time interval. * In development mode, you need to click the flash message to continue. */ - Configure::write('debug', 0); + Configure::write('debug', 2); /** * Configure the Error handler used to handle errors for your application. By default @@ -227,7 +227,7 @@ Configure::write('Acl.database', 'default'); /** - * Uncomment this line and correct your server timezone to fix + * Uncomment this line and correct your server timezone to fix * any date & time related errors. */ //date_default_timezone_set('UTC'); @@ -237,7 +237,7 @@ * If running via cli - apc is disabled by default. ensure it's available and enabled in this case * * Note: 'default' and other application caches should be configured in app/Config/bootstrap.php. - * Please check the comments in boostrap.php for more info on the cache engines available + * Please check the comments in boostrap.php for more info on the cache engines available * and their setttings. */ $engine = 'File'; diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index e68f57a..956dc93 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -4,8 +4,9 @@ class AppController extends Controller { - public $theme = 'GuideOnTheSide'; - + public $theme = 'GuideOnTheSide'; + public $paginate = array(); + // GD settings var $padding = 10; // not the CSS padding, but the padding inside the image var $character_width = 8; @@ -29,15 +30,18 @@ function beforeFilter() { $this->helpers[] = 'Js'; // provide the role to all actions - $role_id = $this->Auth->user('role_id'); - $this->loadModel('Role'); - $this->Role->recursive = 0; - $role = $this->Role->findById($role_id); - $this->Session->write('Role', $role['Role']); + $is_logged_in = $this->Auth->user(); + if ($is_logged_in) { + $role_id = $this->Auth->user('role_id'); + $this->loadModel('Role'); + $this->Role->recursive = 0; + $role = $this->Role->findById($role_id); + $this->Session->write('Role', $role['Role']); + } $this->set('is_admin', $this->Session->read('Role.name') == 'admin'); $this->set('show_password_link', !$this->Auth->user('noLoginForm')); - + if ($theme = Configure::read('user_config.theme')) { $this->theme = $theme; } diff --git a/app/Controller/TutorialsController.php b/app/Controller/TutorialsController.php index 3e4b65a..90bcffb 100644 --- a/app/Controller/TutorialsController.php +++ b/app/Controller/TutorialsController.php @@ -528,11 +528,11 @@ function view_tutorial_only($id = null, $revision_id = null) { //$this->Tutorial->FinalQuiz->useDbConfig = 'default'; } - function add() { + public function add() { if (!empty($this->data)) { - $this->Tutorial->create(); - $this->data['Revision']['message'] = 'created'; + $this->data = array_merge($this->data, array('Revision' => array('message' => 'created'))); $this->Tutorial->user_id = $this->Session->read('Auth.User.id'); + $this->Tutorial->create(); if ($this->Tutorial->save($this->data)) { $this->Session->setFlash(__('The tutorial has been saved')); if ($this->data['Tutorial']['tutorial_type_id'] == TUTORIAL_TYPE_SIDEBYSIDE) { @@ -776,7 +776,7 @@ function view_heading_image($type = 'chapter', $text = '') { $this->layout = 'image'; $text = QH_urldecode($text); - + if ($type == 'chapter') { $string = ucfirst($type); if (!empty($text)) { @@ -841,7 +841,7 @@ function view_definition_image($link_text, $definition = '') { } else { $box_width = $this->padding * 2 + $this->number_of_characters * $this->character_width; } - + $image = imagecreatetruecolor($box_width, $box_height); $background = imagecolorallocate($image, 128, 194, 120); @@ -864,7 +864,7 @@ function view_text_box_image($type = 'one-line', $prompt = '', $placeholder = '' $this->layout = 'image'; $text = QH_urldecode($prompt); - + if ($type == 'one-line' || $type == 'multi-line') { $string = ucfirst($type); if (!empty($text)) { @@ -887,10 +887,10 @@ function view_text_box_image($type = 'one-line', $prompt = '', $placeholder = '' $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); - + imagefill($image, 0, 0, $white); imagerectangle($image, 0, 0, $box_width - 1, $box_height - 1, $black); - + $y = $this->padding + $this->character_height; foreach ($text as $line) { imagettftext($image, $this->font_size, 0, $this->padding, $y, $black, APP . 'Lib/unifont_5.1.20080907.ttf', $line); @@ -901,8 +901,8 @@ function view_text_box_image($type = 'one-line', $prompt = '', $placeholder = '' imagepng($image); imagedestroy($image); $this->autoRender = false; - } - + } + function provide_feedback($id = null, $mode = null) { $this->set('noGoogleAnalytics', true); if (!$id || !is_numeric($id)) { @@ -924,18 +924,18 @@ function provide_feedback($id = null, $mode = null) { htmlentities($this->data['Tutorial']['comment']); $tutorialUrl = Router::url(array('action' => $action, $id), true); $body .= "
" . __('This feedback was sent from %s', $tutorialUrl) . "
"; - + $message = new CakeEmail('default'); $message->subject(__('Feedback for %s tutorial', $tutorial['Tutorial']['title'])); $message->emailFormat('html'); - + $to_array = explode(',', Configure::read('user_config.email.send_all_feedback_to')); $to_array[] = $tutorial['Tutorial']['contact_email']; foreach ($to_array as $to) { $message->addBcc(trim($to)); } - + try { // haddress ("Honeypot address") is the honeypot field. // If it's filled out, pretend to send, but don't really. @@ -946,9 +946,9 @@ function provide_feedback($id = null, $mode = null) { exit(); } catch (Exception $e) { echo $e->getMessage(); - exit(); - } - + exit(); + } + } else { $this->layout = 'public'; $this->set(compact('tutorial', 'mode')); @@ -964,7 +964,7 @@ function view_certificate() { $is_quiz = false; $this->set('tutorial_grades', array()); $this->set('quiz_grades', array()); - + if (array_key_exists('tutorial_id', $this->request->data) && is_numeric($this->request->data['tutorial_id'])) { $tutorial = $this->Tutorial->read(null, $this->request->data['tutorial_id']); if ($tutorial['Tutorial']['certificate']) { @@ -973,16 +973,16 @@ function view_certificate() { if (!isset($this->request->data['questions'])) { $this->request->data['questions'] = array(); } - $this->set('tutorial_grades', $this->Tutorial->grade($this->request->data['tutorial_id'], + $this->set('tutorial_grades', $this->Tutorial->grade($this->request->data['tutorial_id'], $this->request->data['questions'])); - } + } } - + if (!isset($this->request->data['free-response'])) { $this->request->data['free-response'] = array(); } $this->set('free_responses', $this->request->data['free-response']); - + if (array_key_exists('quiz_id', $this->request->data) && is_numeric($this->request->data['quiz_id'])) { $final_quiz = $this->Tutorial->FinalQuiz->read(null, $this->request->data['quiz_id']); if ($final_quiz['FinalQuiz']['certificate']) { @@ -994,7 +994,7 @@ function view_certificate() { $this->set('quiz_grades', $this->Tutorial->FinalQuiz->grade($this->request->data['quiz_id'], $this->request->data['questions'])); } } - + // parse supplied email fields if ($is_tutorial || $is_quiz) { @@ -1008,18 +1008,18 @@ function view_certificate() { } $to_string .= $this->request->data['certificate_email']; } - + $this->set('date', date('F j, Y')); $this->set('time', date('g:ia')); $this->set('name', Sanitize::paranoid($this->request->data['certificate_name'], array(' '))); $this->set('title', $subject); - + $message = new CakeEmail('default'); $message->subject(__('Certificate of Completion for %s', $subject)); $message->template('certificate_of_completion'); $message->emailFormat('html'); $message->viewVars($this->viewVars); - + $to_array = explode(',', $to_string); foreach ($to_array as $key => $to) { if ($to == 'Emailaddresses' || empty($to)) { @@ -1034,7 +1034,7 @@ function view_certificate() { $email_success = true; } catch (Exception $e) { $email_success = $e->getMessage(); - } + } $this->viewPath = 'Emails/html'; $this->layout = 'Emails/html/default'; @@ -1049,7 +1049,7 @@ function view_certificate() { $this->Session->setFlash(__('The following message could not be sent.')); } } - + return $this->render('certificate_of_completion'); } else { return __('This certificate cannot be generated.'); diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index 4050d50..5d947b2 100644 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -2,101 +2,100 @@ class UsersController extends AppController { - var $paginate = - array( - 'limit' => 10, - 'order' => 'username ASC', - 'recursive' => 0, - ); + var $paginate = array( + 'limit' => 10, + 'order' => 'username ASC', + 'recursive' => 0, + ); - function beforeFilter() { - parent::beforeFilter(); - $user = $this->Auth->user(); - if (!in_array($this->action, $this->Auth->allowedActions)) { // if the action is not public - if (($this->action == 'edit') && ($user['id'] == $this->passedArgs[0]) && - (!$this->Auth->user('noLoginForm'))) { - ; // fall through to allow user to change password - } elseif (!$user || !($this->Session->read('Role.name') == 'admin')) { - // if they're not logged in or not admin - $this->redirect(array('controller' => 'tutorials')); - return; - } - } - } + function beforeFilter() { + parent::beforeFilter(); + $user = $this->Auth->user(); + if (!in_array($this->action, $this->Auth->allowedActions)) { // if the action is not public + if (($this->action == 'edit') && ($user['id'] == $this->passedArgs[0]) && + (!$this->Auth->user('noLoginForm'))) { + ; // fall through to allow user to change password + } elseif (!$user || !($this->Session->read('Role.name') == 'admin')) { + // if they're not logged in or not admin + $this->redirect(array('controller' => 'tutorials')); + return; + } + } + } function index() { $this->set('users', $this->paginate()); } function add() { - $hasLoginForm = !$this->Auth->user('noLoginForm'); + $hasLoginForm = !$this->Auth->user('noLoginForm'); if (!empty($this->data)) { - $this->data['User']['keep_password'] = false; - if (!$hasLoginForm) { - $this->data['User']['password'] = sha1(date('Y-m-d H:i:s') . mt_rand()); - $this->data['User']['password'] .= strtoupper($this->data['User']['password']); - // because the User model validates on this - $this->data['User']['password_confirmation'] = $this->data['User']['password']; - } - $this->User->create(); - if ($this->User->save($this->data)) { - $this->Session->setFlash(__('The user has been saved')); - $this->redirect(array('action' => 'index')); - } else { - $this->Session->setFlash(__('The user could not be saved. Please try again.'), 'default', - array('class' => 'page-error message')); - } - } - + $this->data = array_merge_recursive($this->data, array('User' => array('keep_password' => false))); + if (!$hasLoginForm) { + $this->data['User']['password'] = sha1(date('Y-m-d H:i:s') . mt_rand()); + $this->data['User']['password'] .= strtoupper($this->data['User']['password']); + // because the User model validates on this + $this->data['User']['password_confirmation'] = $this->data['User']['password']; + } + $this->User->create(); + if ($this->User->save($this->data)) { + $this->Session->setFlash(__('The user has been saved')); + $this->redirect(array('action' => 'index')); + } else { + $this->Session->setFlash(__('The user could not be saved. Please try again.'), 'default', + array('class' => 'page-error message')); + } + } + $roles = $this->User->Role->find('list'); $this->set(compact('roles', 'hasLoginForm')); } function edit($id = null) { - $hasLoginForm = !$this->Auth->user('noLoginForm'); - $user_is_self = ($this->Auth->user('id') == $id); - $this->User->id = $id; - + $hasLoginForm = !$this->Auth->user('noLoginForm'); + $user_is_self = ($this->Auth->user('id') == $id); + $this->User->id = $id; + if (!$id && empty($this->request->data)) { $this->Session->setFlash(__('Invalid user')); $this->redirect(array('action' => 'index')); } if (!empty($this->request->data)) { - $this->request->data['User']['keep_password'] = false; - if (!$hasLoginForm) { // Assuming that the only time we have a password field is when we have a form - $this->request->data['User']['keep_password'] = true; - } else { - // if empty, don't change password - if (empty($this->request->data['User']['password']) && empty($this->request->data['User']['password_confirmation'])) { - $this->request->data['User']['keep_password'] = true; - } - } - if ($user_is_self) { // don't allow user to change own username or role - $user = $this->User->findById($id); - if (isset($this->request->data['User']['username'])) { - $this->Session->setFlash(__('Don\'t change yourself. I like you the way you are.')); - $this->request->data['User']['username'] = $user['User']['username']; - } - if (isset($this->request->data['User']['role_id'])) { - $this->Session->setFlash(__('Don\'t change yourself. I like you the way you are.')); - $this->request->data['User']['role_id'] = $user['User']['role_id']; - } - } - if ($this->User->save($this->data)) { - $this->Session->setFlash(__('The user has been saved')); - $this->redirect(array('action' => 'index')); + $this->request->data['User']['keep_password'] = false; + if (!$hasLoginForm) { // Assuming that the only time we have a password field is when we have a form + $this->request->data['User']['keep_password'] = true; + } else { + // if empty, don't change password + if (empty($this->request->data['User']['password']) && empty($this->request->data['User']['password_confirmation'])) { + $this->request->data['User']['keep_password'] = true; + } + } + if ($user_is_self) { // don't allow user to change own username or role + $user = $this->User->findById($id); + if (isset($this->request->data['User']['username'])) { + $this->Session->setFlash(__('Don\'t change yourself. I like you the way you are.')); + $this->request->data['User']['username'] = $user['User']['username']; + } + if (isset($this->request->data['User']['role_id'])) { + $this->Session->setFlash(__('Don\'t change yourself. I like you the way you are.')); + $this->request->data['User']['role_id'] = $user['User']['role_id']; + } + } + if ($this->User->save($this->data)) { + $this->Session->setFlash(__('The user has been saved')); + $this->redirect(array('action' => 'index')); } else { - $this->Session->setFlash(__('The user could not be saved. Please try again.')); + $this->Session->setFlash(__('The user could not be saved. Please try again.')); } - } + } if (empty($this->request->data)) { $this->request->data = $this->User->read(null, $id); } - if (!$hasLoginForm && $user_is_self) { - $this->Session->setFlash(__('Don\'t change yourself. I like you the way you are.')); - $this->redirect(array('action' => 'index')); - } + if (!$hasLoginForm && $user_is_self) { + $this->Session->setFlash(__('Don\'t change yourself. I like you the way you are.')); + $this->redirect(array('action' => 'index')); + } $roles = $this->User->Role->find('list'); $this->set(compact('roles', 'hasLoginForm', 'user_is_self')); } @@ -106,15 +105,15 @@ function delete($id = null) { $this->Session->setFlash(__('Invalid id for user')); $this->redirect(array('action'=>'index')); } - if ($this->Auth->user('id') == $id) { - $this->Session->setFlash(__("Don't delete yourself!")); + if ($this->Auth->user('id') == $id) { + $this->Session->setFlash(__("Don't delete yourself!")); $this->redirect(array('action' => 'index')); - } else { - if ($this->User->delete($id)) { - $this->Session->setFlash(__('User deleted')); - $this->redirect(array('action'=>'index')); - } - } + } else { + if ($this->User->delete($id)) { + $this->Session->setFlash(__('User deleted')); + $this->redirect(array('action'=>'index')); + } + } $this->Session->setFlash(__('User was not deleted')); $this->redirect(array('action' => 'index')); } diff --git a/app/Model/Behavior/SteppableBehavior.php b/app/Model/Behavior/SteppableBehavior.php index eea9735..3320283 100644 --- a/app/Model/Behavior/SteppableBehavior.php +++ b/app/Model/Behavior/SteppableBehavior.php @@ -9,16 +9,16 @@ class SteppableBehavior extends ModelBehavior { var $general_question_pattern = '/\
* $this->Blog->hasAndBelongsToMany['Tag']['fields'] = array('name', 'keyname');
* $blog = $this->Blog->read(null, 123);
* $blog['Blog']['tags'] = $this->Blog->Tag->tagArrayToString($blog['Tag']);
*
*
- * @param array $string
+ * @param Model $model Model instance that behavior is attached to
+ * @param array $data Tag data array
* @return string
*/
- public function tagArrayToString(Model $Model, $data = null) {
+ public function tagArrayToString(Model $model, $data = null) {
if ($data) {
- return join($this->settings[$Model->alias]['separator'].' ', Set::extract($data, '{n}.name'));
+ $tags = array();
+ foreach ($data as $tag) {
+ if (!empty($tag['identifier'])) {
+ $tags[] = $tag['identifier'] . ':' . $tag['name'];
+ } else {
+ $tags[] = $tag['name'];
+ }
+ }
+ return join($this->settings[$model->alias]['separator'] . ' ', $tags);
}
return '';
}
@@ -325,28 +390,65 @@ public function tagArrayToString(Model $Model, $data = null) {
/**
* afterSave callback
*
- * @param AppModel $Model
+ * @param Model $model Model instance that behavior is attached to
+ * @param bool $created True if this save created a new record
+ * @param array $options Options passed from Model::save()
+ * @return void
*/
- public function afterSave(Model $Model) {
- if ($this->settings[$Model->alias]['automaticTagging'] == true && !empty($Model->data[$Model->alias][$this->settings[$Model->alias]['field']])) {
- $this->saveTags($Model, $Model->data[$Model->alias][$this->settings[$Model->alias]['field']], $Model->id);
+ public function afterSave(Model $model, $created, $options = array()) {
+ if (!isset($model->data[$model->alias][$this->settings[$model->alias]['field']])) {
+ return;
+ }
+ $field = $model->data[$model->alias][$this->settings[$model->alias]['field']];
+ $hasTags = !empty($field);
+ if ($this->settings[$model->alias]['automaticTagging'] === true && $hasTags) {
+ $this->saveTags($model, $field, $model->id);
+ } elseif (!$hasTags && $this->settings[$model->alias]['deleteTagsOnEmptyField']) {
+ $this->deleteTagged($model);
}
}
+/**
+ * Delete associated Tags if record has no tags and deleteTagsOnEmptyField is true
+ *
+ * @param Model $model Model instance that behavior is attached to
+ * @param mixed $id Foreign key of the model, string for UUID or integer
+ * @return void
+ */
+ public function deleteTagged(Model $model, $id = null) {
+ extract($this->settings[$model->alias]);
+ $tagModel = $model->{$tagAlias};
+ if (is_null($id)) {
+ $id = $model->id;
+ }
+ $tagModel->{$taggedAlias}->deleteAll(
+ array(
+ $taggedAlias . '.model' => $model->name,
+ $taggedAlias . '.foreign_key' => $id,
+ )
+ );
+ }
+
/**
* afterFind Callback
*
- * @param AppModel $Model
- * @param array $results
- * @param boolean $primary
+ * @param Model $model Model instance that behavior is attached to
+ * @param mixed $results The results of the find operation
+ * @param bool $primary Whether this model is being queried directly (vs. being queried as an association)
* @return array
*/
- public function afterFind(Model $Model, $results, $primary) {
- extract($this->settings[$Model->alias]);
+ public function afterFind(Model $model, $results, $primary = false) {
+ extract($this->settings[$model->alias]);
+
+ list($plugin, $class) = pluginSplit($tagClass);
+ if ($model->name === $class) {
+ return $results;
+ }
+
foreach ($results as $key => $row) {
- $row[$Model->alias][$field] = '';
+ $row[$model->alias][$field] = '';
if (isset($row[$tagAlias]) && !empty($row[$tagAlias])) {
- $row[$Model->alias][$field] = $this->tagArrayToString($Model, $row[$tagAlias]);
+ $row[$model->alias][$field] = $this->tagArrayToString($model, $row[$tagAlias]);
if ($unsetInAfterFind == true) {
unset($row[$tagAlias]);
}
@@ -355,4 +457,5 @@ public function afterFind(Model $Model, $results, $primary) {
}
return $results;
}
+
}
diff --git a/app/Plugin/Tags/Model/Tag.php b/app/Plugin/Tags/Model/Tag.php
old mode 100644
new mode 100755
index 0608b63..38baf5e
--- a/app/Plugin/Tags/Model/Tag.php
+++ b/app/Plugin/Tags/Model/Tag.php
@@ -1,13 +1,14 @@
array(
'className' => 'Tags.Tagged',
- 'foreignKey' => 'tag_id'));
+ 'foreignKey' => 'tag_id'
+ )
+ );
/**
* HABTM associations
@@ -47,42 +43,63 @@ class Tag extends TagsAppModel {
* @var array
*/
public $validate = array(
- 'name' => array('rule' => 'notEmpty'),
- 'keyname' => array('rule' => 'notEmpty'));
+ 'name' => array('rule' => 'notBlank'),
+ 'keyname' => array('rule' => 'notBlank')
+ );
+
+/**
+ * Custom validation for keeping BC to CakePHP version below 2.7
+ *
+ * @param array $check
+ * @return bool
+ */
+ public function notBlank($check) {
+ $value = array_values($check);
+ $value = $value[0];
+ if (method_exists('Validation', 'notBlank')) {
+ return Validation::notBlank($value);
+ } else {
+ // below 2.7
+ return Validation::notEmpty($value);
+ }
+ }
/**
* Returns the data for a single tag
*
- * @param string keyname
+ * @param string $keyName Tag key name
+ * @throws CakeException
* @return array
*/
public function view($keyName = null) {
$result = $this->find('first', array(
'conditions' => array(
- $this->alias . '.keyname' => $keyName)));
+ $this->alias . '.keyname' => $keyName
+ )
+ ));
if (empty($result)) {
- throw new Exception(__d('tags', 'Invalid Tag.'));
+ throw new CakeException(__d('tags', 'Invalid Tag.'));
}
return $result;
}
-
/**
* Pre-populates the tag table with entered tags
*
- * @param array post data, should be Contoller->data
- * @return boolean
+ * @param array $postData Post data, should be Contoller->data
+ * @return bool
*/
public function add($postData = null) {
if (isset($postData[$this->alias]['tags'])) {
- $this->Behaviors->attach('Tags.Taggable', array(
+ $this->Behaviors->load('Tags.Taggable', array(
'resetBinding' => true,
- 'automaticTagging' => false));
+ 'automaticTagging' => false
+ ));
$this->Tag = $this;
$result = $this->saveTags($postData[$this->alias]['tags'], false, false);
unset($this->Tag);
- $this->Behaviors->detach('Tags.Taggable');
+ $this->Behaviors->unload('Tags.Taggable');
return $result;
}
}
@@ -90,19 +107,22 @@ public function add($postData = null) {
/**
* Edits an existing tag, allows only to modify upper/lowercased characters
*
- * @param string tag uuid
- * @param array controller post data usually $this->request->data
+ * @param string $tagId Tag UUID
+ * @param array $postData Controller post data usually $this->request->data
+ * @throws CakeException
* @return mixed True on successfully save else post data as array
*/
public function edit($tagId = null, $postData = null) {
$tag = $this->find('first', array(
'contain' => array(),
'conditions' => array(
- $this->alias . '.' . $this->primaryKey => $tagId)));
+ $this->alias . '.' . $this->primaryKey => $tagId
+ )
+ ));
$this->set($tag);
if (empty($tag)) {
- throw new Exception(__d('tags', 'Invalid Tag.'));
+ throw new CakeException(__d('tags', 'Invalid Tag.'));
}
if (!empty($postData[$this->alias]['name'])) {
@@ -119,4 +139,5 @@ public function edit($tagId = null, $postData = null) {
}
}
}
+
}
diff --git a/app/Plugin/Tags/Model/Tagged.php b/app/Plugin/Tags/Model/Tagged.php
old mode 100644
new mode 100755
index 0bba38c..4f0ae38
--- a/app/Plugin/Tags/Model/Tagged.php
+++ b/app/Plugin/Tags/Model/Tagged.php
@@ -1,13 +1,14 @@
true,
- 'tagged' => true);
+ 'tagged' => true
+ );
/**
* belongsTo associations
@@ -47,25 +42,27 @@ class Tagged extends TagsAppModel {
*/
public $belongsTo = array(
'Tag' => array(
- 'className' => 'Tags.Tag'));
+ 'className' => 'Tags.Tag'
+ )
+ );
/**
* Returns a tag cloud
*
* The result contains a "weight" field which has a normalized size of the tag
- * occurrence set. The min and max size can be set by passing 'minSize" and
- * 'maxSize' to the query. This value can be used in the view to controll the
+ * occurrence set. The min and max size can be set by passing 'minSize' and
+ * 'maxSize' to the query. This value can be used in the view to control the
* size of the tag font.
*
+ * @param string $state State string ('before' or 'after')
+ * @param array $query Query array
+ * @param array $results Result set for 'after' state
* @todo Ideas to improve this are welcome
- * @param string $state
- * @param array $query
- * @param array $results
* @return array
* @link https://github.com/CakeDC/tags/issues/10
*/
public function _findCloud($state, $query, $results = array()) {
- if ($state == 'before') {
+ if ($state === 'before') {
// Support old code without the occurrence cache
if (!$this->Tag->hasField('occurrence') || isset($query['occurrenceCache']) && $query['occurrenceCache'] === false) {
$fields = 'Tagged.tag_id, Tag.id, Tag.identifier, Tag.name, Tag.keyname, Tag.weight, COUNT(*) AS occurrence';
@@ -88,7 +85,8 @@ public function _findCloud($state, $query, $results = array()) {
'contain' => 'Tag',
'conditions' => array(),
'fields' => $fields,
- 'group' => $groupBy);
+ 'group' => $groupBy
+ );
foreach ($query as $key => $value) {
if (!empty($value)) {
@@ -135,22 +133,24 @@ public function _findCloud($state, $query, $results = array()) {
/**
* Find all the Model entries tagged with a given tag
- *
+ *
* The query must contain a Model name, and can contain a 'by' key with the Tag keyname to filter the results
+ *
*
* $this->Article->Tagged->find('tagged', array(
* 'by' => 'cakephp',
* 'model' => 'Article'));
- *
*
- * @TODO Find a way to populate the "magic" field Article.tags
- * @param string $state
- * @param array $query
- * @param array $results
+ * @param string $state State string ('before' or 'after')
+ * @param array $query Query array
+ * @param array $results Result set for 'after' state
+ * @todo Find a way to populate the "magic" field Article.tags
+ * @throws InvalidArgumentException if recursive setting is -1
* @return mixed Query array if state is before, array of results or integer (count) if state is after
*/
public function _findTagged($state, $query, $results = array()) {
- if ($state == 'before') {
+ if ($state === 'before') {
if (isset($query['model']) && $Model = ClassRegistry::init($query['model'])) {
$this->bindModel(array(
'belongsTo' => array(
@@ -159,7 +159,11 @@ public function _findTagged($state, $query, $results = array()) {
'foreignKey' => 'foreign_key',
'type' => 'INNER',
'conditions' => array(
- $this->alias . '.model' => $Model->alias)))), false);
+ $this->alias . '.model' => $Model->alias
+ )
+ )
+ )
+ ), false);
if (!isset($query['recursive'])) {
$query['recursive'] = 0;
@@ -173,7 +177,11 @@ public function _findTagged($state, $query, $results = array()) {
$query['fields'] = "COUNT(DISTINCT $Model->alias.$Model->primaryKey)";
$this->Behaviors->Containable->setup($this, array('autoFields' => false));
} else {
- $query['fields'][] = "DISTINCT " . join(',', $this->getDataSource()->fields($Model));
+ if ($query['fields'] === null) {
+ $query['fields'][] = "DISTINCT " . join(',', $this->getDataSource()->fields($Model));
+ } else {
+ array_unshift($query['fields'], "DISTINCT " . join(',', $this->getDataSource()->fields($Model)));
+ }
}
if (!empty($query['by'])) {
diff --git a/app/Plugin/Tags/Model/TagsAppModel.php b/app/Plugin/Tags/Model/TagsAppModel.php
old mode 100644
new mode 100755
index 450c1bb..783b6e6
--- a/app/Plugin/Tags/Model/TagsAppModel.php
+++ b/app/Plugin/Tags/Model/TagsAppModel.php
@@ -1,14 +1,15 @@
find('count', array_merge($parameters, $extra));
}
}
+
}
diff --git a/app/Plugin/Tags/Test/Case/AllTagsPluginTest.php b/app/Plugin/Tags/Test/Case/AllTagsPluginTest.php
deleted file mode 100644
index 7a9075f..0000000
--- a/app/Plugin/Tags/Test/Case/AllTagsPluginTest.php
+++ /dev/null
@@ -1,25 +0,0 @@
-addTestFile($basePath . 'Controller' . DS . 'TagsControllerTest.php');
- // behaviors
- $suite->addTestFile($basePath . 'Behavior' . DS . 'TaggableTest.php');
- // models
- $suite->addTestFile($basePath . 'Model' . DS . 'TagTest.php');
- $suite->addTestFile($basePath . 'Model' . DS . 'TaggedTest.php');
- // helpers
- $suite->addTestFile($basePath . 'Helper' . DS . 'TagCloudTest.php');
- return $suite;
- }
-
-}
\ No newline at end of file
diff --git a/app/Plugin/Tags/Test/Case/AllTagsTest.php b/app/Plugin/Tags/Test/Case/AllTagsTest.php
new file mode 100755
index 0000000..fff711b
--- /dev/null
+++ b/app/Plugin/Tags/Test/Case/AllTagsTest.php
@@ -0,0 +1,20 @@
+addTestDirectory($path . DS . 'Controller');
+ $Suite->addTestDirectory($path . DS . 'View' . DS . 'Helper');
+ $Suite->addTestDirectory($path . DS . 'Model');
+ $Suite->addTestDirectory($path . DS . 'Model' . DS . 'Behavior');
+ return $Suite;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Plugin/Tags/Test/Case/Behavior/TaggableTest.php b/app/Plugin/Tags/Test/Case/Behavior/TaggableTest.php
deleted file mode 100644
index f300cb1..0000000
--- a/app/Plugin/Tags/Test/Case/Behavior/TaggableTest.php
+++ /dev/null
@@ -1,301 +0,0 @@
-Article = ClassRegistry::init('Article');
- $this->Article->Behaviors->attach('Tags.Taggable', array());
- }
-
-/**
- * Method executed after each test
- *
- * @return void
- */
- public function tearDown() {
- unset($this->Article);
- ClassRegistry::flush();
- }
-
-/**
- * Test the occurrence cache
- *
- * @return void
- */
- public function testOccurrenceCache() {
- $resultBefore = $this->Article->Tag->find('first', array(
- 'contain' => array(),
- 'conditions' => array(
- 'Tag.keyname' => 'cakephp')));
-
- // adding a new record with the cakephp tag to increase the occurrence
- $data = array('title' => 'Test Article', 'tags' => 'cakephp, php');
- $this->Article->create();
- $this->Article->save($data, false);
-
- $resultAfter = $this->Article->Tag->find('first', array(
- 'contain' => array(),
- 'conditions' => array(
- 'Tag.keyname' => 'cakephp')));
-
- $this->assertEqual($resultAfter['Tag']['occurrence'] - $resultBefore['Tag']['occurrence'], 1);
-
- // updating the record to not have the cakephp tag anymore, decreases the occurrence
- $data = array('id' => $this->Article->id, 'title' => 'Test Article', 'tags' => 'php, something, else');
- $this->Article->save($data, false);
- $resultAfter = $this->Article->Tag->find('first', array(
- 'contain' => array(),
- 'conditions' => array(
- 'Tag.keyname' => 'cakephp')));
- $this->assertEqual($resultAfter['Tag']['occurrence'], 1);
- }
-
-/**
- * Testings saving of tags trough the specified field in the tagable model
- *
- * @return void
- */
- public function testTagSaving() {
- $data['id'] = 'article-1';
- $data['tags'] = 'foo, bar, test';
- $this->Article->save($data, false);
- $result = $this->Article->find('first', array(
- 'conditions' => array(
- 'id' => 'article-1')));
- $this->assertTrue(!empty($result['Article']['tags']));
-
- $data['tags'] = 'foo, developer, developer, php';
- $this->Article->save($data, false);
- $result = $this->Article->find('first', array(
- 'contain' => array('Tag'),
- 'conditions' => array(
- 'id' => 'article-1')));
- $this->assertTrue(!empty($result['Article']['tags']));
-
-
- $data['tags'] = 'cakephp:foo, developer, cakephp:developer, cakephp:php';
- $this->Article->save($data, false);
- $result = $this->Article->Tag->find('all', array(
- 'recursive' => -1,
- 'order' => 'Tag.identifier DESC',
- 'conditions' => array(
- 'Tag.identifier' => 'cakephp')));
- $result = Set::extract($result, '{n}.Tag.keyname');
- $this->assertEqual($result, array(
- 'foo', 'developer', 'php'));
-
- $this->assertFalse($this->Article->saveTags('foo, bar', null));
- $this->assertFalse($this->Article->saveTags(array('foo', 'bar'), 'something'));
- }
-
-/**
- * Tests that toggling taggedCounter will update the time_tagged counter in the tagged table
- *
- * @return void
- */
- function testSaveTimesTagged() {
- $this->Article->Behaviors->Taggable->settings['Article']['taggedCounter'] = true;
- $tags = 'foo, bar , test';
- $this->assertTrue($this->Article->saveTags($tags, 'article-1', false));
- $this->assertTrue($this->Article->saveTags($tags, 'article-1', false));
-
- $result = $this->Article->Tagged->find('all', array(
- 'conditions' => array('model' => 'Article')));
-
- $fooCount = Set::extract('/Tag[keyname=foo]/../Tagged/times_tagged', $result);
- $this->assertEqual($fooCount, array(2));
-
- $barCount = Set::extract('/Tag[keyname=bar]/../Tagged/times_tagged', $result);
- $this->assertEqual($barCount, array(2));
-
- $testCount = Set::extract('/Tag[keyname=test]/../Tagged/times_tagged', $result);
- $this->assertEqual($testCount, array(2));
- }
-
-/**
- * Testings Taggable::tagArrayToString()
- *
- * @return void
- */
- public function testTagArrayToString() {
- $data['id'] = 'article-1';
- $data['tags'] = 'foo, bar, test';
- $this->Article->save($data, false);
- $result = $this->Article->find('first', array(
- 'conditions' => array(
- 'id' => 'article-1')));
- $result = $this->Article->tagArrayToString($result['Tag']);
- $this->assertTrue(!empty($result));
- $this->assertInternalType('string', $result);
-
- $result = $this->Article->tagArrayToString();
- $this->assertTrue(empty($result));
- $this->assertInternalType('string', $result);
- }
-
-/**
- * Testings Taggable::multibyteKey()
- *
- * @return void
- */
- public function testMultibyteKey() {
- $result = $this->Article->multibyteKey('this is _ a Nice ! - _ key!');
- $this->assertEqual('thisisanicekey', $result);
-
- $result = $this->Article->multibyteKey('Äü-Ü_ß');
- $this->assertEqual('äüüß', $result);
- }
-
-/**
- * testAfterFind callback method
- *
- * @return void
- */
- public function testAfterFind() {
- $data['id'] = 'article-1';
- $data['tags'] = 'foo, bar, test';
- $this->Article->save($data, false);
-
- $result = $this->Article->find('first', array(
- 'conditions' => array(
- 'id' => 'article-1')));
- $this->assertTrue(isset($result['Tag']));
-
- $this->Article->Behaviors->Taggable->settings['Article']['unsetInAfterFind'] = true;
- $result = $this->Article->find('first', array(
- 'conditions' => array(
- 'id' => 'article-1')));
- $this->assertTrue(!isset($result['Tag']));
- }
-
-/**
- * testAfterFindFields
- *
- * @return void
- */
- public function testAfterFindFields() {
- $this->Article->Behaviors->detach('Taggable');
- $results = $this->Article->find('first', array(
- 'recursive' => -1,
- 'fields' => array('id')));
- $expected = array($this->Article->alias => array('id' => 'article-1'));
- $this->assertIdentical($results, $expected);
- }
-
-/**
- * testGettingTagCloudThroughAssociation
- *
- * @link http://cakedc.lighthouseapp.com/projects/59622/tickets/6-tag-cloud-helper
- * @return void
- */
- public function testGettingTagCloudThroughAssociation() {
- $result = $this->Article->Tagged->find('cloud');
- $this->assertTrue(is_array($result) && !empty($result));
- }
-
-}
diff --git a/app/Plugin/Tags/Test/Case/Controller/TagsControllerTest.php b/app/Plugin/Tags/Test/Case/Controller/TagsControllerTest.php
old mode 100644
new mode 100755
index db2e888..d3ab2d2
--- a/app/Plugin/Tags/Test/Case/Controller/TagsControllerTest.php
+++ b/app/Plugin/Tags/Test/Case/Controller/TagsControllerTest.php
@@ -1,17 +1,16 @@
redirectUrl`)
+ * @param int $status Optional HTTP status code (eg: 404)
+ * @param bool $exit If true, exit() will be called after the redirect
* @return void
*/
public function redirect($url, $status = null, $exit = true) {
@@ -47,11 +49,14 @@ public function redirect($url, $status = null, $exit = true) {
/**
* Override controller method for testing
*
+ * @param string $view View to use for rendering
+ * @param string $layout Layout to use
* @return void
*/
- public function render($action = null, $layout = null, $file = null) {
- $this->renderedView = $action;
+ public function render($view = null, $layout = null) {
+ $this->renderedView = $view;
}
+
}
/**
@@ -69,7 +74,8 @@ class TagsControllerTest extends CakeTestCase {
*/
public $fixtures = array(
'plugin.tags.tagged',
- 'plugin.tags.tag');
+ 'plugin.tags.tag'
+ );
/**
* Tags Controller Instance
@@ -84,10 +90,12 @@ class TagsControllerTest extends CakeTestCase {
* @return void
*/
public function setUp() {
+ parent::setUp();
$this->Tags = new TestTagsController(new CakeRequest(null, false));
$this->Tags->params = array(
'named' => array(),
- 'url' => array());
+ 'url' => array()
+ );
$this->Tags->constructClasses();
$this->Tags->Session = $this->getMock('SessionComponent', array(), array(), '', false);
}
@@ -98,6 +106,7 @@ public function setUp() {
* @return void
*/
public function tearDown() {
+ parent::tearDown();
unset($this->Tags);
}
@@ -128,10 +137,10 @@ public function testIndex() {
public function testView() {
$this->Tags->view('cakephp');
$this->assertTrue(!empty($this->Tags->viewVars['tag']));
- $this->assertEqual($this->Tags->viewVars['tag']['Tag']['keyname'], 'cakephp');
+ $this->assertEquals($this->Tags->viewVars['tag']['Tag']['keyname'], 'cakephp');
$this->Tags->view('invalid-key-name!');
- $this->assertEqual($this->Tags->redirectUrl, '/');
+ $this->assertEquals($this->Tags->redirectUrl, '/');
}
/**
@@ -142,10 +151,10 @@ public function testView() {
public function testAdminView() {
$this->Tags->admin_view('cakephp');
$this->assertTrue(!empty($this->Tags->viewVars['tag']));
- $this->assertEqual($this->Tags->viewVars['tag']['Tag']['keyname'], 'cakephp');
+ $this->assertEquals($this->Tags->viewVars['tag']['Tag']['keyname'], 'cakephp');
$this->Tags->admin_view('invalid-key-name!');
- $this->assertEqual($this->Tags->redirectUrl, '/');
+ $this->assertEquals($this->Tags->redirectUrl, '/');
}
/**
@@ -166,20 +175,19 @@ public function testAdminIndex() {
public function testAdminDelete() {
$this->Tags->Session->expects($this->at(0))
->method('setFlash')
- ->with($this->equalTo('Invalid Tag.'))
+ ->with($this->equalTo(__d('tags', 'Invalid Tag.')))
->will($this->returnValue(true));
$this->Tags->Session->expects($this->at(1))
->method('setFlash')
- ->with($this->equalTo('Tag deleted.'))
+ ->with($this->equalTo(__d('tags', 'Tag deleted.')))
->will($this->returnValue(true));
-
$this->Tags->admin_delete('WRONG-ID!!!');
- $this->assertEqual($this->Tags->redirectUrl, array('action' => 'index'));
+ $this->assertEquals($this->Tags->redirectUrl, array('action' => 'index'));
$this->Tags->admin_delete('tag-1');
- $this->assertEqual($this->Tags->redirectUrl, array('action' => 'index'));
+ $this->assertEquals($this->Tags->redirectUrl, array('action' => 'index'));
}
/**
@@ -190,9 +198,20 @@ public function testAdminDelete() {
public function testAdminAdd() {
$this->Tags->data = array(
'Tag' => array(
- 'tags' => 'tag1, tag2, tag3'));
+ 'tags' => 'tag1, tag2, tag3'
+ )
+ );
+ $this->Tags->admin_add();
+ $this->assertEquals($this->Tags->redirectUrl, array('action' => 'index'));
+
+ // adding same tags again.
+ $this->Tags->data = array(
+ 'Tag' => array(
+ 'tags' => 'tag1, tag2, tag3'
+ )
+ );
$this->Tags->admin_add();
- $this->assertEqual($this->Tags->redirectUrl, array('action' => 'index'));
+ $this->assertEquals($this->Tags->redirectUrl, array('action' => 'index'));
}
/**
@@ -204,23 +223,27 @@ public function testAdminEdit() {
$this->Tags->admin_edit('tag-1');
$tag = array(
'Tag' => array(
- 'id' => 'tag-1',
- 'identifier' => null,
- 'name' => 'CakePHP',
- 'keyname' => 'cakephp',
+ 'id' => 'tag-1',
+ 'identifier' => null,
+ 'name' => 'CakePHP',
+ 'keyname' => 'cakephp',
'occurrence' => 1,
'article_occurrence' => 1,
- 'created' => '2008-06-02 18:18:11',
- 'modified' => '2008-06-02 18:18:37'));
+ 'created' => '2008-06-02 18:18:11',
+ 'modified' => '2008-06-02 18:18:37'
+ )
+ );
- $this->assertEqual($this->Tags->data, $tag);
+ $this->assertEquals($this->Tags->data, $tag);
$this->Tags->data = array(
'Tag' => array(
'id' => 'tag-1',
- 'name' => 'CAKEPHP'));
+ 'name' => 'CAKEPHP'
+ )
+ );
$this->Tags->admin_edit('tag-1');
- $this->assertEqual($this->Tags->redirectUrl, array('action' => 'index'));
+ $this->assertEquals($this->Tags->redirectUrl, array('action' => 'index'));
}
}
diff --git a/app/Plugin/Tags/Test/Case/Helper/TagCloudTest.php b/app/Plugin/Tags/Test/Case/Helper/TagCloudTest.php
deleted file mode 100644
index 770fef9..0000000
--- a/app/Plugin/Tags/Test/Case/Helper/TagCloudTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-View = new View($controller);
- $this->TagCloud = new TagCloudHelper($this->View);
- $this->TagCloud->Html = new HtmlHelper($this->View);
- }
-
-/**
- * Test display method
- *
- * @return void
- */
- public function testDisplay() {
- $this->assertEqual($this->TagCloud->display(), '');
- $tags = array(
- array(
- 'Tag' => array(
- 'id' => 1,
- 'identifier' => null,
- 'name' => 'CakePHP',
- 'keyname' => 'cakephp',
- 'weight' => 2,
- 'created' => '2008-06-02 18:18:11',
- 'modified' => '2008-06-02 18:18:37')),
- array(
- 'Tag' => array(
- 'id' => 2,
- 'identifier' => null,
- 'name' => 'CakeDC',
- 'keyname' => 'cakedc',
- 'weight' => 2,
- 'created' => '2008-06-01 18:18:15',
- 'modified' => '2008-06-01 18:18:15')),
- );
-
- // Test tags shuffling
- $options = array(
- 'shuffle' => true);
- $expected = 'CakePHP CakeDC ';
- $i = 100;
- do {
- $i--;
- $result = $this->TagCloud->display($tags, $options);
- } while ($result == $expected && $i > 0);
- $this->assertNotEqual($result, $expected);
-
- // Test normal display
- $options = array(
- 'shuffle' => false);
- $result = $this->TagCloud->display($tags, $options);
- $this->assertEqual($result, $expected);
-
- // Test options
- $options = array_merge($options, array(
- 'before' => '',
- 'after' => '',
- 'maxSize' => 100,
- 'minSize' => 1,
- 'url' => array('controller' => 'search', 'from' => 'twitter'),
- 'named' => 'query'
- ));
- $result = $this->TagCloud->display($tags, $options);
- $expected = 'CakePHP '.
- 'CakeDC ';
- $this->assertEqual($result, $expected);
-
- $tags[1]['Tag']['weight'] = 1;
- $result = $this->TagCloud->display($tags, $options);
- $expected = 'CakePHP '.
- 'CakeDC ';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * (non-PHPdoc)
- * @see cake/tests/lib/CakeTestCase#tearDown($method)
- */
- public function tearDown() {
- unset($this->TagCloud, $this->View);
- ClassRegistry::flush();
- }
-}
diff --git a/app/Plugin/Tags/Test/Case/Model/Behavior/TaggableBehaviorTest.php b/app/Plugin/Tags/Test/Case/Model/Behavior/TaggableBehaviorTest.php
new file mode 100755
index 0000000..1cf72df
--- /dev/null
+++ b/app/Plugin/Tags/Test/Case/Model/Behavior/TaggableBehaviorTest.php
@@ -0,0 +1,538 @@
+ array(),
+ 'noPluginPrefix' => array(
+ 'tagClass' => 'Tag',
+ 'taggedClass' => 'Tagged',
+ ),
+ 'customAliasAndClass' => array(
+ 'tagAlias' => 'CustomTagAlias',
+ 'taggedAlias' => 'CustomTaggedAlias',
+ 'tagClass' => 'Tags.CustomTag',
+ 'taggedClass' => 'Tags.CustomTagged',
+ ),
+ );
+
+/**
+ * Run test cases multiple times with different behavior settings
+ *
+ * @param PHPUnit_Framework_TestResult $result The test result object
+ * @return PHPUnit_Framework_TestResult
+ */
+ public function run(PHPUnit_Framework_TestResult $result = null) {
+ foreach ($this->behaviorSettings as $behaviorSettings) {
+ $this->behaviorSettings = $behaviorSettings;
+ $result = parent::run($result);
+ }
+
+ return $result;
+ }
+
+/**
+ * Method executed before each test
+ *
+ * @return void
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->Article = ClassRegistry::init('Article');
+ Configure::write('Config.language', 'eng');
+ $this->Article->Behaviors->attach('Tags.Taggable', $this->behaviorSettings);
+ }
+
+/**
+ * Method executed after each test
+ *
+ * @return void
+ */
+ public function tearDown() {
+ parent::tearDown();
+ unset($this->Article);
+ ClassRegistry::flush();
+ }
+
+/**
+ * Test the occurrence cache
+ *
+ * @return void
+ */
+ public function testOccurrenceCache() {
+ $tagAlias = $this->Article->Behaviors->Taggable->settings['Article']['tagAlias'];
+
+ $resultBefore = $this->Article->{$tagAlias}->find('first', array(
+ 'contain' => array(),
+ 'conditions' => array(
+ $tagAlias . '.keyname' => 'cakephp'
+ )
+ ));
+
+ // adding a new record with the cakephp tag to increase the occurrence
+ $data = array('title' => 'Test Article', 'tags' => 'cakephp, php');
+ $this->Article->create();
+ $this->Article->save($data, false);
+
+ $resultAfter = $this->Article->{$tagAlias}->find('first', array(
+ 'contain' => array(),
+ 'conditions' => array(
+ $tagAlias . '.keyname' => 'cakephp'
+ )
+ ));
+
+ $this->assertEquals($resultAfter[$tagAlias]['occurrence'] - $resultBefore[$tagAlias]['occurrence'], 1);
+
+ // updating the record to not have the cakephp tag anymore, decreases the occurrence
+ $data = array('id' => $this->Article->id, 'title' => 'Test Article', 'tags' => 'php, something, else');
+ $this->Article->save($data, false);
+ $resultAfter = $this->Article->{$tagAlias}->find('first', array(
+ 'contain' => array(),
+ 'conditions' => array(
+ $tagAlias . '.keyname' => 'cakephp'
+ )
+ ));
+ $this->assertEquals($resultAfter[$tagAlias]['occurrence'], 1);
+ }
+
+/**
+ * Testings saving of tags trough the specified field in the tagable model
+ *
+ * @return void
+ */
+ public function testTagSaving() {
+ $data['id'] = 'article-1';
+ $data['tags'] = 'foo, bar, test';
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-1'
+ )
+ ));
+ $this->assertTrue(!empty($result['Article']['tags']));
+
+ $data['tags'] = 'foo, developer, developer, php';
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'contain' => array('Tag'),
+ 'conditions' => array(
+ 'id' => 'article-1'
+ )
+ ));
+
+ $this->assertTrue(!empty($result['Article']['tags']));
+ $this->assertEquals(3, count($result['Tag']));
+
+ $data['tags'] = 'cakephp:foo, developer, cakephp:developer, cakephp:php';
+ $this->Article->save($data, false);
+ $result = $this->Article->Tag->find('all', array(
+ 'recursive' => -1,
+ 'order' => 'Tag.identifier DESC, Tag.name ASC',
+ 'conditions' => array(
+ 'Tag.identifier' => 'cakephp'
+ )
+ ));
+
+ $result = Set::extract($result, '{n}.Tag.keyname');
+ $this->assertEquals($result, array(
+ 'developer', 'foo', 'php'
+ ));
+
+ $this->assertFalse($this->Article->saveTags('foo, bar', null));
+ $this->assertFalse($this->Article->saveTags(array('foo', 'bar'), 'something'));
+ }
+
+/**
+ * Tests that toggling taggedCounter will update the time_tagged counter in the tagged table
+ *
+ * @return void
+ */
+ public function testSaveTimesTagged() {
+ $this->Article->Behaviors->Taggable->settings['Article']['taggedCounter'] = true;
+ $tags = 'foo, bar , test';
+ $this->assertTrue($this->Article->saveTags($tags, 'article-1', false));
+ $this->assertTrue($this->Article->saveTags($tags, 'article-1', false));
+
+ $result = $this->Article->Tagged->find('all', array(
+ 'conditions' => array('model' => 'Article'),
+ 'contain' => array('Tag'),
+ ));
+ $fooCount = Set::extract('/Tag[keyname=foo]/../Tagged/times_tagged', $result);
+ $this->assertEquals($fooCount, array(2));
+
+ $barCount = Set::extract('/Tag[keyname=bar]/../Tagged/times_tagged', $result);
+ $this->assertEquals($barCount, array(2));
+
+ $testCount = Set::extract('/Tag[keyname=test]/../Tagged/times_tagged', $result);
+ $this->assertEquals($testCount, array(2));
+ }
+
+/**
+ * Testing Taggable::tagArrayToString()
+ *
+ * @return void
+ */
+ public function testTagArrayToString() {
+ $data['id'] = 'article-1';
+ $data['tags'] = 'foo, bar, test';
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-1'
+ )
+ ));
+ $result = $this->Article->tagArrayToString($result['Tag']);
+ $this->assertTrue(!empty($result));
+ $this->assertInternalType('string', $result);
+ $this->assertEquals($result, 'test, bar, foo');
+
+ $result = $this->Article->tagArrayToString();
+ $this->assertTrue(empty($result));
+ $this->assertInternalType('string', $result);
+
+ $data['tags'] = 'cakephp:foo, cakephp:bar, foo, bar';
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-1'
+ )
+ ));
+
+ $result = $this->Article->tagArrayToString($result['Tag']);
+ $this->assertTrue(!empty($result));
+ $this->assertInternalType('string', $result);
+ $this->assertEquals($result, 'cakephp:bar, cakephp:foo, bar, foo');
+ }
+
+/**
+ * Testings Taggable::multibyteKey()
+ *
+ * @return void
+ */
+ public function testMultibyteKey() {
+ $result = $this->Article->multibyteKey('this is _ a Nice ! - _ key!');
+ $this->assertEquals('thisisanicekey', $result);
+
+ $result = $this->Article->multibyteKey('Äü-Ü_ß');
+ $this->assertEquals('äüüß', $result);
+ }
+
+/**
+ * testAfterFind callback method
+ *
+ * @return void
+ */
+ public function testAfterFind() {
+ $tagAlias = $this->Article->Behaviors->Taggable->settings['Article']['tagAlias'];
+
+ $data['id'] = 'article-1';
+ $data['tags'] = 'foo, bar, test';
+ $this->Article->save($data, false);
+
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-1'
+ )
+ ));
+ $this->assertTrue(isset($result[$tagAlias]));
+
+ $this->Article->Behaviors->Taggable->settings['Article']['unsetInAfterFind'] = true;
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-1'
+ )
+ ));
+ $this->assertTrue(!isset($result[$tagAlias]));
+ }
+
+/**
+ * testAfterFindFields
+ *
+ * @return void
+ */
+ public function testAfterFindFields() {
+ $this->Article->Behaviors->detach('Taggable');
+ $results = $this->Article->find('first', array(
+ 'recursive' => -1,
+ 'fields' => array('id')
+ ));
+ $expected = array($this->Article->alias => array('id' => 'article-1'));
+ $this->assertIdentical($results, $expected);
+ }
+
+/**
+ * testGettingTagCloudThroughAssociation
+ *
+ * @link http://cakedc.lighthouseapp.com/projects/59622/tickets/6-tag-cloud-helper
+ * @return void
+ */
+ public function testGettingTagCloudThroughAssociation() {
+ $result = $this->Article->Tagged->find('cloud');
+ $this->assertTrue(is_array($result) && !empty($result));
+ }
+
+/**
+ * testSavingEmptyTagsDeleteAssociatedTags
+ *
+ * @return void
+ */
+ public function testSavingEmptyTagsDeleteAssociatedTags() {
+ $this->Article->Behaviors->Taggable->settings['Article']['deleteTagsOnEmptyField'] = true;
+ $data = $this->Article->findById('article-1');
+ $data['Article']['tags'] = '';
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array('id' => 'article-1')
+ ));
+
+ $this->assertEmpty($result['Tag']);
+ }
+
+/**
+ * testSavingEmptyTagsDoNotDeleteAssociatedTags
+ *
+ * @return void
+ */
+ public function testSavingEmptyTagsDoNotDeleteAssociatedTags() {
+ $this->Article->Behaviors->Taggable->settings['Article']['deleteTagsOnEmptyField'] = false;
+ $data = $this->Article->findById('article-1');
+ $data['Article']['tags'] = '';
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array('id' => 'article-1')
+ ));
+
+ $this->assertNotEmpty($result['Tag']);
+ }
+
+/**
+ * testSavingTagsDoesNotCreateEmptyRecords
+ *
+ * @return void
+ */
+ public function testSavingTagsDoesNotCreateEmptyRecords() {
+ $count = $this->Article->Tag->find('count', array(
+ 'conditions' => array(
+ 'Tag.name' => '',
+ 'Tag.keyname' => '',
+ )
+ ));
+ $this->assertEquals($count, 0);
+
+ $data['id'] = 'article-1';
+ $data['tags'] = 'foo, bar, test';
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-1'
+ )
+ ));
+
+ $count = $this->Article->Tag->find('count', array(
+ 'conditions' => array(
+ 'Tag.name' => '',
+ 'Tag.keyname' => '',
+ )
+ ));
+ $this->assertEquals($count, 0);
+ }
+
+/**
+ * testSavingTagsWithDefferentIdentifier
+ *
+ * @return void
+ */
+ public function testSavingTagsWithDifferentIdentifier() {
+ $data = $this->Article->findById('article-1');
+ $data['Article']['tags'] = 'foo:cakephp, bar:cakephp';
+ $this->Article->save($data);
+ $data = $this->Article->findById('article-1');
+ $this->assertEquals('bar:cakephp, foo:cakephp', $data['Article']['tags']);
+ }
+
+/**
+ * testDeletingMoreThanOneTagAtATime
+ *
+ * @link https://github.com/CakeDC/tags/issues/86
+ * @return void
+ */
+ public function testDeletingMoreThanOneTagAtATime() {
+ // Adding five tags for testing
+ $data = array(
+ 'Article' => array(
+ 'id' => 'article-test-delete-tags',
+ 'tags' => 'foo, bar, test, second, third',
+ )
+ );
+ $this->Article->create();
+ $this->Article->save($data, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-test-delete-tags'
+ )
+ ));
+ $this->assertEquals($result['Article']['tags'], 'third, second, test, bar, foo');
+ // Removing three of the five previously added tags
+ $result['Article']['tags'] = 'third, second';
+ $this->Article->save($result, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-test-delete-tags'
+ )
+ ));
+ $this->assertEquals($result['Article']['tags'], 'second, third');
+ // Removing all tags, empty string - WON'T work as expected because of deleteTagsOnEmptyField
+ $result['Article']['tags'] = '';
+ $this->Article->save($result, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-test-delete-tags'
+ )
+ ));
+ $this->assertEquals($result['Article']['tags'], 'third, second');
+ // Now with deleteTagsOnEmptyField
+ $this->Article->Behaviors->load('Tags.Taggable', array(
+ 'deleteTagsOnEmptyField' => true
+ ));
+ $result['Article']['tags'] = '';
+ $this->Article->save($result, false);
+ $result = $this->Article->find('first', array(
+ 'conditions' => array(
+ 'id' => 'article-test-delete-tags'
+ )
+ ));
+ $this->assertEquals($result['Article']['tags'], '');
+ }
+
+}
diff --git a/app/Plugin/Tags/Test/Case/Model/TagTest.php b/app/Plugin/Tags/Test/Case/Model/TagTest.php
old mode 100644
new mode 100755
index a243b50..43ca44f
--- a/app/Plugin/Tags/Test/Case/Model/TagTest.php
+++ b/app/Plugin/Tags/Test/Case/Model/TagTest.php
@@ -1,23 +1,23 @@
Tag = ClassRegistry::init('Tags.Tag');
}
@@ -50,6 +51,7 @@ public function setUp() {
* @return void
*/
public function tearDown() {
+ parent::tearDown();
unset($this->Tag);
}
@@ -74,15 +76,17 @@ public function testTagFind() {
$expected = array(
'Tag' => array(
- 'id' => 'tag-1',
- 'identifier' => null,
- 'name' => 'CakePHP',
- 'keyname' => 'cakephp',
+ 'id' => 'tag-1',
+ 'identifier' => null,
+ 'name' => 'CakePHP',
+ 'keyname' => 'cakephp',
'occurrence' => 1,
'article_occurrence' => 1,
- 'created' => '2008-06-02 18:18:11',
- 'modified' => '2008-06-02 18:18:37'));
- $this->assertEqual($results, $expected);
+ 'created' => '2008-06-02 18:18:11',
+ 'modified' => '2008-06-02 18:18:37'
+ )
+ );
+ $this->assertEquals($results, $expected);
}
/**
@@ -93,9 +97,9 @@ public function testTagFind() {
public function testView() {
$result = $this->Tag->view('cakephp');
$this->assertTrue(is_array($result));
- $this->assertEqual($result['Tag']['keyname'], 'cakephp');
+ $this->assertEquals($result['Tag']['keyname'], 'cakephp');
- $this->expectException('Exception');
+ $this->expectException('CakeException');
$this->Tag->view('invalid-key!!!');
}
@@ -105,18 +109,30 @@ public function testView() {
* @return void
*/
public function testAdd() {
- $result = $this->Tag->add(
- array('Tag' => array(
- 'tags' => 'tag1, tag2, tag3')));
+ $result = $this->Tag->add(array(
+ 'Tag' => array(
+ 'tags' => 'tag1, tag2, tag3'
+ )
+ ));
$this->assertTrue($result);
$result = $this->Tag->find('all', array(
'recursive' => -1,
'fields' => array(
- 'Tag.name')));
+ 'Tag.name'
+ )
+ ));
$result = Set::extract($result, '{n}.Tag.name');
$this->assertTrue(in_array('tag1', $result));
$this->assertTrue(in_array('tag2', $result));
$this->assertTrue(in_array('tag3', $result));
+
+ // adding same tags again.
+ $result = $this->Tag->add(array(
+ 'Tag' => array(
+ 'tags' => 'tag1, tag2, tag3'
+ )
+ ));
+ $this->assertTrue($result);
}
/**
@@ -126,28 +142,34 @@ public function testAdd() {
*/
public function testEdit() {
$this->assertNull($this->Tag->edit('tag-1'));
- $this->assertEqual($this->Tag->data['Tag']['id'], 'tag-1');
-
+ $this->assertEquals($this->Tag->data['Tag']['id'], 'tag-1');
+
$data = array(
'Tag' => array(
'id' => 'tag-1',
- 'name' => 'CAKEPHP'));
+ 'name' => 'CAKEPHP'
+ )
+ );
$this->assertTrue($this->Tag->edit('tag-1', $data));
$data = array(
'Tag' => array(
'id' => 'tag-1',
- 'name' => 'CAKEPHP111'));
+ 'name' => 'CAKEPHP111'
+ )
+ );
$this->assertFalse($this->Tag->edit('tag-1', $data));
$data = array(
'Tag' => array(
'id' => 'tag-1',
'name' => 'CAKEPHP',
- 'keyname' => ''));
- $this->assertEqual($this->Tag->edit('tag-1', $data), $data);
-
- $this->expectException('Exception');
+ 'keyname' => ''
+ )
+ );
+ $this->assertEquals($this->Tag->edit('tag-1', $data), $data);
+
+ $this->expectException('CakeException');
$this->assertTrue($this->Tag->edit('invalid-id', array()));
}
}
diff --git a/app/Plugin/Tags/Test/Case/Model/TaggedTest.php b/app/Plugin/Tags/Test/Case/Model/TaggedTest.php
old mode 100644
new mode 100755
index 097ff2b..b8c35f3
--- a/app/Plugin/Tags/Test/Case/Model/TaggedTest.php
+++ b/app/Plugin/Tags/Test/Case/Model/TaggedTest.php
@@ -1,15 +1,33 @@
Tagged = ClassRegistry::init('Tags.Tagged');
}
@@ -50,9 +71,10 @@ public function startTest($method) {
*
* @return void
*/
- public function endTest($method) {
+ public function tearDown() {
+ parent::tearDown();
unset($this->Tagged);
- ClassRegistry::flush();
+ ClassRegistry::flush();
}
/**
@@ -83,9 +105,11 @@ public function testTaggedFind() {
'language' => 'eng',
'times_tagged' => 1,
'created' => '2008-12-02 12:32:31',
- 'modified' => '2008-12-02 12:32:31'));
+ 'modified' => '2008-12-02 12:32:31'
+ )
+ );
- $this->assertEqual($result, $expected);
+ $this->assertEquals($result, $expected);
}
/**
@@ -95,42 +119,46 @@ public function testTaggedFind() {
*/
public function testFindCloud() {
$result = $this->Tagged->find('cloud', array(
- 'model' => 'Article'));
-
- $this->assertEqual(count($result), 3);
+ 'model' => 'Article'
+ ));
+
+ $this->assertEquals(count($result), 3);
$this->assertTrue(isset($result[0][0]['occurrence']));
- $this->assertEqual($result[0][0]['occurrence'], 1);
+ $this->assertEquals($result[0][0]['occurrence'], 1);
$result = $this->Tagged->find('cloud');
$this->assertTrue(is_array($result) && !empty($result));
$result = $this->Tagged->find('cloud', array(
- 'limit' => 1));
- $this->assertEqual(count($result), 1);
+ 'limit' => 1
+ ));
+ $this->assertEquals(count($result), 1);
}
/**
* Test custom _findTagged method
- *
+ *
* @return void
*/
public function testFindTagged() {
$this->Tagged->recursive = -1;
$result = $this->Tagged->find('tagged', array(
'by' => 'cakephp',
- 'model' => 'Article'));
- $this->assertEqual(count($result), 1);
- $this->assertEqual($result[0]['Article']['id'], 'article-1');
+ 'model' => 'Article'
+ ));
+ $this->assertEquals(count($result), 1);
+ $this->assertEquals($result[0]['Article']['id'], 'article-1');
$result = $this->Tagged->find('tagged', array(
- 'model' => 'Article'));
- $this->assertEqual(count($result), 2);
-
+ 'model' => 'Article'
+ ));
+ $this->assertEquals(count($result), 2);
// Test call to paginateCount by Controller::pagination()
$result = $this->Tagged->paginateCount(array(), 1, array(
'model' => 'Article',
- 'type' => 'tagged'));
- $this->assertEqual($result, 2);
+ 'type' => 'tagged'
+ ));
+ $this->assertEquals($result, 2);
}
/**
@@ -143,15 +171,83 @@ public function testFindTaggedWithConditions() {
$result = $this->Tagged->find('tagged', array(
'by' => 'cakephp',
'model' => 'Article',
- 'conditions' => array('Article.title LIKE' => 'Second %')));
- $this->assertEqual(count($result), 0);
+ 'conditions' => array('Article.title LIKE' => 'Second %')
+ ));
+ $this->assertEquals(count($result), 0);
$result = $this->Tagged->find('tagged', array(
'by' => 'cakephp',
'model' => 'Article',
- 'conditions' => array('Article.title LIKE' => 'First %')));
- $this->assertEqual(count($result), 1);
- $this->assertEqual($result[0]['Article']['id'], 'article-1');
+ 'conditions' => array('Article.title LIKE' => 'First %')
+ ));
+ $this->assertEquals(count($result), 1);
+ $this->assertEquals($result[0]['Article']['id'], 'article-1');
+ }
+
+/**
+ * testDeepAssociations
+ *
+ * @link https://github.com/CakeDC/tags/issues/15
+ * @return void
+ */
+ public function testDeepAssociationsHasOne() {
+ $this->Tagged->bindModel(array(
+ 'belongsTo' => array(
+ 'Article' => array(
+ 'className' => 'TaggedArticle',
+ 'foreignKey' => 'foreign_key'
+ )
+ )
+ ));
+
+ $this->Tagged->Article->bindModel(array(
+ 'hasOne' => array(
+ 'User' => array()
+ )
+ ));
+
+ $result = $this->Tagged->find('all', array(
+ 'contain' => array(
+ 'Article' => array(
+ 'User'
+ )
+ )
+ ));
+
+ $this->assertEquals($result[0]['Article']['User']['name'], 'CakePHP');
+ }
+
+/**
+ * testDeepAssociationsBelongsTo
+ *
+ * @link https://github.com/CakeDC/tags/issues/15
+ * @return void
+ */
+ public function testDeepAssociationsBelongsTo() {
+ $this->Tagged->bindModel(array(
+ 'belongsTo' => array(
+ 'Article' => array(
+ 'className' => 'TaggedArticle',
+ 'foreignKey' => 'foreign_key'
+ )
+ )
+ ));
+
+ $this->Tagged->Article->bindModel(array(
+ 'belongsTo' => array(
+ 'User' => array()
+ )
+ ));
+
+ $result = $this->Tagged->find('all', array(
+ 'contain' => array(
+ 'Article' => array(
+ 'User'
+ )
+ )
+ ));
+
+ $this->assertEquals($result[0]['Article']['User']['name'], 'CakePHP');
}
}
diff --git a/app/Plugin/Tags/Test/Case/View/Helper/TagCloudHelperTest.php b/app/Plugin/Tags/Test/Case/View/Helper/TagCloudHelperTest.php
new file mode 100755
index 0000000..bd8e73d
--- /dev/null
+++ b/app/Plugin/Tags/Test/Case/View/Helper/TagCloudHelperTest.php
@@ -0,0 +1,177 @@
+ array(
+ 'id' => 1,
+ 'identifier' => null,
+ 'name' => 'CakePHP',
+ 'keyname' => 'cakephp',
+ 'weight' => 2,
+ 'created' => '2008-06-02 18:18:11',
+ 'modified' => '2008-06-02 18:18:37'
+ )
+ ),
+ array(
+ 'Tag' => array(
+ 'id' => 2,
+ 'identifier' => null,
+ 'name' => 'CakeDC',
+ 'keyname' => 'cakedc',
+ 'weight' => 2,
+ 'created' => '2008-06-01 18:18:15',
+ 'modified' => '2008-06-01 18:18:15'
+ )
+ ),
+ );
+
+/**
+ * Helper being tested
+ *
+ * @var TagCloudHelper
+ */
+ public $TagCloud;
+
+/**
+ * Setup the test case
+ *
+ * @return void
+ */
+ public function setUp() {
+ parent::setUp();
+ $controller = null;
+ $this->View = new View($controller);
+ $this->TagCloud = new TagCloudHelper($this->View);
+ $this->TagCloud->Html = new HtmlHelper($this->View);
+ }
+
+/**
+ * Test display method
+ *
+ * @return void
+ */
+ public function testDisplay() {
+ $this->assertEquals($this->TagCloud->display(), '');
+
+ // Test tags shuffling
+ $options = array(
+ 'shuffle' => true
+ );
+ $expected = 'CakePHP CakeDC ';
+ $i = 100;
+ do {
+ $i--;
+ $result = $this->TagCloud->display($this->sampleTags, $options);
+ } while ($result == $expected && $i > 0);
+ $this->assertNotEqual($result, $expected);
+
+ // Test normal display
+ $options = array(
+ 'shuffle' => false
+ );
+ $result = $this->TagCloud->display($this->sampleTags, $options);
+ $this->assertEquals($result, $expected);
+
+ // Test options
+ $options = array_merge($options, array(
+ 'before' => '',
+ 'after' => '',
+ 'maxSize' => 100,
+ 'minSize' => 1,
+ 'url' => array('controller' => 'search', 'from' => 'twitter'),
+ 'named' => 'query'
+ ));
+ $result = $this->TagCloud->display($this->sampleTags, $options);
+ $expected = 'CakePHP ' .
+ 'CakeDC ';
+ $this->assertEquals($result, $expected);
+
+ $tags = $this->sampleTags;
+ $tags[1]['Tag']['weight'] = 1;
+ $result = $this->TagCloud->display($tags, $options);
+ $expected = 'CakePHP ' .
+ 'CakeDC ';
+ $this->assertEquals($result, $expected);
+ }
+
+/**
+ * Test that display method defines correct size when using custom weight fields
+ *
+ * @return void
+ */
+ public function testDisplayShouldDefineCorrectSizeWhenCustomWeightField() {
+ $tags = $this->sampleTags;
+ $tags[0]['Tag']['custom_weight'] = 6;
+ $tags[1]['Tag']['custom_weight'] = 3;
+
+ $options = array(
+ 'before' => '',
+ 'shuffle' => false,
+ 'extract' => '{n}.Tag.custom_weight',
+ );
+
+ $result = $this->TagCloud->display($tags, $options);
+ $expected = 'CakePHP ' .
+ 'CakeDC ';
+ $this->assertEquals($result, $expected);
+ }
+
+/**
+ * Test query string param type
+ *
+ * @return void
+ */
+ public function testQueryStringUrlParams() {
+ $tags = $this->sampleTags;
+ $tags[0]['Tag']['custom_weight'] = 6;
+ $tags[1]['Tag']['custom_weight'] = 3;
+
+ $options = array(
+ 'shuffle' => false,
+ 'extract' => '{n}.Tag.custom_weight',
+ 'paramType' => 'querystring'
+ );
+
+ $result = $this->TagCloud->display($tags, $options);
+ $expected = 'CakePHP ' .
+ 'CakeDC ';
+ $this->assertEquals($result, $expected);
+ }
+
+/**
+ * Tear down the test case
+ *
+ * @return void
+ */
+ public function tearDown() {
+ parent::tearDown();
+ unset($this->TagCloud, $this->View);
+ ClassRegistry::flush();
+ }
+}
diff --git a/app/Plugin/Tags/Test/Fixture/ArticleFixture.php b/app/Plugin/Tags/Test/Fixture/ArticleFixture.php
old mode 100644
new mode 100755
index cdf4c71..c7a094d
--- a/app/Plugin/Tags/Test/Fixture/ArticleFixture.php
+++ b/app/Plugin/Tags/Test/Fixture/ArticleFixture.php
@@ -1,11 +1,11 @@
array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36),
- 'title' => array('type' => 'string', 'null' => false));
+ 'id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36),
+ 'title' => array('type' => 'string', 'null' => false),
+ 'user_id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36)
+ );
/**
* records property
@@ -41,11 +36,18 @@ class ArticleFixture extends CakeTestFixture {
public $records = array(
array(
'id' => 'article-1',
- 'title' => 'First Article'),
+ 'title' => 'First Article',
+ 'user_id' => 'user-1'
+ ),
array(
'id' => 'article-2',
- 'title' => 'Second Article'),
+ 'title' => 'Second Article',
+ 'user_id' => 'user-2'
+ ),
array(
'id' => 'article-3',
- 'title' => 'Third Article'));
+ 'title' => 'Third Article',
+ 'user_id' => 'user-3'
+ )
+ );
}
diff --git a/app/Plugin/Tags/Test/Fixture/TagFixture.php b/app/Plugin/Tags/Test/Fixture/TagFixture.php
old mode 100644
new mode 100755
index 9983630..132154f
--- a/app/Plugin/Tags/Test/Fixture/TagFixture.php
+++ b/app/Plugin/Tags/Test/Fixture/TagFixture.php
@@ -1,11 +1,11 @@
array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'),
- 'identifier' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 30, 'key' => 'index'),
- 'name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 30),
- 'keyname' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 30),
+ 'id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36, 'key' => 'primary'),
+ 'identifier' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 30, 'key' => 'index'),
+ 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 30),
+ 'keyname' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 30),
'occurrence' => array('type' => 'integer', 'null' => false, 'default' => 0, 'length' => 8),
'article_occurrence' => array('type' => 'integer', 'null' => false, 'default' => 0, 'length' => 8),
- 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL),
- 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL),
+ 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
+ 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'UNIQUE_TAG' => array('column' => array('identifier', 'keyname'), 'unique' => 1)
@@ -58,31 +51,35 @@ class TagFixture extends CakeTestFixture {
*/
public $records = array(
array(
- 'id' => 'tag-1',
- 'identifier' => null,
- 'name' => 'CakePHP',
- 'keyname' => 'cakephp',
+ 'id' => 'tag-1',
+ 'identifier' => null,
+ 'name' => 'CakePHP',
+ 'keyname' => 'cakephp',
'occurrence' => 1,
'article_occurrence' => 1,
- 'created' => '2008-06-02 18:18:11',
- 'modified' => '2008-06-02 18:18:37'),
+ 'created' => '2008-06-02 18:18:11',
+ 'modified' => '2008-06-02 18:18:37'
+ ),
array(
- 'id' => 'tag-2',
- 'identifier' => null,
- 'name' => 'CakeDC',
- 'keyname' => 'cakedc',
+ 'id' => 'tag-2',
+ 'identifier' => null,
+ 'name' => 'CakeDC',
+ 'keyname' => 'cakedc',
'occurrence' => 1,
'article_occurrence' => 1,
- 'created' => '2008-06-01 18:18:15',
- 'modified' => '2008-06-01 18:18:15'),
+ 'created' => '2008-06-01 18:18:15',
+ 'modified' => '2008-06-01 18:18:15'
+ ),
array(
- 'id' => 'tag-3',
- 'identifier' => null,
- 'name' => 'CakeDC',
- 'keyname' => 'cakedc',
+ 'id' => 'tag-3',
+ 'identifier' => null,
+ 'name' => 'CakeDC',
+ 'keyname' => 'cakedc',
'occurrence' => 1,
'article_occurrence' => 1,
- 'created' => '2008-06-01 18:18:15',
- 'modified' => '2008-06-01 18:18:15'));
+ 'created' => '2008-06-01 18:18:15',
+ 'modified' => '2008-06-01 18:18:15'
+ )
+ );
}
diff --git a/app/Plugin/Tags/Test/Fixture/TaggedFixture.php b/app/Plugin/Tags/Test/Fixture/TaggedFixture.php
old mode 100644
new mode 100755
index eec4090..1c5698d
--- a/app/Plugin/Tags/Test/Fixture/TaggedFixture.php
+++ b/app/Plugin/Tags/Test/Fixture/TaggedFixture.php
@@ -1,11 +1,11 @@
array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'),
- 'foreign_key' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36),
- 'tag_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36),
- 'model' => array('type' => 'string', 'null' => false, 'default' => NULL, 'key' => 'index'),
- 'language' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 6),
+ 'id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36, 'key' => 'primary'),
+ 'foreign_key' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36),
+ 'tag_id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36),
+ 'model' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index'),
+ 'language' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 6),
'times_tagged' => array('type' => 'integer', 'null' => false, 'default' => 1),
- 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL),
- 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL),
+ 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
+ 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'UNIQUE_TAGGING' => array('column' => array('model', 'foreign_key', 'tag_id', 'language'), 'unique' => 1),
diff --git a/app/Plugin/Tags/Test/Fixture/UserFixture.php b/app/Plugin/Tags/Test/Fixture/UserFixture.php
new file mode 100755
index 0000000..f225186
--- /dev/null
+++ b/app/Plugin/Tags/Test/Fixture/UserFixture.php
@@ -0,0 +1,54 @@
+ array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36),
+ 'name' => array('type' => 'string', 'null' => false),
+ 'article_id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36)
+ );
+
+/**
+ * records property
+ *
+ * @var array
+ */
+ public $records = array(
+ array(
+ 'id' => 'user-1',
+ 'name' => 'CakePHP',
+ 'article_id' => 'article-1'
+ ),
+ array(
+ 'id' => 'user-2',
+ 'name' => 'Second User',
+ 'article_id' => 'article-2'
+ ),
+ array(
+ 'id' => 'user-3',
+ 'name' => 'Third User',
+ 'article_id' => 'article-3'
+ )
+ );
+
+}
diff --git a/app/Plugin/Tags/View/Helper/TagCloudHelper.php b/app/Plugin/Tags/View/Helper/TagCloudHelper.php
old mode 100644
new mode 100755
index 1c15cf7..c5caf04
--- a/app/Plugin/Tags/View/Helper/TagCloudHelper.php
+++ b/app/Plugin/Tags/View/Helper/TagCloudHelper.php
@@ -1,14 +1,16 @@
array(
'controller' => 'search'
),
- 'named' => 'by'
+ 'named' => 'by',
+ 'paramType' => 'named'
);
$options = array_merge($defaults, $options);
@@ -74,21 +78,42 @@ public function display($tags = null, $options = array()) {
$cloud = null;
foreach ($tags as $tag) {
- $options['url'][$options['named']] = $tag[$options['tagModel']]['keyname'];
+ $data = Set::extract(array($tag), $options['extract']);
+ $tagWeight = array_pop($data);
- $size = $options['minSize'] + (($tag[$options['tagModel']]['weight'] - $minWeight) * (($options['maxSize'] - $options['minSize']) / ($spread)));
- $size = ceil($size);
+ $size = $options['minSize'] + (($tagWeight - $minWeight) * (($options['maxSize'] - $options['minSize']) / ($spread)));
+ $size = $tag[$options['tagModel']]['size'] = ceil($size);
$cloud .= $this->_replace($options['before'], $size);
- $cloud .= $this->Html->link($tag[$options['tagModel']]['name'], $options['url'], array('id' => 'tag-' . $tag[$options['tagModel']]['id'])) . ' ';
+ $cloud .= $this->Html->link($tag[$options['tagModel']]['name'], $this->_tagUrl($tag, $options), array('id' => 'tag-' . $tag[$options['tagModel']]['id'])) . ' ';
$cloud .= $this->_replace($options['after'], $size);
}
+
return $cloud;
}
+/**
+ * Generates the URL for a tag
+ *
+ * @param array $tag Tag data array
+ * @param array $options Display options
+ * @return array|string
+ */
+ protected function _tagUrl($tag, $options) {
+ if ($options['paramType'] === 'named') {
+ $options['url'][$options['named']] = $tag[$options['tagModel']]['keyname'];
+ } else {
+ $options['url']['?'][$options['named']] = $tag[$options['tagModel']]['keyname'];
+ }
+
+ return $options['url'];
+ }
+
/**
* Replaces %size% in strings with the calculated "size" of the tag
*
+ * @param string $string Before or after string
+ * @param float $size Calculated size
* @return string
*/
protected function _replace($string, $size) {
diff --git a/app/Plugin/Tags/View/Helper/tag_cloud.php b/app/Plugin/Tags/View/Helper/tag_cloud.php
deleted file mode 100644
index e69de29..0000000
diff --git a/app/Plugin/Tags/View/Tags/admin_add.ctp b/app/Plugin/Tags/View/Tags/admin_add.ctp
old mode 100644
new mode 100755
index 818b444..185d1b4
--- a/app/Plugin/Tags/View/Tags/admin_add.ctp
+++ b/app/Plugin/Tags/View/Tags/admin_add.ctp
@@ -1,11 +1,11 @@
diff --git a/app/Plugin/Tags/View/Tags/admin_edit.ctp b/app/Plugin/Tags/View/Tags/admin_edit.ctp
old mode 100644
new mode 100755
index e25da83..4d549c1
--- a/app/Plugin/Tags/View/Tags/admin_edit.ctp
+++ b/app/Plugin/Tags/View/Tags/admin_edit.ctp
@@ -1,11 +1,11 @@
diff --git a/app/Plugin/Tags/View/Tags/admin_index.ctp b/app/Plugin/Tags/View/Tags/admin_index.ctp
old mode 100644
new mode 100755
index 9187d4a..7c07e8b
--- a/app/Plugin/Tags/View/Tags/admin_index.ctp
+++ b/app/Plugin/Tags/View/Tags/admin_index.ctp
@@ -1,11 +1,11 @@
@@ -23,7 +23,6 @@ echo $this->Paginator->counter(array(