woocommerce/plugins/woocommerce-admin/tests/notes/class-wc-tests-customizing-...

132 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/**
* CustomizingProductCatalog note tests
*
* @package WooCommerce\Admin\Tests\Notes
*/
Make individual note classes internal (https://github.com/woocommerce/woocommerce-admin/pull/8398) * Moved `WooSubscriptionsNotes` * Moved `WooSubscriptionsNotes` deprecated * Moved `WooCommerceSubscriptions` * Moved `WooCommercePayments` * Fix `WooCommerceSubscriptions` * Fix `WooSubscriptionsNotes * Fix `WooCommercePayments` * Moved `WelcomeToWooCommerceForStoreUsers * Add use `Note` * Moved `UpdateStoreDetails` * Moved `UnsecuredReportFiles` * Moved `TrackingOptIn` * Moved `TestCheckout` * Moved `SetUpAdditionalPaymentTypes` * Moved `SellingOnlineCourses` * Moved `RealTimeOrderAlerts` * Moved `PersonalizeStore` * Moved `PerformanceOnMobile` * Moved `PaymentsRemindMeLater` * Moved `OrderMilestones` * Moved `OnlineClothingStore` * Moved `OnboardingPayments * Moved `NewSalesRecord` * Moved `NavigationNudge` * Moved `NavigationNudge` * Moved `MobileApp` * Moved `MigrateFromShopify` * Moved `MarketingJetpack` * Moved `ManageStoreActivityFromHomeScreen` * Moved `ManageOrdersOnTheGo` * Moved `MagentoMigration` * Moved `LaunchChecklist` * Moved `InstallJPAndWCSPlugins` * Moved `InsightFirstSale` * Moved `InsightFirstProductAndPayment` * Moved `GivingFeedbackNotes` * Moved `FirstProduct` * Moved `FirstDownlaodableProduct` * Moved `EUVATNumber` * Moved `EditProductsOnTheMove` * Moved `DeactivatePlugin` * Moved `CustomizingProductCatalog` * Moved `CustomizeStoreWithBlocks` * Moved `CouponPageMoved` * Moved `CompleteStoreDetails` * Moved `ChoosingTheme` * Moved `AddingAndManangingProducts` * Moved `AddFirstProduct` * Removed `OnboardingTraits` trait * Moved `EmailNotification` * Fixed notes * Add changelog * Fix lint error Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2022-03-08 13:55:27 +00:00
use \Automattic\WooCommerce\Internal\Admin\Notes\CustomizingProductCatalog;
use \Automattic\WooCommerce\Admin\Notes\Note;
/**
* Class WC_Tests_Marketing_Notes
*/
class WC_Tests_Customizing_Product_Catalog extends WC_Unit_Test_Case {
/**
* @var CustomizingProductCatalog
*/
private $instance;
/**
* setUp
*/
public function setUp() {
parent::setUp();
$this->empty_posts();
$this->instance = new CustomizingProductCatalog();
}
/**
* Empty wp_posts table
*/
private function empty_posts() {
global $wpdb;
$wpdb->query( "delete from {$wpdb->prefix}posts" );
}
/**
* Given 0 products
* When get_note() is called
* Then it should return null
*/
public function test_it_does_not_add_note_if_product_count_is_zero() {
// Given -- setUp() takes care of it.
// When.
$note = $this->instance->get_note();
// Then.
$this->assertNull( $note );
}
/**
* Given a fresh product
* When get_note() is called
* Then it should return null
*/
public function test_it_does_not_add_note_if_prouduct_is_less_than_a_day_old() {
// Given.
wp_insert_post(
array(
'post_title' => 'a product',
'post_type' => 'product',
'post_status' => 'publish',
'post_content' => '',
)
);
// When.
$note = $this->instance->get_note();
// Then.
$this->assertNull( $note );
}
/**
* Given a store that has been active for 14+ days
* When get_note() is called
* Then it should return null
*/
public function test_it_does_not_add_note_if_store_has_been_active_for_14_days_or_more() {
// Given.
update_option( 'woocommerce_admin_install_timestamp', time() - ( DAY_IN_SECONDS * 14 ) );
wp_insert_post(
array(
'post_title' => 'a product',
'post_type' => 'product',
'post_status' => 'publish',
'post_content' => '',
)
);
// When.
$note = $this->instance->get_note();
// Then.
$this->assertNull( $note );
}
/**
* Given a store that has been active for less than 14 days
* and a product that is older than day
*
* When get_note() is called
* Then it should return an instance of Note
*/
public function test_it_adds_note() {
// Given.
update_option( 'woocommerce_admin_install_timestamp', time() - ( DAY_IN_SECONDS * 13 ) );
$day_before = gmdate( 'Y-m-d H:i:s', time() - DAY_IN_SECONDS );
$product = new \WC_Product();
$product->set_props(
array(
'name' => 'test',
)
);
$product_id = $product->save();
wp_update_post(
array(
'ID' => $product_id,
'post_date' => $day_before,
'post_date_gmt' => get_gmt_from_date( $day_before ),
)
);
// When.
$note = $this->instance->get_note();
// Then.
$this->assertInstanceOf( Note::class, $note );
}
}