Skip to content
Permalink
Browse files

Adds some more tests to tag repository

  • Loading branch information...
jacobemerick committed Feb 25, 2016
1 parent b5f9bde commit 5f2e885da5dc2087aad68af057b62547e96c5027
Showing with 108 additions and 9 deletions.
  1. +1 −1 src/Domain/Blog/Tag/MysqlTagRepository.php
  2. +107 −8 tests/unit/Domain/Blog/Tag/MysqlTagRepositoryTest.php
@@ -77,7 +77,7 @@ public function getTagsForPost($post)
$query = "
SELECT `tag`.*
FROM `jpemeric_blog`.`tag`
INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`tag_id` AND `post_id` = :post
INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`tag_id` AND `ptlink`.`post_id` = :post
ORDER BY `tag`";
$bindings = [
'post' => $post,
@@ -29,8 +29,8 @@ public static function setUpBeforeClass()
);
$extendedPdo->exec("
CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`ptlink` (
`post` integer NOT NULL,
`tag` integer NOT NULL
`post_id` integer NOT NULL,
`tag_id` integer NOT NULL
)"
);
$extendedPdo->exec("
@@ -91,6 +91,8 @@ public function testFindTagByTitle()
array_walk($testData, [$this, 'insertTagData']);
shuffle($testData);
$repository = new MysqlTagRepository(self::$connection);
$data = $repository->findTagByTitle(reset($testData)['tag']);
@@ -110,11 +112,88 @@ public function testFindTagByTitleFailure()
$this->assertFalse($data);
}
public function testGetAllTags() {}
public function testGetAllTags()
{
$testData = [
[
'id' => rand(1, 100),
'tag' => 'test one',
],
[
'id' => rand(101, 200),
'tag' => 'test two',
],
];
array_walk($testData, [$this, 'insertTagData']);
$repository = new MysqlTagRepository(self::$connection);
$data = $repository->getAllTags();
$this->assertNotFalse($data);
$this->assertInternalType('array', $data);
$this->assertCount(count($testData), $data);
foreach ($testData as $key => $testDataRow) {
$this->assertArrayHasKey('id', $data[$key]);
$this->assertEquals($testDataRow['id'], $data[$key]['id']);
$this->assertArrayHasKey('tag', $data[$key]);
$this->assertEquals($testDataRow['tag'], $data[$key]['tag']);
}
}
public function testGetAllTagsFailure()
{
$repository = new MysqlTagRepository(self::$connection);
$data = $repository->getAllTags();
$this->assertEmpty($data);
$this->assertInternalType('array', $data);
}
public function testGetTagCloud()
{
$testPostData = [
[
'id' => rand(1, 100),
],
[
'id' => rand(101, 200),
],
];
public function testGetAllTagsFailure() {}
$testTagData = [
[
'id' => rand(1, 100),
'tag' => 'test one',
],
[
'id' => rand(101, 200),
'tag' => 'test two',
],
[
'id' => rand(201, 300),
'tag' => 'test three',
],
];
public function testGetTagCloud() {}
$testPTLinkData = [];
foreach ($testPostData as $testPostRow) {
$tempTagData = $testTagData;
shuffle($tempTagData);
for ($i = 0; $i < 2; $i++) {
array_push($testPTLinkData, [
'post_id' => $testPostRow['id'],
'tag_id' => $tempTagData[$i]['id'],
]);
}
}
array_walk($testPostData, [$this, 'insertPostData']);
array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
array_walk($testTagData, [$this, 'insertTagData']);
// todo assert stuff, I guess
}
public function testGetTagCloudInactive() {}
@@ -124,7 +203,27 @@ public function testGetTagsForPost() {}
public function testGetTagsForPostOrder() {}
public function testGetTagsForPostFailure() {}
public function testGetTagsForPostFailure()
{
$testData = [
[
'id' => rand(1, 100),
'tag' => 'test one',
],
[
'id' => rand(101, 200),
'tag' => 'test two',
],
];
array_walk($testData, [$this, 'insertTagData']);
$repository = new MysqlTagRepository(self::$connection);
$data = $repository->getTagsForPost(rand(1, 10));
$this->assertEmpty($data);
$this->assertInternalType('array', $data);
}
protected function insertPostData(array $data)
{
@@ -160,9 +259,9 @@ protected function insertPTLinkData(array $data)
return self::$connection->getDefault()->perform("
INSERT INTO `jpemeric_blog`.`ptlink`
(post, tag)
(post_id, tag_id)
VALUES
(:post, :tag)",
(:post_id, :tag_id)",
$data
);
}

0 comments on commit 5f2e885

Please sign in to comment.
You can’t perform that action at this time.