|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * OpenMage |
| 5 | + * |
| 6 | + * This source file is subject to the Open Software License (OSL 3.0) |
| 7 | + * that is bundled with this package in the file LICENSE.txt. |
| 8 | + * It is also available at https://opensource.org/license/osl-3-0-php |
| 9 | + * |
| 10 | + * @category OpenMage |
| 11 | + * @package OpenMage_Tests |
| 12 | + * @copyright Copyright (c) 2025 The OpenMage Contributors (https://www.openmage.org) |
| 13 | + * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
| 14 | + */ |
| 15 | + |
| 16 | +declare(strict_types=1); |
| 17 | + |
| 18 | +namespace OpenMage\Tests\Unit\Mage\Wishlist\Model; |
| 19 | + |
| 20 | +use Mage; |
| 21 | +use Mage_Wishlist_Model_Item as Subject; |
| 22 | +use PHPUnit\Framework\TestCase; |
| 23 | + |
| 24 | +class ItemTest extends TestCase |
| 25 | +{ |
| 26 | + /** @var Subject */ |
| 27 | + private $subject; |
| 28 | + |
| 29 | + protected function setUp(): void |
| 30 | + { |
| 31 | + Mage::app(); |
| 32 | + $this->subject = Mage::getModel('wishlist/item'); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @dataProvider qtyDataProvider |
| 37 | + * @group Mage_Wishlist |
| 38 | + * @group Mage_Wishlist_Model |
| 39 | + */ |
| 40 | + public function testSetQty(int $expectedQty, int $inputQty): void |
| 41 | + { |
| 42 | + $this->subject->setQty($inputQty); |
| 43 | + $this->assertEquals($expectedQty, $this->subject->getQty()); |
| 44 | + } |
| 45 | + |
| 46 | + public function qtyDataProvider(): \Generator |
| 47 | + { |
| 48 | + yield 'positive quantity' => [ |
| 49 | + 5, |
| 50 | + 5, |
| 51 | + ]; |
| 52 | + yield 'zero quantity' => [ |
| 53 | + 0, |
| 54 | + 0, |
| 55 | + ]; |
| 56 | + yield 'negative quantity' => [ |
| 57 | + 1, |
| 58 | + -1, |
| 59 | + ]; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @dataProvider validateDataProvider |
| 64 | + * @group Mage_Wishlist |
| 65 | + * @group Mage_Wishlist_Model |
| 66 | + */ |
| 67 | + public function testValidate(?string $expectedExceptionMessage, ?int $wishlistId, ?int $productId): void |
| 68 | + { |
| 69 | + $this->subject->setWishlistId($wishlistId); |
| 70 | + $this->subject->setProductId($productId); |
| 71 | + |
| 72 | + if ($expectedExceptionMessage) { |
| 73 | + $this->expectExceptionMessage($expectedExceptionMessage); |
| 74 | + } |
| 75 | + |
| 76 | + $result = $this->subject->validate(); |
| 77 | + |
| 78 | + if (!$expectedExceptionMessage) { |
| 79 | + $this->assertTrue($result); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + public function validateDataProvider(): \Generator |
| 84 | + { |
| 85 | + yield 'valid data' => [ |
| 86 | + null, |
| 87 | + 1, |
| 88 | + 1, |
| 89 | + ]; |
| 90 | + yield 'missing wishlist ID' => [ |
| 91 | + 'Cannot specify wishlist.', |
| 92 | + null, |
| 93 | + 1, |
| 94 | + ]; |
| 95 | + yield 'missing product ID' => [ |
| 96 | + 'Cannot specify product.', |
| 97 | + 1, |
| 98 | + null, |
| 99 | + ]; |
| 100 | + } |
| 101 | +} |
0 commit comments