Skip to content

Commit

Permalink
Added: testGetPostSettings and expanded testGetFilename
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Jun 7, 2024
1 parent 845b9ae commit 0890bdd
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions tests/integration/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Plausible\Analytics\Tests\Integration;

use Exception;
use Plausible\Analytics\Tests\TestCase;
use Plausible\Analytics\WP\Helpers;

Expand Down Expand Up @@ -49,6 +50,7 @@ public function enableSelfHostedDomain( $settings ) {

/**
* @see Helpers::get_filename()
* @throws Exception
*/
public function testGetFilename() {
add_filter( 'plausible_analytics_settings', [ $this, 'addExcludedPages' ] );
Expand All @@ -74,6 +76,16 @@ public function testGetFilename() {
remove_filter( 'plausible_analytics_settings', [ $this, 'enableOutboundLinks' ] );

$this->assertEquals( 'plausible.outbound-links', $filename );

add_filter( 'plausible_analytics_settings', [ $this, 'enableRevenue' ] );
add_filter( 'plausible_analytics_integrations_woocommerce', '__return_true' );

$filename = Helpers::get_filename();

remove_filter( 'plausible_analytics_settings', [ $this, 'enableRevenue' ] );
remove_filter( 'plausible_analytics_integrations_woocommerce', '__return_true' );

$this->assertEquals( 'plausible.revenue.tagged-events', $filename );
}

/**
Expand Down Expand Up @@ -102,10 +114,37 @@ public function enableOutboundLinks( $settings ) {
return $settings;
}

/**
* Enable Enhanced Measurements > Custom Events (Tagged Events)
*
* @param $settings
*
* @return mixed
*/
public function enableRevenue( $settings ) {
$settings[ 'enhanced_measurements' ] = [ 'revenue' ];

return $settings;
}

/**
* @see Helpers::get_settings()
*
* @return void
*/
public function testGetPostSettings() {
$_POST[ 'action' ] = 'plausible_analytics_save_options';
$_POST[ 'options' ] = wp_json_encode( [ [ 'name' => 'test', 'value' => 'test' ] ] );

$settings = Helpers::get_settings();

$this->assertArrayHasKey( 'test', $settings );
}

/**
* @see Helpers::get_proxy_resource()
* @return void
* @throws \Exception
* @throws Exception
*/
public function testGetProxyResource() {
$namespace = Helpers::get_proxy_resource( 'namespace' );
Expand Down Expand Up @@ -149,7 +188,7 @@ public function testUpdateSetting() {
/**
* @see Helpers::get_js_path()
* @return void
* @throws \Exception
* @throws Exception
*/
public function testGetJsPath() {
add_filter( 'plausible_analytics_settings', [ $this, 'enableProxy' ] );
Expand All @@ -166,7 +205,7 @@ public function testGetJsPath() {
/**
* @see Helpers::download_file()
* @return void
* @throws \Exception
* @throws Exception
*/
public function testDownloadFile() {
Helpers::download_file( 'https://plausible.io/js/plausible.js', wp_get_upload_dir()[ 'basedir' ] . '/test.js' );
Expand Down Expand Up @@ -221,7 +260,7 @@ public function testGetDataApiUrl() {
/**
* @see Helpers::get_rest_endpoint()
* @return void
* @throws \Exception
* @throws Exception
*/
public function testGetRestEndpoint() {
$endpoint = Helpers::get_rest_endpoint( false );
Expand Down

0 comments on commit 0890bdd

Please sign in to comment.