2020-05-22 13:48:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Marketing notes tests
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin\Tests\Notes
|
2020-05-22 13:48:40 +00:00
|
|
|
*/
|
|
|
|
|
2020-09-28 04:35:10 +00:00
|
|
|
use \Automattic\WooCommerce\Admin\Notes\Notes;
|
|
|
|
use \Automattic\WooCommerce\Admin\Notes\Note;
|
2020-10-28 17:12:14 +00:00
|
|
|
use \Automattic\WooCommerce\Admin\Notes\WooCommercePayments;
|
2020-05-22 13:48:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2021-04-26 21:57:39 +00:00
|
|
|
$data_store = Notes::load_data_store();
|
2020-05-22 13:48:40 +00:00
|
|
|
|
2020-09-28 04:35:10 +00:00
|
|
|
$note = new Note();
|
2020-05-22 13:48:40 +00:00
|
|
|
$note->set_title( 'PHPUNIT_TEST_MARKETING_NOTE' );
|
|
|
|
$note->set_content( 'PHPUNIT_TEST_MARKETING_NOTE_CONTENT' );
|
2020-09-28 04:35:10 +00:00
|
|
|
$note->set_type( Note::E_WC_ADMIN_NOTE_MARKETING );
|
2020-05-22 13:48:40 +00:00
|
|
|
$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(
|
2020-09-28 04:35:10 +00:00
|
|
|
'type' => array( Note::E_WC_ADMIN_NOTE_MARKETING ),
|
2020-05-22 13:48:40 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$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(
|
2020-09-28 04:35:10 +00:00
|
|
|
'type' => array( Note::E_WC_ADMIN_NOTE_MARKETING ),
|
2020-05-22 13:48:40 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$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' );
|
|
|
|
|
2020-10-28 17:12:14 +00:00
|
|
|
WooCommercePayments::possibly_add_note();
|
2020-05-22 13:48:40 +00:00
|
|
|
|
|
|
|
// Load all marketing notes and check that the note was not added.
|
2021-04-26 21:57:39 +00:00
|
|
|
$data_store = Notes::load_data_store();
|
2020-05-22 13:48:40 +00:00
|
|
|
$notes = $data_store->get_notes(
|
|
|
|
array(
|
2020-09-28 04:35:10 +00:00
|
|
|
'type' => array( Note::E_WC_ADMIN_NOTE_MARKETING ),
|
2020-05-22 13:48:40 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( 0, count( $notes ) );
|
|
|
|
}
|
|
|
|
}
|