diff --git a/src/Admin/Provisioning.php b/src/Admin/Provisioning.php index a7ebfe17..3c64aeb6 100644 --- a/src/Admin/Provisioning.php +++ b/src/Admin/Provisioning.php @@ -231,6 +231,8 @@ private function create_goals( $goals ) { * @param $settings * * @return void + * + * @codeCoverageIgnore Because we don't want to test the API. */ public function maybe_create_woocommerce_funnels( $old_settings, $settings ) { if ( ! Helpers::is_enhanced_measurement_enabled( 'revenue', $settings[ 'enhanced_measurements' ] ) || ! Integrations::is_wc_active() ) { @@ -261,7 +263,7 @@ public function maybe_create_woocommerce_funnels( $old_settings, $settings ) { * * @return void * - * @codeCoverageIgnore Because this method should be mocked in tests. + * @codeCoverageIgnore Because this method should be mocked in tests if needed. */ private function create_funnel( $name, $steps ) { $create_request = new Client\Model\FunnelCreateRequest( diff --git a/tests/integration/Admin/ProvisioningTest.php b/tests/integration/Admin/ProvisioningTest.php index 160275da..a21d9928 100644 --- a/tests/integration/Admin/ProvisioningTest.php +++ b/tests/integration/Admin/ProvisioningTest.php @@ -103,68 +103,4 @@ public function testCreateGoals() { delete_option( 'plausible_analytics_enhanced_measurements_goal_ids' ); } - - /** - * @see Provisioning::maybe_create_woocommerce_funnels() - * @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_funnels( [], $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' ); - } }