woocommerce/tests/unit-tests/util/install.php

114 lines
3.4 KiB
PHP
Raw Normal View History

<?php
2015-03-06 15:32:40 +00:00
/**
2015-11-03 13:31:20 +00:00
* Class WC_Tests_Install.
2015-03-06 15:32:40 +00:00
* @package WooCommerce\Tests\Util
*/
class WC_Tests_Install extends WC_Unit_Test_Case {
/**
2015-11-03 13:31:20 +00:00
* Test check version.
*/
public function test_check_version() {
2017-01-04 18:45:45 +00:00
update_option( 'woocommerce_version', ( (float) WC()->version - 1 ) );
WC_Install::check_version();
$this->assertTrue( did_action( 'woocommerce_updated' ) === 1 );
update_option( 'woocommerce_version', WC()->version );
WC_Install::check_version();
$this->assertTrue( did_action( 'woocommerce_updated' ) === 1 );
update_option( 'woocommerce_version', (float) WC()->version + 1 );
WC_Install::check_version();
$this->assertTrue(
did_action( 'woocommerce_updated' ) === 1,
'WC_Install::check_version() should not call install routine when the WC version stored in the database is bigger than the version in the code as downgrades are not supported.'
);
}
/**
2015-11-03 13:31:20 +00:00
* Test - install.
*/
public function test_install() {
2017-10-05 17:11:25 +00:00
// clean existing install first.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
define( 'WP_UNINSTALL_PLUGIN', true );
2016-08-24 16:34:13 +00:00
define( 'WC_REMOVE_ALL_DATA', true );
}
2016-01-08 14:53:24 +00:00
include dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php';
2017-10-05 17:11:25 +00:00
delete_transient( 'wc_installing' );
WC_Install::install();
$this->assertEquals( WC()->version, get_option( 'woocommerce_version' ) );
}
/**
2015-11-03 13:31:20 +00:00
* Test - create pages.
*/
public function test_create_pages() {
// Clear options
delete_option( 'woocommerce_shop_page_id' );
delete_option( 'woocommerce_cart_page_id' );
delete_option( 'woocommerce_checkout_page_id' );
delete_option( 'woocommerce_myaccount_page_id' );
WC_Install::create_pages();
$this->assertGreaterThan( 0, get_option( 'woocommerce_shop_page_id' ) );
$this->assertGreaterThan( 0, get_option( 'woocommerce_cart_page_id' ) );
$this->assertGreaterThan( 0, get_option( 'woocommerce_checkout_page_id' ) );
$this->assertGreaterThan( 0, get_option( 'woocommerce_myaccount_page_id' ) );
// Delete pages
wp_delete_post( get_option( 'woocommerce_shop_page_id' ), true );
wp_delete_post( get_option( 'woocommerce_cart_page_id' ), true );
wp_delete_post( get_option( 'woocommerce_checkout_page_id' ), true );
wp_delete_post( get_option( 'woocommerce_myaccount_page_id' ), true );
// Clear options
delete_option( 'woocommerce_shop_page_id' );
delete_option( 'woocommerce_cart_page_id' );
delete_option( 'woocommerce_checkout_page_id' );
delete_option( 'woocommerce_myaccount_page_id' );
WC_Install::create_pages();
$this->assertGreaterThan( 0, get_option( 'woocommerce_shop_page_id' ) );
$this->assertGreaterThan( 0, get_option( 'woocommerce_cart_page_id' ) );
$this->assertGreaterThan( 0, get_option( 'woocommerce_checkout_page_id' ) );
$this->assertGreaterThan( 0, get_option( 'woocommerce_myaccount_page_id' ) );
}
/**
2015-11-03 13:31:20 +00:00
* Test - create roles.
*/
public function test_create_roles() {
2015-02-03 16:22:58 +00:00
// Clean existing install first
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
define( 'WP_UNINSTALL_PLUGIN', true );
2016-08-24 16:34:13 +00:00
define( 'WC_REMOVE_ALL_DATA', true );
}
include dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php';
WC_Install::create_roles();
$this->assertNotNull( get_role( 'customer' ) );
$this->assertNotNull( get_role( 'shop_manager' ) );
}
/**
2015-11-03 13:31:20 +00:00
* Test - remove roles.
*/
public function test_remove_roles() {
WC_Install::remove_roles();
$this->assertNull( get_role( 'customer' ) );
$this->assertNull( get_role( 'shop_manager' ) );
}
}