diff --git a/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php b/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php index 8316d9ef11f8..d8f9ac793786 100644 --- a/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php +++ b/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php @@ -143,7 +143,7 @@ public function get_items( $request ) { public function prepare_item_for_response( $item, $request ) { $data = [ 'id' => $item->get_id(), - 'channel' => $item->get_channel()->get_slug(), + 'channel' => $item->get_type()->get_channel()->get_slug(), 'title' => $item->get_title(), 'manage_url' => $item->get_manage_url(), ]; diff --git a/plugins/woocommerce/src/Admin/Marketing/MarketingCampaign.php b/plugins/woocommerce/src/Admin/Marketing/MarketingCampaign.php index 45037fea367f..c85ced83f213 100644 --- a/plugins/woocommerce/src/Admin/Marketing/MarketingCampaign.php +++ b/plugins/woocommerce/src/Admin/Marketing/MarketingCampaign.php @@ -7,14 +7,12 @@ namespace Automattic\WooCommerce\Admin\Marketing; -use JsonSerializable; - /** * MarketingCampaign class * * @since x.x.x */ -class MarketingCampaign implements JsonSerializable { +class MarketingCampaign { /** * The unique identifier. * @@ -23,11 +21,11 @@ class MarketingCampaign implements JsonSerializable { protected $id; /** - * The marketing channel that this campaign belongs to. + * The marketing campaign type. * - * @var MarketingChannelInterface + * @var MarketingCampaignType */ - protected $channel; + protected $type; /** * Title of the marketing campaign. @@ -53,15 +51,15 @@ class MarketingCampaign implements JsonSerializable { /** * MarketingCampaign constructor. * - * @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 $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 string $id The marketing campaign's unique identifier. + * @param MarketingCampaignType $type The marketing campaign type. + * @param string $title The title of the marketing campaign. + * @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. */ - public function __construct( string $id, MarketingChannelInterface $channel, string $title, string $manage_url, Price $cost = null ) { + public function __construct( string $id, MarketingCampaignType $type, string $title, string $manage_url, Price $cost = null ) { $this->id = $id; - $this->channel = $channel; + $this->type = $type; $this->title = $title; $this->manage_url = $manage_url; $this->cost = $cost; @@ -77,12 +75,12 @@ public function get_id(): string { } /** - * Returns the marketing channel that this campaign belongs to. + * Returns the marketing campaign type. * - * @return MarketingChannelInterface + * @return MarketingCampaignType */ - public function get_channel(): MarketingChannelInterface { - return $this->channel; + public function get_type(): MarketingCampaignType { + return $this->type; } /** @@ -111,19 +109,4 @@ public function get_manage_url(): string { public function get_cost(): ?Price { return $this->cost; } - - /** - * Serialize the marketing campaign data. - * - * @return array - */ - public function jsonSerialize() { - return [ - 'id' => $this->get_id(), - 'channel' => $this->get_channel()->get_slug(), - 'title' => $this->get_title(), - 'manage_url' => $this->get_manage_url(), - 'cost' => $this->get_cost(), - ]; - } } diff --git a/plugins/woocommerce/tests/php/src/Admin/Marketing/MarketingCampaignTest.php b/plugins/woocommerce/tests/php/src/Admin/Marketing/MarketingCampaignTest.php index 30d8c243ba57..4277cff9437f 100644 --- a/plugins/woocommerce/tests/php/src/Admin/Marketing/MarketingCampaignTest.php +++ b/plugins/woocommerce/tests/php/src/Admin/Marketing/MarketingCampaignTest.php @@ -3,7 +3,7 @@ namespace Automattic\WooCommerce\Tests\Admin\Marketing; use Automattic\WooCommerce\Admin\Marketing\MarketingCampaign; -use Automattic\WooCommerce\Admin\Marketing\MarketingChannelInterface; +use Automattic\WooCommerce\Admin\Marketing\MarketingCampaignType; use Automattic\WooCommerce\Admin\Marketing\Price; use WC_Unit_Test_Case; @@ -13,15 +13,15 @@ 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_type`, `get_title`, `get_manage_url`, and `get_cost` return the class properties set by the constructor. */ public function test_get_methods_return_properties() { - $test_channel_1 = $this->createMock( MarketingChannelInterface::class ); - $test_channel_1->expects( $this->any() )->method( 'get_slug' )->willReturn( 'test-channel-1' ); + $test_campaign_type_1 = $this->createMock( MarketingCampaignType::class ); - $marketing_campaign = new MarketingCampaign( '1234', $test_channel_1, 'Ad #1234', 'https://example.com/manage-campaigns', new Price( '1000', 'USD' ) ); + $marketing_campaign = new MarketingCampaign( '1234', $test_campaign_type_1, 'Ad #1234', 'https://example.com/manage-campaigns', new Price( '1000', 'USD' ) ); $this->assertEquals( '1234', $marketing_campaign->get_id() ); + $this->assertEquals( $test_campaign_type_1, $marketing_campaign->get_type() ); $this->assertEquals( 'Ad #1234', $marketing_campaign->get_title() ); $this->assertEquals( 'https://example.com/manage-campaigns', $marketing_campaign->get_manage_url() ); $this->assertNotNull( $marketing_campaign->get_cost() ); @@ -33,36 +33,10 @@ public function test_get_methods_return_properties() { * @testdox `cost` property can be null. */ public function test_cost_can_be_null() { - $test_channel_1 = $this->createMock( MarketingChannelInterface::class ); + $test_campaign_type_1 = $this->createMock( MarketingCampaignType::class ); - $marketing_campaign = new MarketingCampaign( '1234', $test_channel_1, 'Ad #1234', 'https://example.com/manage-campaigns' ); + $marketing_campaign = new MarketingCampaign( '1234', $test_campaign_type_1, 'Ad #1234', 'https://example.com/manage-campaigns' ); $this->assertNull( $marketing_campaign->get_cost() ); } - - /** - * @testdox It can be serialized to JSON including all its properties. - */ - public function test_can_be_serialized_to_json() { - $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 ); - $this->assertNotEmpty( $json ); - $this->assertEqualSets( - [ - 'id' => $marketing_campaign->get_id(), - 'channel' => 'test-channel-1', - 'title' => $marketing_campaign->get_title(), - 'manage_url' => $marketing_campaign->get_manage_url(), - 'cost' => [ - 'value' => $marketing_campaign->get_cost()->get_value(), - 'currency' => $marketing_campaign->get_cost()->get_currency(), - ], - ], - json_decode( $json, true ) - ); - } }