woocommerce/unit-tests/AbstractReportsTest.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2019-06-10 12:39:46 +00:00
<?php
/**
* Abstract for reports tests - these tests can only run if WC Admin exists.
*/
namespace WooCommerce\RestApi\UnitTests;
defined( 'ABSPATH' ) || exit;
use \WooCommerce\RestApi\UnitTests\Bootstrap;
use \WC_REST_Unit_Test_Case;
/**
* Class AbstractReportsTest.
*/
abstract class AbstractReportsTest extends WC_REST_Unit_Test_Case {
/**
2019-06-10 14:08:29 +00:00
* User variable.
*
* @var WP_User
2019-06-10 12:39:46 +00:00
*/
2019-06-10 14:08:29 +00:00
protected static $user;
2019-06-10 12:39:46 +00:00
2019-06-10 14:08:29 +00:00
/**
* Setup once before running tests.
*
* @param object $factory Factory object.
*/
public static function wpSetUpBeforeClass( $factory ) {
self::$user = $factory->user->create(
2019-06-10 12:39:46 +00:00
array(
'role' => 'administrator',
)
);
2019-06-10 14:08:29 +00:00
}
2019-06-10 12:39:46 +00:00
2019-06-10 14:08:29 +00:00
/**
* Setup test reports categories data.
*/
public function setUp() {
if ( ! class_exists( '\WC_Admin_Reports_Sync' ) ) {
$this->markTestSkipped( 'Skipping reports tests - WC_Admin_Reports_Sync class not found.' );
return;
}
parent::setUp();
wp_set_current_user( self::$user );
2019-06-10 12:39:46 +00:00
global $wpdb;
2019-06-10 14:08:29 +00:00
$wpdb->query( "DELETE FROM $wpdb->prefix" . \WC_Admin_Reports_Orders_Stats_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . \WC_Admin_Reports_Products_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . \WC_Admin_Reports_Coupons_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . \WC_Admin_Reports_Customers_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
2019-06-10 12:39:46 +00:00
}
}