Skip to content

Commit

Permalink
Added: testMaybeCreateWooCommerceGoals()
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Jun 7, 2024
1 parent 3b493b8 commit 4bea534
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion tests/integration/Admin/ProvisioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Plausible\Analytics\WP\Client\Model\Goal;
use Plausible\Analytics\WP\Client\Model\GoalPageviewAllOfGoal;
use Plausible\Analytics\WP\Helpers;
use function Brain\Monkey\Functions\when;

class ProvisioningTest extends TestCase {
/**
Expand Down Expand Up @@ -49,7 +50,6 @@ public function testCreateSharedLink() {
* @throws ApiException
*/
public function testCreateGoals() {
$settings = [];
$settings[ 'enhanced_measurements' ] = [
'404',
'outbound-links',
Expand Down Expand Up @@ -92,5 +92,71 @@ public function testCreateGoals() {
$this->assertArrayHasKey( 111, $goal_ids );
$this->assertArrayHasKey( 222, $goal_ids );
$this->assertArrayHasKey( 333, $goal_ids );

delete_option( 'plausible_analytics_enhanced_measurements_goal_ids' );
}

/**
* @see Provisioning::maybe_create_woocommerce_goals()
* @return void
* @throws ApiException
*/
public function testCreateWooCommerceGoals() {
$settings = [
'enhanced_measurements' => [
'revenue',
],
];
$mock = $this->getMockBuilder( Client::class )->onlyMethods( [ 'create_goals' ] )->getMock();
$goals_array = [
new Goal(
[
'goal' => new GoalPageviewAllOfGoal( [ 'display_name' => 'Add Item To Cart', 'id' => 112, 'path' => null ] ),
'goal_type' => 'Goal.CustomEvent',
]
),
new Goal(
[
'goal' => new GoalPageviewAllOfGoal( [ 'display_name' => 'Remove Cart Item', 'id' => 223, 'path' => null ] ),
'goal_type' => 'Goal.CustomEvent',
]
),
new Goal(
[
'goal' => new GoalPageviewAllOfGoal( [ 'display_name' => 'Entered Checkout', 'id' => 334, 'path' => null ] ),
'goal_type' => 'Goal.CustomEvent',
]
),
new Goal(
[
'goal' => new GoalPageviewAllOfGoal( [ 'display_name' => 'Purchase', 'id' => 445, 'path' => null ] ),
'goal_type' => 'Goal.Revenue',
]
),
];
$goals = new Client\Model\GoalListResponse();

$goals->setGoals( $goals_array );
$goals->setMeta( new Client\Model\GoalListResponseMeta() );
$mock->method( 'create_goals' )->willReturn( $goals );

$class = new Provisioning( $mock );

add_filter( 'plausible_analytics_integrations_woocommerce', '__return_true' );
when( 'get_woocommerce_currency' )->justReturn( 'EUR' );

$class->maybe_create_woocommerce_goals( [], $settings );

remove_filter( 'plausible_analytics_integrations_woocommerce', '__return_true' );

$goal_ids = get_option( 'plausible_analytics_enhanced_measurements_goal_ids' );

$this->assertCount( 4, $goal_ids );
$this->assertArrayHasKey( 112, $goal_ids );
$this->assertArrayHasKey( 223, $goal_ids );
$this->assertArrayHasKey( 334, $goal_ids );
$this->assertArrayHasKey( 445, $goal_ids );

delete_option( 'plausible_analytics_enhanced_measurements_goal_ids' );
}
}

0 comments on commit 4bea534

Please sign in to comment.