Skip to content

Commit

Permalink
Expandend ActionsTest and ignored some code from coverage we can't test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Mar 27, 2024
1 parent b37ec65 commit 448ca68
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Actions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* Plausible Analytics | Actions.
*
* @since 1.0.0
* @package WordPress
* @subpackage Plausible Analytics
Expand All @@ -13,6 +14,7 @@
class Actions {
/**
* Constructor.
*
* @since 1.0.0
* @access public
* @return void
Expand All @@ -24,6 +26,7 @@ public function __construct() {

/**
* Register Assets.
*
* @since 1.0.0
* @access public
* @return void
Expand All @@ -38,7 +41,7 @@ public function maybe_register_assets() {
*/
if ( ( ! empty( $user_role ) && ! isset( $settings[ 'tracked_user_roles' ] ) ) ||
( ! empty( $user_role ) && ! in_array( $user_role, $settings[ 'tracked_user_roles' ], true ) ) ) {
return;
return; // @codeCoverageIgnore
}

$version =
Expand All @@ -65,6 +68,7 @@ public function maybe_register_assets() {

/**
* Create admin bar nodes.
*
* @since 1.3.0
* @access public
*
Expand All @@ -76,12 +80,12 @@ public function admin_bar_node( $admin_bar ) {
$disable = ! empty( Helpers::get_settings()[ 'disable_toolbar_menu' ] );

if ( $disable ) {
return;
return; // @codeCoverageIgnore
}

// Add main admin bar node.
$args[] = [
'id' => 'plausible-admin-bar',
'id' => 'plausible-analytics',
'title' => 'Plausible Analytics',
];

Expand All @@ -93,7 +97,7 @@ public function admin_bar_node( $admin_bar ) {
'id' => 'view-analytics',
'title' => esc_html__( 'View Analytics', 'plausible-analytics' ),
'href' => admin_url( 'index.php?page=plausible_analytics_statistics' ),
'parent' => 'plausible-admin-bar',
'parent' => 'plausible-analytics',
];

// Add link to individual page stats.
Expand All @@ -109,7 +113,7 @@ public function admin_bar_node( $admin_bar ) {
is_home() ? '' : $uri,
admin_url( 'index.php?page=plausible_analytics_statistics' )
),
'parent' => 'plausible-admin-bar',
'parent' => 'plausible-analytics',
];
}
}
Expand All @@ -119,7 +123,7 @@ public function admin_bar_node( $admin_bar ) {
'id' => 'settings',
'title' => esc_html__( 'Settings', 'plausible-analytics' ),
'href' => admin_url( 'options-general.php?page=plausible_analytics' ),
'parent' => 'plausible-admin-bar',
'parent' => 'plausible-analytics',
];

foreach ( $args as $arg ) {
Expand Down
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct( $token = '' ) {

/**
* Validates the API token (password) set in the current instance and caches the state to a transient valid for 1 day.
*
* @return bool
* @throws ApiException
*/
Expand Down Expand Up @@ -75,6 +76,7 @@ public function validate_api_token() {

/**
* Retrieve Features from Capabilities object.
*
* @return false|Client\Model\CapabilitiesFeatures
*/
private function get_features() {
Expand All @@ -89,6 +91,7 @@ private function get_features() {

/**
* Retrieve all capabilities assigned to configured API token.
*
* @return bool|Client\Model\Capabilities
*/
private function get_capabilities() {
Expand All @@ -101,6 +104,7 @@ private function get_capabilities() {

/**
* Retrieve Data Domain property from Capabilities object.
*
* @return false|string
*/
private function get_data_domain() {
Expand All @@ -115,10 +119,12 @@ private function get_data_domain() {

/**
* Create Shared Link in Plausible Dashboard.
*
* @return void
*/
public function create_shared_link() {
$shared_link = (object) [];
$result = (object) [];

try {
$result = $this->api_instance->plausibleWebPluginsAPIControllersSharedLinksCreate(
Expand Down
7 changes: 7 additions & 0 deletions src/Cron.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* Plausible Analytics | Cron.
*
* @since 1.3.0
* @package WordPress
* @subpackage Plausible Analytics
Expand All @@ -13,9 +14,13 @@

defined( 'ABSPATH' ) || exit;

/**
* @codeCoverageIgnore
*/
class Cron {
/**
* Build class
*
* @return void
* @throws InvalidArgument
* @throws Exception
Expand All @@ -26,6 +31,7 @@ public function __construct() {

/**
* Run
*
* @return void
* @throws InvalidArgument
* @throws Exception
Expand All @@ -36,6 +42,7 @@ private function init() {

/**
* Download the plausible.js file if the Proxy is enabled and downloads it to the uploads directory with an alias.
*
* @return bool
* @throws InvalidArgument
* @throws Exception
Expand Down
8 changes: 8 additions & 0 deletions src/Uninstall.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* Plausible Analytics | Uninstall script.
*
* @since 1.3.0
* @package WordPress
* @subpackage Plausible Analytics
Expand All @@ -12,11 +13,15 @@

/**
* This class is run upon uninstall and cleans up any data in the database and leftover files added by this plugin.
*
* @package Plausible\Analytics\WP
*
* @codeCoverageIgnore
*/
class Uninstall {
/**
* Trigger logic.
*
* @return void
*/
public function run() {
Expand All @@ -27,6 +32,7 @@ public function run() {

/**
* Delete options.
*
* @return void
*/
private function delete_options() {
Expand All @@ -39,6 +45,7 @@ private function delete_options() {

/**
* Delete transients.
*
* @return void
*/
private function delete_transients() {
Expand All @@ -48,6 +55,7 @@ private function delete_transients() {

/**
* Deletes the Proxy Speed Module from the mu-plugins directory.
*
* @return void
*/
private function delete_proxy_speed_module() {
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/ActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Plausible\Analytics\Tests\TestCase;
use Plausible\Analytics\WP\Actions;
use Plausible\Analytics\WP\Helpers;
use WP_Admin_Bar;

class ActionsTest extends TestCase {
/**
Expand All @@ -32,4 +33,21 @@ public function testRegisterAssets() {
remove_filter( 'plausible_analytics_settings', [ $this, 'enableProxy' ] );
remove_filter( 'plausible_analytics_settings', [ $this, 'setDomain' ] );
}

/**
* @see Actions::admin_bar_node()
*/
public function testAdminBarNode() {
$class = new Actions();

if ( ! class_exists( 'WP_Admin_Bar' ) ) {
require_once( ABSPATH . 'wp-includes/class-wp-admin-bar.php' );
}

$admin_bar = new WP_Admin_Bar();

$class->admin_bar_node( $admin_bar );

$this->assertNotEmpty( $admin_bar->get_node( 'plausible-analytics' ) );
}
}

0 comments on commit 448ca68

Please sign in to comment.