|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Aternos\CurseForgeApi\Tests\Unit\Client\Options; |
| 4 | + |
| 5 | +use Aternos\CurseForgeApi\Client\Options\ModSearchOptions; |
| 6 | +use Aternos\CurseForgeApi\Model\ModLoaderType; |
| 7 | +use Aternos\CurseForgeApi\Model\ModsSearchSortField; |
| 8 | +use Aternos\CurseForgeApi\Model\PremiumType; |
| 9 | +use Aternos\CurseForgeApi\Model\SortOrder; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class ModSearchOptionsTest extends TestCase |
| 13 | +{ |
| 14 | + public function testConstruct(): void |
| 15 | + { |
| 16 | + $modSearchOptions = new ModSearchOptions(1); |
| 17 | + $this->assertSame(1, $modSearchOptions->getGameId()); |
| 18 | + $this->assertSame(0, $modSearchOptions->getOffset()); |
| 19 | + $this->assertSame(50, $modSearchOptions->getPageSize()); |
| 20 | + $this->assertNull($modSearchOptions->getClassId()); |
| 21 | + $this->assertNull($modSearchOptions->getCategoryIds()); |
| 22 | + $this->assertNull($modSearchOptions->getGameVersions()); |
| 23 | + $this->assertNull($modSearchOptions->getSearchFilter()); |
| 24 | + $this->assertNull($modSearchOptions->getSortField()); |
| 25 | + $this->assertNull($modSearchOptions->getSortOrder()); |
| 26 | + $this->assertNull($modSearchOptions->getModLoaderTypes()); |
| 27 | + $this->assertNull($modSearchOptions->getGameVersionTypeId()); |
| 28 | + $this->assertNull($modSearchOptions->getAuthorId()); |
| 29 | + $this->assertNull($modSearchOptions->getPrimaryAuthorId()); |
| 30 | + $this->assertNull($modSearchOptions->getPremiumType()); |
| 31 | + $this->assertNull($modSearchOptions->getSlug()); |
| 32 | + } |
| 33 | + |
| 34 | + public function testSetGameId(): void |
| 35 | + { |
| 36 | + $modSearchOptions = new ModSearchOptions(1); |
| 37 | + $this->assertSame(1, $modSearchOptions->getGameId()); |
| 38 | + $modSearchOptions->setGameId(2); |
| 39 | + $this->assertSame(2, $modSearchOptions->getGameId()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testSetOffset(): void |
| 43 | + { |
| 44 | + $modSearchOptions = new ModSearchOptions(1, 10); |
| 45 | + $this->assertSame(10, $modSearchOptions->getOffset()); |
| 46 | + $modSearchOptions->setOffset(20); |
| 47 | + $this->assertSame(20, $modSearchOptions->getOffset()); |
| 48 | + } |
| 49 | + |
| 50 | + public function testSetPageSize(): void |
| 51 | + { |
| 52 | + $modSearchOptions = new ModSearchOptions(1, 0, 20); |
| 53 | + $this->assertSame(20, $modSearchOptions->getPageSize()); |
| 54 | + $modSearchOptions->setPageSize(30); |
| 55 | + $this->assertSame(30, $modSearchOptions->getPageSize()); |
| 56 | + } |
| 57 | + |
| 58 | + public function testSetClassId(): void |
| 59 | + { |
| 60 | + $modSearchOptions = new ModSearchOptions(1); |
| 61 | + $this->assertNull($modSearchOptions->getClassId()); |
| 62 | + $modSearchOptions->setClassId(2); |
| 63 | + $this->assertSame(2, $modSearchOptions->getClassId()); |
| 64 | + $modSearchOptions->setClassId(null); |
| 65 | + $this->assertNull($modSearchOptions->getClassId()); |
| 66 | + } |
| 67 | + |
| 68 | + public function testSetCategoryIds(): void |
| 69 | + { |
| 70 | + $modSearchOptions = new ModSearchOptions(1); |
| 71 | + $this->assertNull($modSearchOptions->getCategoryIds()); |
| 72 | + $modSearchOptions->setCategoryIds([2, 3]); |
| 73 | + $this->assertSame([2, 3], $modSearchOptions->getCategoryIds()); |
| 74 | + $modSearchOptions->setCategoryIds(null); |
| 75 | + $this->assertNull($modSearchOptions->getCategoryIds()); |
| 76 | + } |
| 77 | + |
| 78 | + public function testAddCategoryId(): void |
| 79 | + { |
| 80 | + $modSearchOptions = new ModSearchOptions(1); |
| 81 | + $this->assertNull($modSearchOptions->getCategoryIds()); |
| 82 | + $modSearchOptions->addCategoryId(2); |
| 83 | + $this->assertSame([2], $modSearchOptions->getCategoryIds()); |
| 84 | + $modSearchOptions->addCategoryId(3); |
| 85 | + $this->assertSame([2, 3], $modSearchOptions->getCategoryIds()); |
| 86 | + } |
| 87 | + |
| 88 | + public function testRemoveCategoryId(): void |
| 89 | + { |
| 90 | + $modSearchOptions = new ModSearchOptions(1, categoryIds: [1, 2]); |
| 91 | + $this->assertSame([1, 2], $modSearchOptions->getCategoryIds()); |
| 92 | + $modSearchOptions->removeCategoryId(1); |
| 93 | + $this->assertSame([2], $modSearchOptions->getCategoryIds()); |
| 94 | + $modSearchOptions->removeCategoryId(2); |
| 95 | + $this->assertSame([], $modSearchOptions->getCategoryIds()); |
| 96 | + } |
| 97 | + |
| 98 | + public function testGetEncodedCategoryIds(): void |
| 99 | + { |
| 100 | + $modSearchOptions = new ModSearchOptions(1); |
| 101 | + $this->assertNull($modSearchOptions->getEncodedCategoryIds()); |
| 102 | + $modSearchOptions->setCategoryIds([2, 3]); |
| 103 | + $this->assertSame("[2,3]", $modSearchOptions->getEncodedCategoryIds()); |
| 104 | + } |
| 105 | + |
| 106 | + public function testSetGameVersions(): void |
| 107 | + { |
| 108 | + $modSearchOptions = new ModSearchOptions(1); |
| 109 | + $this->assertNull($modSearchOptions->getGameVersions()); |
| 110 | + $modSearchOptions->setGameVersions(["1.16.4", "1.16.5"]); |
| 111 | + $this->assertSame(["1.16.4", "1.16.5"], $modSearchOptions->getGameVersions()); |
| 112 | + $modSearchOptions->setGameVersions(null); |
| 113 | + $this->assertNull($modSearchOptions->getGameVersions()); |
| 114 | + } |
| 115 | + |
| 116 | + public function testAddGameVersion(): void |
| 117 | + { |
| 118 | + $modSearchOptions = new ModSearchOptions(1); |
| 119 | + $this->assertNull($modSearchOptions->getGameVersions()); |
| 120 | + $modSearchOptions->addGameVersion("1.16.4"); |
| 121 | + $this->assertSame(["1.16.4"], $modSearchOptions->getGameVersions()); |
| 122 | + $modSearchOptions->addGameVersion("1.16.5"); |
| 123 | + $this->assertSame(["1.16.4", "1.16.5"], $modSearchOptions->getGameVersions()); |
| 124 | + } |
| 125 | + |
| 126 | + public function testRemoveGameVersion(): void |
| 127 | + { |
| 128 | + $modSearchOptions = new ModSearchOptions(1, gameVersions: ["1.16.4", "1.16.5"]); |
| 129 | + $this->assertSame(["1.16.4", "1.16.5"], $modSearchOptions->getGameVersions()); |
| 130 | + $modSearchOptions->removeGameVersion("1.16.4"); |
| 131 | + $this->assertSame(["1.16.5"], $modSearchOptions->getGameVersions()); |
| 132 | + $modSearchOptions->removeGameVersion("1.16.5"); |
| 133 | + $this->assertSame([], $modSearchOptions->getGameVersions()); |
| 134 | + } |
| 135 | + |
| 136 | + public function testGetEncodedGameVersions(): void |
| 137 | + { |
| 138 | + $modSearchOptions = new ModSearchOptions(1); |
| 139 | + $this->assertNull($modSearchOptions->getEncodedGameVersions()); |
| 140 | + $modSearchOptions->setGameVersions(["1.16.4", "1.16.5"]); |
| 141 | + $this->assertSame("[\"1.16.4\",\"1.16.5\"]", $modSearchOptions->getEncodedGameVersions()); |
| 142 | + } |
| 143 | + |
| 144 | + public function testSetSearchFilter(): void |
| 145 | + { |
| 146 | + $modSearchOptions = new ModSearchOptions(1); |
| 147 | + $this->assertNull($modSearchOptions->getSearchFilter()); |
| 148 | + $modSearchOptions->setSearchFilter("test"); |
| 149 | + $this->assertSame("test", $modSearchOptions->getSearchFilter()); |
| 150 | + $modSearchOptions->setSearchFilter(null); |
| 151 | + $this->assertNull($modSearchOptions->getSearchFilter()); |
| 152 | + } |
| 153 | + |
| 154 | + public function testSetSortField(): void |
| 155 | + { |
| 156 | + $modSearchOptions = new ModSearchOptions(1); |
| 157 | + $this->assertNull($modSearchOptions->getSortField()); |
| 158 | + $modSearchOptions->setSortField(ModsSearchSortField::NAME); |
| 159 | + $this->assertSame(ModsSearchSortField::NAME, $modSearchOptions->getSortField()); |
| 160 | + $modSearchOptions->setSortField(null); |
| 161 | + $this->assertNull($modSearchOptions->getSortField()); |
| 162 | + } |
| 163 | + |
| 164 | + public function testSetSortOrder(): void |
| 165 | + { |
| 166 | + $modSearchOptions = new ModSearchOptions(1); |
| 167 | + $this->assertNull($modSearchOptions->getSortOrder()); |
| 168 | + $modSearchOptions->setSortOrder(SortOrder::ASCENDING); |
| 169 | + $this->assertSame(SortOrder::ASCENDING, $modSearchOptions->getSortOrder()); |
| 170 | + $modSearchOptions->setSortOrder(null); |
| 171 | + $this->assertNull($modSearchOptions->getSortOrder()); |
| 172 | + } |
| 173 | + |
| 174 | + public function testSetModLoaderTypes(): void |
| 175 | + { |
| 176 | + $modSearchOptions = new ModSearchOptions(1); |
| 177 | + $this->assertNull($modSearchOptions->getModLoaderTypes()); |
| 178 | + $modSearchOptions->setModLoaderTypes([ModLoaderType::FORGE, ModLoaderType::FABRIC]); |
| 179 | + $this->assertSame([ModLoaderType::FORGE, ModLoaderType::FABRIC], $modSearchOptions->getModLoaderTypes()); |
| 180 | + $modSearchOptions->setModLoaderTypes(null); |
| 181 | + $this->assertNull($modSearchOptions->getModLoaderTypes()); |
| 182 | + } |
| 183 | + |
| 184 | + public function testAddModLoaderType(): void |
| 185 | + { |
| 186 | + $modSearchOptions = new ModSearchOptions(1); |
| 187 | + $this->assertNull($modSearchOptions->getModLoaderTypes()); |
| 188 | + $modSearchOptions->addModLoaderType(ModLoaderType::FORGE); |
| 189 | + $this->assertSame([ModLoaderType::FORGE], $modSearchOptions->getModLoaderTypes()); |
| 190 | + $modSearchOptions->addModLoaderType(ModLoaderType::FABRIC); |
| 191 | + $this->assertSame([ModLoaderType::FORGE, ModLoaderType::FABRIC], $modSearchOptions->getModLoaderTypes()); |
| 192 | + } |
| 193 | + |
| 194 | + public function testRemoveModLoaderType(): void |
| 195 | + { |
| 196 | + $modSearchOptions = new ModSearchOptions(1, modLoaderTypes: [ModLoaderType::FORGE, ModLoaderType::FABRIC]); |
| 197 | + $this->assertSame([ModLoaderType::FORGE, ModLoaderType::FABRIC], $modSearchOptions->getModLoaderTypes()); |
| 198 | + $modSearchOptions->removeModLoaderType(ModLoaderType::FORGE); |
| 199 | + $this->assertSame([ModLoaderType::FABRIC], $modSearchOptions->getModLoaderTypes()); |
| 200 | + $modSearchOptions->removeModLoaderType(ModLoaderType::FABRIC); |
| 201 | + $this->assertSame([], $modSearchOptions->getModLoaderTypes()); |
| 202 | + } |
| 203 | + |
| 204 | + public function testGetEncodedModLoaderTypes(): void |
| 205 | + { |
| 206 | + $modSearchOptions = new ModSearchOptions(1); |
| 207 | + $this->assertNull($modSearchOptions->getEncodedModLoaderTypes()); |
| 208 | + $modSearchOptions->setModLoaderTypes([ModLoaderType::FORGE, ModLoaderType::FABRIC]); |
| 209 | + $this->assertSame("[1,4]", $modSearchOptions->getEncodedModLoaderTypes()); |
| 210 | + } |
| 211 | + |
| 212 | + public function testSetGameVersionTypeId(): void |
| 213 | + { |
| 214 | + $modSearchOptions = new ModSearchOptions(1); |
| 215 | + $this->assertNull($modSearchOptions->getGameVersionTypeId()); |
| 216 | + $modSearchOptions->setGameVersionTypeId(2); |
| 217 | + $this->assertSame(2, $modSearchOptions->getGameVersionTypeId()); |
| 218 | + $modSearchOptions->setGameVersionTypeId(null); |
| 219 | + $this->assertNull($modSearchOptions->getGameVersionTypeId()); |
| 220 | + } |
| 221 | + |
| 222 | + public function testSetAuthorId(): void |
| 223 | + { |
| 224 | + $modSearchOptions = new ModSearchOptions(1); |
| 225 | + $this->assertNull($modSearchOptions->getAuthorId()); |
| 226 | + $modSearchOptions->setAuthorId(2); |
| 227 | + $this->assertSame(2, $modSearchOptions->getAuthorId()); |
| 228 | + $modSearchOptions->setAuthorId(null); |
| 229 | + $this->assertNull($modSearchOptions->getAuthorId()); |
| 230 | + } |
| 231 | + |
| 232 | + public function testSetPrimaryAuthorId(): void |
| 233 | + { |
| 234 | + $modSearchOptions = new ModSearchOptions(1); |
| 235 | + $this->assertNull($modSearchOptions->getPrimaryAuthorId()); |
| 236 | + $modSearchOptions->setPrimaryAuthorId(2); |
| 237 | + $this->assertSame(2, $modSearchOptions->getPrimaryAuthorId()); |
| 238 | + $modSearchOptions->setPrimaryAuthorId(null); |
| 239 | + $this->assertNull($modSearchOptions->getPrimaryAuthorId()); |
| 240 | + } |
| 241 | + |
| 242 | + public function testSetPremiumType(): void |
| 243 | + { |
| 244 | + $modSearchOptions = new ModSearchOptions(1); |
| 245 | + $this->assertNull($modSearchOptions->getPremiumType()); |
| 246 | + $modSearchOptions->setPremiumType(PremiumType::FREE); |
| 247 | + $this->assertSame(PremiumType::FREE, $modSearchOptions->getPremiumType()); |
| 248 | + $modSearchOptions->setPremiumType(null); |
| 249 | + $this->assertNull($modSearchOptions->getPremiumType()); |
| 250 | + } |
| 251 | + |
| 252 | + public function testSetSlug(): void |
| 253 | + { |
| 254 | + $modSearchOptions = new ModSearchOptions(1); |
| 255 | + $this->assertNull($modSearchOptions->getSlug()); |
| 256 | + $modSearchOptions->setSlug("test-slug"); |
| 257 | + $this->assertSame("test-slug", $modSearchOptions->getSlug()); |
| 258 | + } |
| 259 | +} |
0 commit comments