This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
generated from a8cteam51/team51-plugin-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from a8cteam51/test/events
Add event tests
- Loading branch information
Showing
15 changed files
with
775 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Class AddsItemToCartEventTest | ||
* | ||
* @package Sift_Decisions | ||
*/ | ||
|
||
require_once 'EventTest.php'; | ||
|
||
// phpcs:disable Universal.Arrays.DisallowShortArraySyntax.Found, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound | ||
|
||
use WPCOMSpecialProjects\SiftDecisions\WooCommerce_Actions\Events; | ||
|
||
/** | ||
* Test case. | ||
*/ | ||
class AddsItemToCartEventTest extends EventTest { | ||
/** | ||
* Test that the $add_item_to_cart event is triggered. | ||
* | ||
* @return void | ||
*/ | ||
public function test_adds_item_to_cart() { | ||
\WC()->cart->add_to_cart( static::$product_id ); | ||
$this->assertAddsItemToCartEventTriggered(); | ||
} | ||
|
||
/** | ||
* Assert $add_item_to_cart event is triggered. | ||
* | ||
* @param integer $product_id Product ID. | ||
* | ||
* @return void | ||
*/ | ||
public static function assertAddsItemToCartEventTriggered( $product_id = null ) { | ||
$product = wc_get_product( $product_id ?? static::$product_id ); | ||
$events = static::filter_events( | ||
[ | ||
'event' => '$add_item_to_cart', | ||
'properties.$item.$sku' => $product->get_sku(), | ||
] | ||
); | ||
static::assertGreaterThanOrEqual( 1, count( $events ), 'No $add_item_to_cart event found.' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Class CreateAccountEventTest | ||
* | ||
* @package Sift_Decisions | ||
*/ | ||
|
||
require_once 'EventTest.php'; | ||
|
||
// phpcs:disable Universal.Arrays.DisallowShortArraySyntax.Found, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound | ||
|
||
use WPCOMSpecialProjects\SiftDecisions\WooCommerce_Actions\Events; | ||
|
||
/** | ||
* Test case. | ||
*/ | ||
class CreateAccountEventTest extends EventTest { | ||
/** | ||
* Test that the $create_account event is triggered. | ||
* | ||
* @return void | ||
*/ | ||
public function test_create_account() { | ||
$user = wp_create_user( 'testuser', 'password' ); | ||
|
||
$this->assertCreateAccountEventTriggered(); | ||
|
||
wp_delete_user( $user ); | ||
} | ||
|
||
/** | ||
* Assert $create_account event is triggered. | ||
* | ||
* @return void | ||
*/ | ||
public static function assertCreateAccountEventTriggered() { | ||
$events = static::filter_events( [ 'event' => '$create_account' ] ); | ||
static::assertGreaterThanOrEqual( 1, count( $events ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Class CreateOrderEventTest | ||
* | ||
* @package Sift_Decisions | ||
*/ | ||
|
||
require_once 'EventTest.php'; | ||
|
||
// phpcs:disable Universal.Arrays.DisallowShortArraySyntax.Found, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound | ||
|
||
use WPCOMSpecialProjects\SiftDecisions\WooCommerce_Actions\Events; | ||
|
||
/** | ||
* Test case. | ||
*/ | ||
class CreateOrderEventTest extends EventTest { | ||
/** | ||
* Test that the $create_order event is triggered. | ||
* | ||
* @return void | ||
*/ | ||
public function test_create_account() { | ||
// Arrange | ||
$_REQUEST['woocommerce-process-checkout-nonce'] = wp_create_nonce( 'woocommerce-process_checkout' ); | ||
add_filter( 'woocommerce_checkout_fields', fn() => [], 10, 0 ); | ||
add_filter( 'woocommerce_cart_needs_payment', '__return_false' ); | ||
|
||
// Act | ||
WC()->cart->add_to_cart( static::$product_id ); | ||
$co = WC_Checkout::instance(); | ||
$co->process_checkout(); | ||
|
||
// Assert | ||
static::assertCreateOrderEventTriggered(); | ||
} | ||
|
||
/** | ||
* Assert $create_order event is triggered. | ||
* | ||
* @return void | ||
*/ | ||
public static function assertCreateOrderEventTriggered() { | ||
$events = static::filter_events( [ 'event' => '$create_order' ] ); | ||
static::assertGreaterThanOrEqual( 1, count( $events ), 'No $create_order event found' ); | ||
} | ||
} |
Oops, something went wrong.