|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SkyVerge\WooCommerce\PluginFramework\v5_15_4\Tests\unit\Helpers; |
| 4 | + |
| 5 | +use Generator; |
| 6 | +use Mockery; |
| 7 | +use SkyVerge\WooCommerce\PluginFramework\v5_15_4\Helpers\PageHelper; |
| 8 | +use SkyVerge\WooCommerce\PluginFramework\v5_15_4\Tests\TestCase; |
| 9 | + |
| 10 | +/** |
| 11 | + * @coversDefaultClass \SkyVerge\WooCommerce\PluginFramework\v5_15_4\Helpers\PageHelper |
| 12 | + */ |
| 13 | +final class PageHelperTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @covers ::isWooCommerceAnalyticsPage() |
| 17 | + * @dataProvider providerCanDetermineIsWooCommerceAnalyticsPage |
| 18 | + * @throws \ReflectionException |
| 19 | + */ |
| 20 | + public function testCanDetermineIsWooCommerceAnalyticsPage($pageData, bool $expected) : void |
| 21 | + { |
| 22 | + $pageController = Mockery::mock(\Automattic\WooCommerce\Admin\PageController::class); |
| 23 | + $pageController->expects('get_current_page') |
| 24 | + ->once() |
| 25 | + ->andReturn($pageData); |
| 26 | + |
| 27 | + $this->mockStaticMethod(PageHelper::class, 'getWooCommercePageController') |
| 28 | + ->once() |
| 29 | + ->andReturn($pageController); |
| 30 | + |
| 31 | + $this->assertSame($expected, PageHelper::isWooCommerceAnalyticsPage()); |
| 32 | + } |
| 33 | + |
| 34 | + /** @see testCanDetermineIsWooCommerceAnalyticsPage */ |
| 35 | + public function providerCanDetermineIsWooCommerceAnalyticsPage() : Generator |
| 36 | + { |
| 37 | + yield 'no page data' => [ |
| 38 | + 'pageData' => false, |
| 39 | + 'expected' => false, |
| 40 | + ]; |
| 41 | + |
| 42 | + yield 'woocommerce home' => [ |
| 43 | + 'pageData' => [ |
| 44 | + 'id' => 'woocommerce-home', |
| 45 | + 'parent' => 'woocommerce', |
| 46 | + ], |
| 47 | + 'expected' => false, |
| 48 | + ]; |
| 49 | + |
| 50 | + yield 'orders page' => [ |
| 51 | + 'pageData' => [ |
| 52 | + 'id' => 'woocommerce-custom-orders', |
| 53 | + ], |
| 54 | + 'expected' => false, |
| 55 | + ]; |
| 56 | + |
| 57 | + yield 'analytics overview' => [ |
| 58 | + 'pageData' => [ |
| 59 | + 'id' => 'woocommerce-analytics', |
| 60 | + 'parent' => null, |
| 61 | + ], |
| 62 | + 'expected' => true, |
| 63 | + ]; |
| 64 | + |
| 65 | + yield 'analytics revenue' => [ |
| 66 | + 'pageData' => [ |
| 67 | + 'id' => 'woocommerce-analytics-revenue', |
| 68 | + 'parent' => 'woocommerce-analytics', |
| 69 | + ], |
| 70 | + 'expected' => true, |
| 71 | + ]; |
| 72 | + |
| 73 | + yield 'analytics products' => [ |
| 74 | + 'pageData' => [ |
| 75 | + 'id' => 'woocommerce-analytics-products', |
| 76 | + 'parent' => 'woocommerce-analytics', |
| 77 | + ], |
| 78 | + 'expected' => true, |
| 79 | + ]; |
| 80 | + } |
| 81 | +} |
0 commit comments