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

Commit

Permalink
Fixing #51, tags with an identifier (cakephp:developer) are not displ…
Browse files Browse the repository at this point in the history
…ayed with the identifier when returned from the DB later
  • Loading branch information
Florian Krämer committed Apr 3, 2014
1 parent 9c4c9ed commit a8421c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Model/Behavior/TaggableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,15 @@ public function multibyteKey(Model $model, $string = 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 '';
}
Expand Down
14 changes: 13 additions & 1 deletion Test/Case/Model/Behavior/TaggableBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function testSaveTimesTagged() {
}

/**
* Testings Taggable::tagArrayToString()
* Testing Taggable::tagArrayToString()
*
* @return void
*/
Expand All @@ -230,10 +230,22 @@ public function testTagArrayToString() {
$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';
$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');
}

/**
Expand Down

0 comments on commit a8421c7

Please sign in to comment.