Skip to content

Commit

Permalink
Tagビヘイビアテスト
Browse files Browse the repository at this point in the history
  • Loading branch information
RyujiAMANO committed Jun 11, 2015
1 parent b333de3 commit f0b4a9c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Model/Behavior/TagBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function setup(Model $Model, $settings = array()) {
* @param Model $Model モデル
* @param bool $created 新規作成
* @param array $options options
* @throws InternalErrorException
* @return void
*/
public function afterSave(Model $Model, $created, $options = array()) {
Expand All @@ -59,7 +60,7 @@ public function afterSave(Model $Model, $created, $options = array()) {
if (isset($Model->data['Tag'])) {
$Tag = $this->_getTagModel();
if (!$Tag->saveTags($blockId, $Model->name, $Model->id, $Model->data['Tag'])) {
return false;
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
}
// cleanup
Expand Down
58 changes: 58 additions & 0 deletions Test/Case/Model/Behavior/TagBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,62 @@ public function testDelete() {
$count = $FakeModel->find('count');
$this->assertEqual($count, 0);
}

/**
* タグ取得
*
* @return void
*/
public function testGetTagByTagId() {
$FakeModel = ClassRegistry::init('FakeModel');
$this->_unloadTrackable($FakeModel);

$tag = $FakeModel->getTagByTagId(1);
$this->assertEqual($tag['Tag']['name'], 'タグ1');
}

/**
* test After save
*
* @return void
*/
public function testAfterSave() {
$FakeModel = ClassRegistry::init('FakeModel');
$this->_unloadTrackable($FakeModel);

$FakeModel->create();
$data['FakeModel']['block_id'] = 1;
$data['Tag'] = array(
'name' => 'tag1',
'name' => 'tag2',
);
$result = $FakeModel->save($data);
$this->assertInternalType('array', $result);

//Tag save fail
$mock = $this->getMockForModel('Tags.Tag', ['saveTags']);
$mock->expects($this->once())
->method('saveTags')
->will($this->returnValue(false));

$FakeModel->create();
$this->setExpectedException('InternalErrorException');
$FakeModel->save($data);
}

/**
* ε(     v ゚ω゚) < タグ条件ありのFind
*
* @return void
*/
public function testFindWithTag() {
}

/**
* ε(     v ゚ω゚) < 検索結果にタグがくっついてるか
*
* @return void
*/
public function testAfterFind() {
}
}

0 comments on commit f0b4a9c

Please sign in to comment.