Skip to content
Merged
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
20 changes: 20 additions & 0 deletions Classes/Domain/Model/Order/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ public function toArray(): array
return $payment;
}

public function isOpen(): bool
{
return $this->getStatus() === 'open';
}

public function isPending(): bool
{
return $this->getStatus() === 'pending';
}

public function isPaid(): bool
{
return $this->getStatus() === 'paid';
}

public function isCanceled(): bool
{
return $this->getStatus() === 'canceled';
}

public function getProvider(): ?string
{
return $this->provider;
Expand Down
23 changes: 22 additions & 1 deletion Classes/Domain/Model/Order/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,25 @@
* LICENSE file that was distributed with this source code.
*/

class Shipping extends AbstractService {}
class Shipping extends AbstractService
{
public function isOpen(): bool
{
return $this->getStatus() === 'open';
}

public function isOnHold(): bool
{
return $this->getStatus() === 'on_hold';
}

public function isInProcess(): bool
{
return $this->getStatus() === 'in_process';
}

public function isShipped(): bool
{
return $this->getStatus() === 'shipped';
}
}
32 changes: 32 additions & 0 deletions Documentation/Changelog/11.10/Feature-866-OrderStatusMethods.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. include:: ../../Includes.rst.txt

==========================================================================
Feature: #866 - Status methods of the payment and the shipping of an order
==========================================================================

See `Issue 866 <https://github.com/extcode/cart/issues/866>`__

Description
===========

The payment (``\Extcode\Cart\Domain\Model\Order\Payment``) and the shipping
(``\Extcode\Cart\Domain\Model\Order\Shipping``) of an order have new methods
for the status of EXT:cart:

========= ==================================================================
Service Methods
========= ==================================================================
payment ``isOpen()``, ``isPending()``, ``isPaid()``, ``isCanceled()``
shipping ``isOpen()``, ``isOnHold()``, ``isInProcess()``, ``isShipped()``
========= ==================================================================

Further status added by other extensions have no method, compare them with
``getStatus()``.

Impact
======

Extensions, e.g. for payment providers, use the methods instead of comparing
the status with strings themselves.

.. index:: PHP-API
24 changes: 24 additions & 0 deletions Documentation/Changelog/11.10/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. include:: ../../Includes.rst.txt

11.10 Changes
=============

**Table of contents**

.. contents::
:local:
:depth: 1

11.10.0
-------

Features
~~~~~~~~

* :doc:`#866 - Status methods of the payment and the shipping of an order <Feature-866-OrderStatusMethods>`

.. toctree::
:hidden:
:glob:

*-*
1 change: 1 addition & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ChangeLog
:maxdepth: 5
:titlesonly:

11.10/Index
11.9/Index
11.8/Index
11.7/Index
Expand Down
30 changes: 30 additions & 0 deletions Tests/Unit/Domain/Model/Order/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Extcode\Cart\Domain\Model\Order\Payment;
use Extcode\Cart\Domain\Model\Order\Transaction;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
Expand All @@ -28,6 +29,35 @@ public function setUp(): void
parent::setUp();
}

#[DataProvider('statusDataProvider')]
#[Test]
public function statusMethodsReturnWhetherThePaymentHasTheStatus(
string $status,
bool $isOpen,
bool $isPending,
bool $isPaid,
bool $isCanceled,
): void {
$this->payment->setStatus($status);

self::assertSame($isOpen, $this->payment->isOpen());
self::assertSame($isPending, $this->payment->isPending());
self::assertSame($isPaid, $this->payment->isPaid());
self::assertSame($isCanceled, $this->payment->isCanceled());
}

/**
* @return iterable<string, array{string, bool, bool, bool, bool}>
*/
public static function statusDataProvider(): iterable
{
yield 'open' => ['open', true, false, false, false];
yield 'pending' => ['pending', false, true, false, false];
yield 'paid' => ['paid', false, false, true, false];
yield 'canceled' => ['canceled', false, false, false, true];
yield 'status of another extension' => ['refunded', false, false, false, false];
}

#[Test]
public function toArrayReturnsArray(): void
{
Expand Down
30 changes: 30 additions & 0 deletions Tests/Unit/Domain/Model/Order/ShippingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Extcode\Cart\Domain\Model\Order\Shipping;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

Expand All @@ -26,6 +27,35 @@ public function setUp(): void
parent::setUp();
}

#[DataProvider('statusDataProvider')]
#[Test]
public function statusMethodsReturnWhetherTheShippingHasTheStatus(
string $status,
bool $isOpen,
bool $isOnHold,
bool $isInProcess,
bool $isShipped,
): void {
$this->shipping->setStatus($status);

self::assertSame($isOpen, $this->shipping->isOpen());
self::assertSame($isOnHold, $this->shipping->isOnHold());
self::assertSame($isInProcess, $this->shipping->isInProcess());
self::assertSame($isShipped, $this->shipping->isShipped());
}

/**
* @return iterable<string, array{string, bool, bool, bool, bool}>
*/
public static function statusDataProvider(): iterable
{
yield 'open' => ['open', true, false, false, false];
yield 'on hold' => ['on_hold', false, true, false, false];
yield 'in process' => ['in_process', false, false, true, false];
yield 'shipped' => ['shipped', false, false, false, true];
yield 'status of another extension' => ['delivered', false, false, false, false];
}

#[Test]
public function getNameInitiallyReturnsEmptyString(): void
{
Expand Down
Loading