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
24 changes: 24 additions & 0 deletions src/WooCommerce/Method/OrderMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,30 @@ public function seeOrderInDatabase(array $criteria): void
$this->wpDb()->seeInDatabase($tableName, $mappedCriteria);
}

/**
* Verify that no order exists in the database with the given criteria.
*
* @example
* ```php
* $orderId = $I->haveOrderInDatabase(['status' => 'completed']);
* $I->dontSeeOrderInDatabase(['id' => $orderId, 'status' => 'cancelled']);
* $I->dontSeeOrderInDatabase(['id' => 999999]);
* ```
*
* Accepts a `status` criterion with or without the `wc-` prefix (e.g. `cancelled` or
* `wc-cancelled`); it is normalized before matching against the stored value.
*
* @param array<string, mixed> $criteria Database query criteria (e.g., ['id' => 123, 'status' => 'cancelled']). Supports storage-agnostic keys like 'id', 'status'
*
* @return void
*/
public function dontSeeOrderInDatabase(array $criteria): void
{
$tableName = $this->orderStorage()->getTableName();
$mappedCriteria = $this->orderStorage()->mapCriteria($criteria);
$this->wpDb()->dontSeeInDatabase($tableName, $mappedCriteria);
}

/**
* Verify that order meta exists in the database with the given criteria.
*
Expand Down
30 changes: 30 additions & 0 deletions tests/acceptance/OrderCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Aztec\WPBrowser\Tests\Acceptance;

use Aztec\WPBrowser\Tests\Support\AcceptanceTester;
use PHPUnit\Framework\AssertionFailedError;

class OrderCest
{
Expand Down Expand Up @@ -368,6 +369,35 @@ public function testSeeOrderInDatabaseNormalizesUnprefixedStatusCriterion(Accept
]);
}

public function testDontSeeOrderInDatabaseNormalizesUnprefixedStatusCriterion(AcceptanceTester $I): void
{
$orderId = $I->haveOrderInDatabase([
'post_status' => 'wc-active',
]);

$I->dontSeeOrderInDatabase([
'id' => $orderId,
'status' => 'cancelled',
]);

// If the unprefixed 'active' criterion were not normalized to 'wc-active', it would
// never match the stored row and dontSeeOrderInDatabase would (incorrectly) pass.
$I->expectThrowable(
AssertionFailedError::class,
function () use ($I, $orderId): void {
$I->dontSeeOrderInDatabase([
'id' => $orderId,
'status' => 'active',
]);
},
);
}

public function testDontSeeOrderInDatabaseWithNonStatusCriteria(AcceptanceTester $I): void
{
$I->dontSeeOrderInDatabase(['id' => 999999]);
}

public function testSeeOrderMetaInDatabase(AcceptanceTester $I): void
{
$orderId = $I->haveOrderInDatabase();
Expand Down
30 changes: 30 additions & 0 deletions tests/acceptance/OrderHPOSCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Aztec\WPBrowser\Tests\Acceptance;

use Aztec\WPBrowser\Tests\Support\AcceptanceTester;
use PHPUnit\Framework\AssertionFailedError;

class OrderHPOSCest
{
Expand Down Expand Up @@ -354,6 +355,35 @@ public function testSeeOrderInDatabaseNormalizesUnprefixedStatusCriterion(Accept
]);
}

public function testDontSeeOrderInDatabaseNormalizesUnprefixedStatusCriterion(AcceptanceTester $I): void
{
$orderId = $I->haveOrderInDatabase([
'status' => 'wc-active',
]);

$I->dontSeeOrderInDatabase([
'id' => $orderId,
'status' => 'cancelled',
]);

// If the unprefixed 'active' criterion were not normalized to 'wc-active', it would
// never match the stored row and dontSeeOrderInDatabase would (incorrectly) pass.
$I->expectThrowable(
AssertionFailedError::class,
function () use ($I, $orderId): void {
$I->dontSeeOrderInDatabase([
'id' => $orderId,
'status' => 'active',
]);
},
);
}

public function testDontSeeOrderInDatabaseWithNonStatusCriteria(AcceptanceTester $I): void
{
$I->dontSeeOrderInDatabase(['id' => 999999]);
}

public function testSeeOrderMetaInDatabase(AcceptanceTester $I): void
{
$orderId = $I->haveOrderInDatabase();
Expand Down
25 changes: 25 additions & 0 deletions tests/acceptance/SubscriptionCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Aztec\WPBrowser\Tests\Acceptance;

use Aztec\WPBrowser\Tests\Support\AcceptanceTester;
use PHPUnit\Framework\AssertionFailedError;

class SubscriptionCest
{
Expand Down Expand Up @@ -285,6 +286,30 @@ public function testDontSeeSubscriptionInDatabase(AcceptanceTester $I): void
]);
}

public function testDontSeeSubscriptionInDatabaseNormalizesUnprefixedStatusCriterion(AcceptanceTester $I): void
{
$subscriptionId = $I->haveSubscriptionInDatabase([
'post_status' => 'wc-active',
]);

$I->dontSeeSubscriptionInDatabase([
'id' => $subscriptionId,
'status' => 'cancelled',
]);

// If the unprefixed 'active' criterion were not normalized to 'wc-active', it would
// never match the stored row and dontSeeSubscriptionInDatabase would (incorrectly) pass.
$I->expectThrowable(
AssertionFailedError::class,
function () use ($I, $subscriptionId): void {
$I->dontSeeSubscriptionInDatabase([
'id' => $subscriptionId,
'status' => 'active',
]);
},
);
}

public function testDontSeeSubscriptionMetaInDatabase(AcceptanceTester $I): void
{
$subscriptionId = $I->haveSubscriptionInDatabase();
Expand Down
Loading