Add channel property to MarketingCampaign
This commit is contained in:
parent
53dac1d8e3
commit
6415f3f911
|
@ -22,6 +22,13 @@ class MarketingCampaign implements JsonSerializable {
|
||||||
*/
|
*/
|
||||||
protected $id;
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The marketing channel that this campaign belongs to.
|
||||||
|
*
|
||||||
|
* @var MarketingChannelInterface
|
||||||
|
*/
|
||||||
|
protected $channel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of the marketing campaign.
|
* Title of the marketing campaign.
|
||||||
*
|
*
|
||||||
|
@ -47,12 +54,14 @@ class MarketingCampaign implements JsonSerializable {
|
||||||
* MarketingCampaign constructor.
|
* MarketingCampaign constructor.
|
||||||
*
|
*
|
||||||
* @param string $id The marketing campaign's unique identifier.
|
* @param string $id The marketing campaign's unique identifier.
|
||||||
|
* @param MarketingChannelInterface $channel The marketing channel that this campaign belongs to.
|
||||||
* @param string $title The title of the marketing campaign.
|
* @param string $title The title of the marketing campaign.
|
||||||
* @param string $manage_url The URL to the channel's campaign management page.
|
* @param string $manage_url The URL to the channel's campaign management page.
|
||||||
* @param Price|null $cost The cost of the marketing campaign with the currency.
|
* @param Price|null $cost The cost of the marketing campaign with the currency.
|
||||||
*/
|
*/
|
||||||
public function __construct( string $id, string $title, string $manage_url, Price $cost = null ) {
|
public function __construct( string $id, MarketingChannelInterface $channel, string $title, string $manage_url, Price $cost = null ) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
$this->channel = $channel;
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
$this->manage_url = $manage_url;
|
$this->manage_url = $manage_url;
|
||||||
$this->cost = $cost;
|
$this->cost = $cost;
|
||||||
|
@ -67,6 +76,15 @@ class MarketingCampaign implements JsonSerializable {
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the marketing channel that this campaign belongs to.
|
||||||
|
*
|
||||||
|
* @return MarketingChannelInterface
|
||||||
|
*/
|
||||||
|
public function get_channel(): MarketingChannelInterface {
|
||||||
|
return $this->channel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the title of the marketing campaign.
|
* Returns the title of the marketing campaign.
|
||||||
*
|
*
|
||||||
|
@ -102,6 +120,7 @@ class MarketingCampaign implements JsonSerializable {
|
||||||
public function jsonSerialize() {
|
public function jsonSerialize() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->get_id(),
|
'id' => $this->get_id(),
|
||||||
|
'channel' => $this->get_channel()->get_slug(),
|
||||||
'title' => $this->get_title(),
|
'title' => $this->get_title(),
|
||||||
'manage_url' => $this->get_manage_url(),
|
'manage_url' => $this->get_manage_url(),
|
||||||
'cost' => $this->get_cost(),
|
'cost' => $this->get_cost(),
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Automattic\WooCommerce\Tests\Admin\Marketing;
|
namespace Automattic\WooCommerce\Tests\Admin\Marketing;
|
||||||
|
|
||||||
use Automattic\WooCommerce\Admin\Marketing\MarketingCampaign;
|
use Automattic\WooCommerce\Admin\Marketing\MarketingCampaign;
|
||||||
|
use Automattic\WooCommerce\Admin\Marketing\MarketingChannelInterface;
|
||||||
use Automattic\WooCommerce\Admin\Marketing\Price;
|
use Automattic\WooCommerce\Admin\Marketing\Price;
|
||||||
use WC_Unit_Test_Case;
|
use WC_Unit_Test_Case;
|
||||||
|
|
||||||
|
@ -15,7 +16,10 @@ class MarketingCampaignTest extends WC_Unit_Test_Case {
|
||||||
* @testdox `get_id`, `get_title`, `get_manage_url`, and `get_cost` return the class properties set by the constructor.
|
* @testdox `get_id`, `get_title`, `get_manage_url`, and `get_cost` return the class properties set by the constructor.
|
||||||
*/
|
*/
|
||||||
public function test_get_methods_return_properties() {
|
public function test_get_methods_return_properties() {
|
||||||
$marketing_campaign = new MarketingCampaign( '1234', 'Ad #1234', 'https://example.com/manage-campaigns', new Price( '1000', 'USD' ) );
|
$test_channel_1 = $this->createMock( MarketingChannelInterface::class );
|
||||||
|
$test_channel_1->expects( $this->any() )->method( 'get_slug' )->willReturn( 'test-channel-1' );
|
||||||
|
|
||||||
|
$marketing_campaign = new MarketingCampaign( '1234', $test_channel_1, 'Ad #1234', 'https://example.com/manage-campaigns', new Price( '1000', 'USD' ) );
|
||||||
|
|
||||||
$this->assertEquals( '1234', $marketing_campaign->get_id() );
|
$this->assertEquals( '1234', $marketing_campaign->get_id() );
|
||||||
$this->assertEquals( 'Ad #1234', $marketing_campaign->get_title() );
|
$this->assertEquals( 'Ad #1234', $marketing_campaign->get_title() );
|
||||||
|
@ -29,7 +33,9 @@ class MarketingCampaignTest extends WC_Unit_Test_Case {
|
||||||
* @testdox `cost` property can be null.
|
* @testdox `cost` property can be null.
|
||||||
*/
|
*/
|
||||||
public function test_cost_can_be_null() {
|
public function test_cost_can_be_null() {
|
||||||
$marketing_campaign = new MarketingCampaign( '1234', 'Ad #1234', 'https://example.com/manage-campaigns' );
|
$test_channel_1 = $this->createMock( MarketingChannelInterface::class );
|
||||||
|
|
||||||
|
$marketing_campaign = new MarketingCampaign( '1234', $test_channel_1, 'Ad #1234', 'https://example.com/manage-campaigns' );
|
||||||
|
|
||||||
$this->assertNull( $marketing_campaign->get_cost() );
|
$this->assertNull( $marketing_campaign->get_cost() );
|
||||||
}
|
}
|
||||||
|
@ -38,13 +44,17 @@ class MarketingCampaignTest extends WC_Unit_Test_Case {
|
||||||
* @testdox It can be serialized to JSON including all its properties.
|
* @testdox It can be serialized to JSON including all its properties.
|
||||||
*/
|
*/
|
||||||
public function test_can_be_serialized_to_json() {
|
public function test_can_be_serialized_to_json() {
|
||||||
$marketing_campaign = new MarketingCampaign( '1234', 'Ad #1234', 'https://example.com/manage-campaigns', new Price( '1000', 'USD' ) );
|
$test_channel_1 = $this->createMock( MarketingChannelInterface::class );
|
||||||
|
$test_channel_1->expects( $this->any() )->method( 'get_slug' )->willReturn( 'test-channel-1' );
|
||||||
|
|
||||||
|
$marketing_campaign = new MarketingCampaign( '1234', $test_channel_1, 'Ad #1234', 'https://example.com/manage-campaigns', new Price( '1000', 'USD' ) );
|
||||||
|
|
||||||
$json = wp_json_encode( $marketing_campaign );
|
$json = wp_json_encode( $marketing_campaign );
|
||||||
$this->assertNotEmpty( $json );
|
$this->assertNotEmpty( $json );
|
||||||
$this->assertEqualSets(
|
$this->assertEqualSets(
|
||||||
[
|
[
|
||||||
'id' => $marketing_campaign->get_id(),
|
'id' => $marketing_campaign->get_id(),
|
||||||
|
'channel' => 'test-channel-1',
|
||||||
'title' => $marketing_campaign->get_title(),
|
'title' => $marketing_campaign->get_title(),
|
||||||
'manage_url' => $marketing_campaign->get_manage_url(),
|
'manage_url' => $marketing_campaign->get_manage_url(),
|
||||||
'cost' => [
|
'cost' => [
|
||||||
|
|
Loading…
Reference in New Issue