Skip to content

Commit 448ca68

Browse files
committed
Expandend ActionsTest and ignored some code from coverage we can't test.
1 parent b37ec65 commit 448ca68

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

src/Actions.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* Plausible Analytics | Actions.
4+
*
45
* @since 1.0.0
56
* @package WordPress
67
* @subpackage Plausible Analytics
@@ -13,6 +14,7 @@
1314
class Actions {
1415
/**
1516
* Constructor.
17+
*
1618
* @since 1.0.0
1719
* @access public
1820
* @return void
@@ -24,6 +26,7 @@ public function __construct() {
2426

2527
/**
2628
* Register Assets.
29+
*
2730
* @since 1.0.0
2831
* @access public
2932
* @return void
@@ -38,7 +41,7 @@ public function maybe_register_assets() {
3841
*/
3942
if ( ( ! empty( $user_role ) && ! isset( $settings[ 'tracked_user_roles' ] ) ) ||
4043
( ! empty( $user_role ) && ! in_array( $user_role, $settings[ 'tracked_user_roles' ], true ) ) ) {
41-
return;
44+
return; // @codeCoverageIgnore
4245
}
4346

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

6669
/**
6770
* Create admin bar nodes.
71+
*
6872
* @since 1.3.0
6973
* @access public
7074
*
@@ -76,12 +80,12 @@ public function admin_bar_node( $admin_bar ) {
7680
$disable = ! empty( Helpers::get_settings()[ 'disable_toolbar_menu' ] );
7781

7882
if ( $disable ) {
79-
return;
83+
return; // @codeCoverageIgnore
8084
}
8185

8286
// Add main admin bar node.
8387
$args[] = [
84-
'id' => 'plausible-admin-bar',
88+
'id' => 'plausible-analytics',
8589
'title' => 'Plausible Analytics',
8690
];
8791

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

99103
// Add link to individual page stats.
@@ -109,7 +113,7 @@ public function admin_bar_node( $admin_bar ) {
109113
is_home() ? '' : $uri,
110114
admin_url( 'index.php?page=plausible_analytics_statistics' )
111115
),
112-
'parent' => 'plausible-admin-bar',
116+
'parent' => 'plausible-analytics',
113117
];
114118
}
115119
}
@@ -119,7 +123,7 @@ public function admin_bar_node( $admin_bar ) {
119123
'id' => 'settings',
120124
'title' => esc_html__( 'Settings', 'plausible-analytics' ),
121125
'href' => admin_url( 'options-general.php?page=plausible_analytics' ),
122-
'parent' => 'plausible-admin-bar',
126+
'parent' => 'plausible-analytics',
123127
];
124128

125129
foreach ( $args as $arg ) {

src/Client.php

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct( $token = '' ) {
4242

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

7677
/**
7778
* Retrieve Features from Capabilities object.
79+
*
7880
* @return false|Client\Model\CapabilitiesFeatures
7981
*/
8082
private function get_features() {
@@ -89,6 +91,7 @@ private function get_features() {
8991

9092
/**
9193
* Retrieve all capabilities assigned to configured API token.
94+
*
9295
* @return bool|Client\Model\Capabilities
9396
*/
9497
private function get_capabilities() {
@@ -101,6 +104,7 @@ private function get_capabilities() {
101104

102105
/**
103106
* Retrieve Data Domain property from Capabilities object.
107+
*
104108
* @return false|string
105109
*/
106110
private function get_data_domain() {
@@ -115,10 +119,12 @@ private function get_data_domain() {
115119

116120
/**
117121
* Create Shared Link in Plausible Dashboard.
122+
*
118123
* @return void
119124
*/
120125
public function create_shared_link() {
121126
$shared_link = (object) [];
127+
$result = (object) [];
122128

123129
try {
124130
$result = $this->api_instance->plausibleWebPluginsAPIControllersSharedLinksCreate(

src/Cron.php

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* Plausible Analytics | Cron.
4+
*
45
* @since 1.3.0
56
* @package WordPress
67
* @subpackage Plausible Analytics
@@ -13,9 +14,13 @@
1314

1415
defined( 'ABSPATH' ) || exit;
1516

17+
/**
18+
* @codeCoverageIgnore
19+
*/
1620
class Cron {
1721
/**
1822
* Build class
23+
*
1924
* @return void
2025
* @throws InvalidArgument
2126
* @throws Exception
@@ -26,6 +31,7 @@ public function __construct() {
2631

2732
/**
2833
* Run
34+
*
2935
* @return void
3036
* @throws InvalidArgument
3137
* @throws Exception
@@ -36,6 +42,7 @@ private function init() {
3642

3743
/**
3844
* Download the plausible.js file if the Proxy is enabled and downloads it to the uploads directory with an alias.
45+
*
3946
* @return bool
4047
* @throws InvalidArgument
4148
* @throws Exception

src/Uninstall.php

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* Plausible Analytics | Uninstall script.
4+
*
45
* @since 1.3.0
56
* @package WordPress
67
* @subpackage Plausible Analytics
@@ -12,11 +13,15 @@
1213

1314
/**
1415
* This class is run upon uninstall and cleans up any data in the database and leftover files added by this plugin.
16+
*
1517
* @package Plausible\Analytics\WP
18+
*
19+
* @codeCoverageIgnore
1620
*/
1721
class Uninstall {
1822
/**
1923
* Trigger logic.
24+
*
2025
* @return void
2126
*/
2227
public function run() {
@@ -27,6 +32,7 @@ public function run() {
2732

2833
/**
2934
* Delete options.
35+
*
3036
* @return void
3137
*/
3238
private function delete_options() {
@@ -39,6 +45,7 @@ private function delete_options() {
3945

4046
/**
4147
* Delete transients.
48+
*
4249
* @return void
4350
*/
4451
private function delete_transients() {
@@ -48,6 +55,7 @@ private function delete_transients() {
4855

4956
/**
5057
* Deletes the Proxy Speed Module from the mu-plugins directory.
58+
*
5159
* @return void
5260
*/
5361
private function delete_proxy_speed_module() {

tests/integration/ActionsTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Plausible\Analytics\Tests\TestCase;
99
use Plausible\Analytics\WP\Actions;
1010
use Plausible\Analytics\WP\Helpers;
11+
use WP_Admin_Bar;
1112

1213
class ActionsTest extends TestCase {
1314
/**
@@ -32,4 +33,21 @@ public function testRegisterAssets() {
3233
remove_filter( 'plausible_analytics_settings', [ $this, 'enableProxy' ] );
3334
remove_filter( 'plausible_analytics_settings', [ $this, 'setDomain' ] );
3435
}
36+
37+
/**
38+
* @see Actions::admin_bar_node()
39+
*/
40+
public function testAdminBarNode() {
41+
$class = new Actions();
42+
43+
if ( ! class_exists( 'WP_Admin_Bar' ) ) {
44+
require_once( ABSPATH . 'wp-includes/class-wp-admin-bar.php' );
45+
}
46+
47+
$admin_bar = new WP_Admin_Bar();
48+
49+
$class->admin_bar_node( $admin_bar );
50+
51+
$this->assertNotEmpty( $admin_bar->get_node( 'plausible-analytics' ) );
52+
}
3553
}

0 commit comments

Comments
 (0)