|
| 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