| @@ 744-785 (lines=42) @@ | ||
| 741 | } |
|
| 742 | } |
|
| 743 | ||
| 744 | public function testGetActivePostsByCategoryInactive() |
|
| 745 | { |
|
| 746 | $testData = [ |
|
| 747 | [ |
|
| 748 | 'id' => rand(1, 100), |
|
| 749 | 'category' => 'test category', |
|
| 750 | 'display' => 1, |
|
| 751 | ], |
|
| 752 | [ |
|
| 753 | 'id' => rand(101, 200), |
|
| 754 | 'category' => 'test category', |
|
| 755 | 'display' => 1, |
|
| 756 | ], |
|
| 757 | [ |
|
| 758 | 'id' => rand(201, 300), |
|
| 759 | 'category' => 'test category', |
|
| 760 | 'display' => 0, |
|
| 761 | ], |
|
| 762 | ]; |
|
| 763 | ||
| 764 | array_walk($testData, [$this, 'insertPostData']); |
|
| 765 | ||
| 766 | $repository = new MysqlPostRepository(self::$connection); |
|
| 767 | $data = $repository->getActivePostsByCategory(reset($testData)['category']); |
|
| 768 | ||
| 769 | $this->assertNotFalse($data); |
|
| 770 | $this->assertInternalType('array', $data); |
|
| 771 | ||
| 772 | $testData = array_filter($testData, function ($row) { |
|
| 773 | return ($row['display'] == 1); |
|
| 774 | }); |
|
| 775 | ||
| 776 | $this->assertCount(count($testData), $data); |
|
| 777 | ||
| 778 | $testIds = array_column($testData, 'ids'); |
|
| 779 | $dataIds = array_column($data, 'ids'); |
|
| 780 | ||
| 781 | $this->assertEmpty(array_merge( |
|
| 782 | array_diff($testIds, $dataIds), |
|
| 783 | array_diff($dataIds, $testIds) |
|
| 784 | )); |
|
| 785 | } |
|
| 786 | ||
| 787 | public function testGetActivePostsByCategoryFailure() |
|
| 788 | { |
|
| @@ 796-835 (lines=40) @@ | ||
| 793 | $this->assertInternalType('array', $data); |
|
| 794 | } |
|
| 795 | ||
| 796 | public function testGetActivePostsByCategoryRange() |
|
| 797 | { |
|
| 798 | $testData = [ |
|
| 799 | [ |
|
| 800 | 'id' => rand(1, 100), |
|
| 801 | 'category' => 'test category', |
|
| 802 | 'display' => 1, |
|
| 803 | ], |
|
| 804 | [ |
|
| 805 | 'id' => rand(101, 200), |
|
| 806 | 'category' => 'test category', |
|
| 807 | 'display' => 1, |
|
| 808 | ], |
|
| 809 | [ |
|
| 810 | 'id' => rand(201, 300), |
|
| 811 | 'category' => 'test category', |
|
| 812 | 'display' => 1, |
|
| 813 | ], |
|
| 814 | ]; |
|
| 815 | ||
| 816 | array_walk($testData, [$this, 'insertPostData']); |
|
| 817 | ||
| 818 | $repository = new MysqlPostRepository(self::$connection); |
|
| 819 | $data = $repository->getActivePostsByCategory(reset($testData)['category'], 2, 1); |
|
| 820 | ||
| 821 | $this->assertNotFalse($data); |
|
| 822 | $this->assertInternalType('array', $data); |
|
| 823 | ||
| 824 | $testData = array_slice($testData, 1, 2); |
|
| 825 | ||
| 826 | $this->assertCount(count($testData), $data); |
|
| 827 | ||
| 828 | $testIds = array_column($testData, 'ids'); |
|
| 829 | $dataIds = array_column($data, 'ids'); |
|
| 830 | ||
| 831 | $this->assertEmpty(array_merge( |
|
| 832 | array_diff($testIds, $dataIds), |
|
| 833 | array_diff($dataIds, $testIds) |
|
| 834 | )); |
|
| 835 | } |
|
| 836 | ||
| 837 | public function testGetActivePostsByCategoryRangeFailure() |
|
| 838 | { |
|