Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
},
"type": "prestashop-module",
"author": "PrestaShop"
}
}
69 changes: 69 additions & 0 deletions src/ApiPlatform/Resources/ShowcaseCard/ShowcaseCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

declare(strict_types=1);

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\ShowcaseCard;

use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Command\CloseShowcaseCardCommand;
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Query\GetShowcaseCardIsClosed;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;

#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/showcase-cards/{showcaseCardName}/{employeeId}',
requirements: [
'showcaseCardName' => '[a-z_-]+',
'employeeId' => '\d+',
],
CQRSQuery: GetShowcaseCardIsClosed::class,
CQRSQueryMapping: [
'[_queryResult]' => '[closed]',
],
scopes: ['showcase_card_read'],
),
new CQRSUpdate(
uriTemplate: '/showcase-cards/{showcaseCardName}/{employeeId}/close',
requirements: [
'showcaseCardName' => '[a-z_-]+',
'employeeId' => '\d+',
],
allowEmptyBody: true,
CQRSCommand: CloseShowcaseCardCommand::class,
CQRSQuery: GetShowcaseCardIsClosed::class,
CQRSQueryMapping: [
'[_queryResult]' => '[closed]',
],
scopes: ['showcase_card_write'],
),
],
)]
class ShowcaseCard
{
public string $showcaseCardName;

public int $employeeId;

public bool $closed;
}
78 changes: 78 additions & 0 deletions tests/Integration/ApiPlatform/ShowcaseCardEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

declare(strict_types=1);

namespace PsApiResourcesTest\Integration\ApiPlatform;

use Tests\Resources\DatabaseDump;

class ShowcaseCardEndpointTest extends ApiTestCase
{
protected const TEST_SHOWCASECARD = 'monitoring_card';
protected const TEST_EMPLOYEE_ID = 1;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::createApiClient(['showcase_card_read', 'showcase_card_write']);
}

public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
// Reset DB as it was before this test
DatabaseDump::restoreTables(['configuration']);
}

public static function getProtectedEndpoints(): iterable
{
yield 'get endpoint' => [
'GET',
'/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID,
];
yield 'put endpoint' => [
'PUT',
'/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close',
];
}

public function testGetShowcard(): void
{
$showcaseCard = $this->getItem('/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID, ['showcase_card_read']);

$this->assertEquals(self::TEST_SHOWCASECARD, $showcaseCard['showcaseCardName']);
$this->assertEquals(self::TEST_EMPLOYEE_ID, $showcaseCard['employeeId']);
$this->assertEquals(false, $showcaseCard['closed']);
}

/**
* @depends testGetShowcard
*/
public function testCloseShowcard(): void
{
$showcaseCard = $this->updateItem('/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close', null, ['showcase_card_write']);

$this->assertEquals(self::TEST_SHOWCASECARD, $showcaseCard['showcaseCardName']);
$this->assertEquals(self::TEST_EMPLOYEE_ID, $showcaseCard['employeeId']);
$this->assertEquals(true, $showcaseCard['closed']);
}
}
1 change: 1 addition & 0 deletions tests/Rector/ApiResourceUriTemplateRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ final class ApiResourceUriTemplateRector extends AbstractRector
'thumbnail',
'logo',
'duplicate',
'close',
];

public function __construct()
Expand Down
Loading