Skip to content

Commit f0956ea

Browse files
refactor: add unit test for dashboard data
1 parent 5af1eef commit f0956ea

File tree

2 files changed

+102
-6
lines changed

2 files changed

+102
-6
lines changed

inc/plugins/class-dashboard.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ public function form_submissions_callback() {
192192
* @access public
193193
*/
194194
public function enqueue_options_assets() {
195-
$wp_upload_dir = wp_upload_dir( null, false );
196-
$basedir = $wp_upload_dir['basedir'] . '/themeisle-gutenberg/';
197-
$asset_file = include OTTER_BLOCKS_PATH . '/build/dashboard/index.asset.php';
195+
$asset_file = include OTTER_BLOCKS_PATH . '/build/dashboard/index.asset.php';
198196

199197
wp_enqueue_style(
200198
'otter-blocks-styles',
@@ -213,8 +211,6 @@ public function enqueue_options_assets() {
213211

214212
wp_set_script_translations( 'otter-blocks-scripts', 'otter-blocks' );
215213

216-
$offer = new LimitedOffers();
217-
218214
wp_localize_script(
219215
'otter-blocks-scripts',
220216
'otterObj',
@@ -275,7 +271,7 @@ public function get_dashboard_data() {
275271
'neveInstalled' => defined( 'NEVE_VERSION' ),
276272
);
277273

278-
$this->load_survey();
274+
return apply_filters( 'otter_dashboard_data', $global_data );
279275
}
280276

281277
/**

tests/test-dashboard.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Class Dashboard
4+
*
5+
* @package gutenberg-blocks
6+
*/
7+
8+
use ThemeIsle\GutenbergBlocks\Plugins\Dashboard;
9+
10+
/**
11+
* Dashboard Test Case.
12+
*/
13+
class Test_Dashboard extends WP_UnitTestCase {
14+
15+
/**
16+
* @var Dashboard
17+
*/
18+
private $dashboard;
19+
20+
/**
21+
* Set up test environment.
22+
*/
23+
public function set_up() {
24+
parent::set_up();
25+
$this->dashboard = Dashboard::instance();
26+
27+
28+
if ( ! function_exists( 'tsdk_translate_link' ) ) {
29+
function tsdk_translate_link( $link ) {
30+
return $link;
31+
}
32+
}
33+
34+
if ( ! function_exists( 'tsdk_utmify' ) ) {
35+
function tsdk_utmify( $link ) {
36+
return $link;
37+
}
38+
}
39+
}
40+
41+
/**
42+
* Test get_dashboard_data returns expected structure
43+
*/
44+
public function test_get_dashboard_data() {
45+
$data = $this->dashboard->get_dashboard_data();
46+
47+
// Test required keys exist
48+
$required_keys = array(
49+
'version',
50+
'assetsPath',
51+
'stylesExist',
52+
'hasPro',
53+
'upgradeLink',
54+
'docsLink',
55+
'showFeedbackNotice',
56+
'deal',
57+
'hasOnboarding',
58+
'days_since_install',
59+
'rootUrl',
60+
'neveThemePreviewUrl',
61+
'neveThemeActivationUrl',
62+
'neveDashboardUrl',
63+
'neveInstalled',
64+
);
65+
66+
foreach ( $required_keys as $key ) {
67+
$this->assertArrayHasKey( $key, $data, "Dashboard data missing required key: {$key}" );
68+
}
69+
70+
// Test specific value types
71+
$this->assertIsString( $data['version'], 'Version should be a string' );
72+
$this->assertIsString( $data['assetsPath'], 'AssetsPath should be a string' );
73+
$this->assertIsBool( $data['stylesExist'], 'StylesExist should be a boolean' );
74+
$this->assertIsBool( $data['hasPro'], 'HasPro should be a boolean' );
75+
$this->assertIsString( $data['upgradeLink'], 'UpgradeLink should be a string' );
76+
$this->assertIsString( $data['docsLink'], 'DocsLink should be a string' );
77+
$this->assertIsBool( $data['showFeedbackNotice'], 'ShowFeedbackNotice should be a boolean' );
78+
$this->assertIsArray( $data['deal'], 'Deal should be an array' );
79+
$this->assertIsBool( $data['hasOnboarding'], 'HasOnboarding should be a boolean' );
80+
$this->assertIsInt( $data['days_since_install'], 'DaysSinceInstall should be an integer' );
81+
$this->assertIsString( $data['rootUrl'], 'RootUrl should be a string' );
82+
$this->assertIsString( $data['neveThemePreviewUrl'], 'NeveThemePreviewUrl should be a string' );
83+
$this->assertIsString( $data['neveThemeActivationUrl'], 'NeveThemeActivationUrl should be a string' );
84+
$this->assertIsString( $data['neveDashboardUrl'], 'NeveDashboardUrl should be a string' );
85+
$this->assertIsBool( $data['neveInstalled'], 'NeveInstalled should be a boolean' );
86+
87+
// Test version matches constant
88+
$this->assertEquals( OTTER_BLOCKS_VERSION, $data['version'], 'Version should match OTTER_BLOCKS_VERSION constant' );
89+
90+
// Test assets path
91+
$this->assertStringContainsString( 'assets/', $data['assetsPath'], 'AssetsPath should contain "assets/" directory' );
92+
}
93+
94+
/**
95+
* Clean up test environment.
96+
*/
97+
public function tear_down() {
98+
parent::tear_down();
99+
}
100+
}

0 commit comments

Comments
 (0)