woocommerce/plugins/woocommerce-admin/tests/notes/class-wc-tests-marketing-no...

77 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* Marketing notes tests
*
* @package WooCommerce\Admin\Tests\Notes
*/
use \Automattic\WooCommerce\Admin\Notes\Notes;
use \Automattic\WooCommerce\Admin\Notes\Note;
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\WooCommercePayments;
/**
* Class WC_Tests_Marketing_Notes
*/
class WC_Tests_Marketing_Notes extends WC_Unit_Test_Case {
/**
* Tests that a marketing note can be added.
*/
public function test_add_remove_marketing_note() {
$data_store = Notes::load_data_store();
$note = new Note();
$note->set_title( 'PHPUNIT_TEST_MARKETING_NOTE' );
$note->set_content( 'PHPUNIT_TEST_MARKETING_NOTE_CONTENT' );
$note->set_type( Note::E_WC_ADMIN_NOTE_MARKETING );
$note->set_name( 'PHPUNIT_TEST_MARKETING_NOTE_NAME' );
$note->set_source( 'PHPUNIT_TEST' );
$note->set_is_snoozable( false );
$note->save();
// Load all marketing notes and check that the note was successfully saved.
$notes = $data_store->get_notes(
array(
'type' => array( Note::E_WC_ADMIN_NOTE_MARKETING ),
)
);
$this->assertEquals( 1, count( $notes ) );
// Opt out of WooCommerce marketing.
update_option( 'woocommerce_show_marketplace_suggestions', 'no' );
// Reload all marketing notes to verify they have been removed.
$notes = $data_store->get_notes(
array(
'type' => array( Note::E_WC_ADMIN_NOTE_MARKETING ),
)
);
$this->assertEquals( 0, count( $notes ) );
}
/**
* Tests to see if marketing notes are prevented when marketing is opted out.
*/
public function test_prevent_add_marketing_note() {
// Update settings so that note should be added.
update_option( 'woocommerce_default_country', 'US:GA' );
update_option( 'woocommerce_admin_install_timestamp', time() - WEEK_IN_SECONDS );
// Set user preferences to disallow marketing suggestions.
update_option( 'woocommerce_show_marketplace_suggestions', 'no' );
WooCommercePayments::possibly_add_note();
// Load all marketing notes and check that the note was not added.
$data_store = Notes::load_data_store();
$notes = $data_store->get_notes(
array(
'type' => array( Note::E_WC_ADMIN_NOTE_MARKETING ),
)
);
$this->assertEquals( 0, count( $notes ) );
}
}