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 f0b4a9c commit d05a730
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
19 changes: 17 additions & 2 deletions Test/Case/Model/Behavior/TagBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,33 @@ public function testAfterSave() {
}

/**
* ε(     v ゚ω゚) < タグ条件ありのFind
* タグ条件ありのFind
*
* @return void
*/
public function testFindWithTag() {
$FakeModel = ClassRegistry::init('FakeModel');
$this->_unloadTrackable($FakeModel);

$conditions = array('Tag.id' => 1);
$result = $FakeModel->find('all', array('conditions' => $conditions));
$this->assertInternalType('array', $result);

$conditions = array('TagsContent.tag_id' => 1);
$result = $FakeModel->find('all', array('conditions' => $conditions));
$this->assertInternalType('array', $result);
}

/**
* ε(     v ゚ω゚) < 検索結果にタグがくっついてるか
* 検索結果にタグがくっついてるか
*
* @return void
*/
public function testAfterFind() {
$FakeModel = ClassRegistry::init('FakeModel');
$this->_unloadTrackable($FakeModel);

$fake = $FakeModel->findById(1);
$this->assertEquals(count($fake['Tag']), 1);
}
}
4 changes: 2 additions & 2 deletions Test/Case/Model/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ public function testCleanup() {
// まだ元コンテンツがあるのでcleanUpしてもタグは残る
$this->Tag->cleanUp($FakeModel, $blockId);
$tags = $this->Tag->getTagsByContentId('FakeModel', $contentId);
$this->assertEqual(count($tags), 3);
$this->assertEquals(count($tags), 4);
$FakeModel->delete($contentId);

// 元コンテンツが削除されたので関連するコンテンツのなくなったタグは削除される
$this->Tag->cleanUp($FakeModel, $blockId);
$tags = $this->Tag->getTagsByContentId('FakeModel', $contentId);
$this->assertEqual(count($tags), 0);
$this->assertEquals(count($tags), 0);
}

}
12 changes: 12 additions & 0 deletions Test/Fixture/TagFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ class TagFixture extends CakeTestFixture {
'modified_user' => 1,
'modified' => '2015-05-05 01:32:05'
),
array(
'id' => 4,
'block_id' => 1,
'model' => 'FakeModel',
'origin_id' => 1,
'language_id' => 1,
'name' => 'タグ4',
'created_user' => 1,
'created' => '2015-05-05 01:32:05',
'modified_user' => 1,
'modified' => '2015-05-05 01:32:05'
),
);

}
10 changes: 10 additions & 0 deletions Test/Fixture/TagsContentFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ class TagsContentFixture extends CakeTestFixture {
'modified_user' => 1,
'modified' => '2015-05-12 06:32:38'
),
array(
'id' => 2,
'model' => 'FakeModel',
'content_id' => 1,
'tag_id' => 4,
'created_user' => 1,
'created' => '2015-05-12 06:32:38',
'modified_user' => 1,
'modified' => '2015-05-12 06:32:38'
),
);

}

0 comments on commit d05a730

Please sign in to comment.