|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright since 2007 PrestaShop SA and Contributors |
| 4 | + * PrestaShop is an International Registered Trademark & Property of PrestaShop SA |
| 5 | + * |
| 6 | + * NOTICE OF LICENSE |
| 7 | + * |
| 8 | + * This source file is subject to the Academic Free License version 3.0 |
| 9 | + * that is bundled with this package in the file LICENSE.md. |
| 10 | + * It is also available through the world-wide-web at this URL: |
| 11 | + * https://opensource.org/licenses/AFL-3.0 |
| 12 | + * If you did not receive a copy of the license and are unable to |
| 13 | + * obtain it through the world-wide-web, please send an email |
| 14 | + * to license@prestashop.com so we can send you a copy immediately. |
| 15 | + * |
| 16 | + * @author PrestaShop SA and Contributors <contact@prestashop.com> |
| 17 | + * @copyright Since 2007 PrestaShop SA and Contributors |
| 18 | + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 |
| 19 | + */ |
| 20 | + |
| 21 | +namespace PsApiResourcesTest\Integration\ApiPlatform; |
| 22 | + |
| 23 | +class DiscountTypeEndpointTest extends ApiTestCase |
| 24 | +{ |
| 25 | + public static function setUpBeforeClass(): void |
| 26 | + { |
| 27 | + parent::setUpBeforeClass(); |
| 28 | + self::createApiClient(); |
| 29 | + } |
| 30 | + |
| 31 | + public static function getProtectedEndpoints(): iterable |
| 32 | + { |
| 33 | + // The endpoint doesn't require any scope but you still need to be logged (have a valid token) |
| 34 | + yield 'get endpoint' => [ |
| 35 | + 'GET', |
| 36 | + '/discount-types', |
| 37 | + ]; |
| 38 | + } |
| 39 | + |
| 40 | + public function testGetDiscountTypes(): void |
| 41 | + { |
| 42 | + $discountTypes = $this->listDiscountTypes(); |
| 43 | + |
| 44 | + $this->assertGreaterThanOrEqual(1, count($discountTypes)); |
| 45 | + |
| 46 | + if (count($discountTypes) > 0) { |
| 47 | + $firstType = $discountTypes[0]; |
| 48 | + $this->assertArrayHasKey('discountTypeId', $firstType); |
| 49 | + $this->assertArrayHasKey('type', $firstType); |
| 50 | + $this->assertArrayHasKey('names', $firstType); |
| 51 | + $this->assertArrayHasKey('descriptions', $firstType); |
| 52 | + $this->assertArrayHasKey('isCore', $firstType); |
| 53 | + $this->assertArrayHasKey('active', $firstType); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + private function listDiscountTypes(): array |
| 58 | + { |
| 59 | + $bearerToken = $this->getBearerToken(); |
| 60 | + $response = static::createClient()->request('GET', '/discount-types', [ |
| 61 | + 'auth_bearer' => $bearerToken, |
| 62 | + ]); |
| 63 | + self::assertResponseStatusCodeSame(200); |
| 64 | + |
| 65 | + $decodedResponse = json_decode($response->getContent(), true); |
| 66 | + $this->assertNotFalse($decodedResponse); |
| 67 | + $this->assertIsArray($decodedResponse); |
| 68 | + |
| 69 | + return $decodedResponse; |
| 70 | + } |
| 71 | +} |
0 commit comments