From c80f0c301f3f61204944571b535cdd77bc76e1b7 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 08:52:38 +0000 Subject: [PATCH 01/13] Bump Google Ads classes to V18 --- bin/GoogleAdsCleanupServices.php | 2 +- src/API/Google/Ads.php | 12 +-- src/API/Google/AdsAsset.php | 20 ++-- src/API/Google/AdsAssetGroup.php | 24 ++--- src/API/Google/AdsAssetGroupAsset.php | 12 +-- src/API/Google/AdsCampaign.php | 20 ++-- src/API/Google/AdsCampaignBudget.php | 10 +- src/API/Google/AdsCampaignCriterion.php | 12 +-- src/API/Google/AdsCampaignLabel.php | 14 +-- src/API/Google/AdsConversionAction.php | 26 ++--- src/API/Google/AdsReport.php | 4 +- src/API/Google/AssetFieldType.php | 4 +- src/API/Google/BillingSetupStatus.php | 4 +- src/API/Google/CallToActionType.php | 4 +- src/API/Google/CampaignStatus.php | 4 +- src/API/Google/CampaignType.php | 4 +- src/API/Google/ExceptionTrait.php | 6 +- src/API/Google/MerchantMetrics.php | 2 +- src/API/Google/Query/AdsQuery.php | 6 +- src/API/Google/Query/AdsReportQuery.php | 2 +- .../Controllers/Ads/AssetGroupController.php | 2 +- src/Google/Ads/GoogleAdsClient.php | 2 +- src/Google/Ads/ServiceClientFactoryTrait.php | 38 ++++---- .../GoogleServiceProvider.php | 2 +- .../HelperTrait/GoogleAdsClientTrait.php | 94 +++++++++---------- .../API/Google/AdsAssetGroupAssetTest.php | 4 +- tests/Unit/API/Google/AdsAssetGroupTest.php | 6 +- tests/Unit/API/Google/AdsAssetTest.php | 2 +- .../API/Google/AdsCampaignCriterionTest.php | 2 +- .../API/Google/AdsConversionActionTest.php | 2 +- tests/Unit/API/Google/AdsTest.php | 8 +- tests/Unit/API/Google/MerchantMetricsTest.php | 6 +- 32 files changed, 179 insertions(+), 181 deletions(-) diff --git a/bin/GoogleAdsCleanupServices.php b/bin/GoogleAdsCleanupServices.php index 4a047f3c08..19a91a74d0 100644 --- a/bin/GoogleAdsCleanupServices.php +++ b/bin/GoogleAdsCleanupServices.php @@ -26,7 +26,7 @@ class GoogleAdsCleanupServices { * * @var string */ - protected $version = 'V16'; + protected $version = 'V18'; /** * @var Event Composer event. diff --git a/src/API/Google/Ads.php b/src/API/Google/Ads.php index 82a671ac73..32bcdb60de 100644 --- a/src/API/Google/Ads.php +++ b/src/API/Google/Ads.php @@ -13,12 +13,12 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface; use Exception; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Enums\AccessRoleEnum\AccessRole; -use Google\Ads\GoogleAds\V16\Enums\ProductLinkInvitationStatusEnum\ProductLinkInvitationStatus; -use Google\Ads\GoogleAds\V16\Resources\ProductLinkInvitation; -use Google\Ads\GoogleAds\V16\Services\ListAccessibleCustomersRequest; -use Google\Ads\GoogleAds\V16\Services\UpdateProductLinkInvitationRequest; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Enums\AccessRoleEnum\AccessRole; +use Google\Ads\GoogleAds\V18\Enums\ProductLinkInvitationStatusEnum\ProductLinkInvitationStatus; +use Google\Ads\GoogleAds\V18\Resources\ProductLinkInvitation; +use Google\Ads\GoogleAds\V18\Services\ListAccessibleCustomersRequest; +use Google\Ads\GoogleAds\V18\Services\UpdateProductLinkInvitationRequest; use Google\ApiCore\ApiException; use Google\ApiCore\ValidationException; diff --git a/src/API/Google/AdsAsset.php b/src/API/Google/AdsAsset.php index 116ed0b6e8..e146c61960 100644 --- a/src/API/Google/AdsAsset.php +++ b/src/API/Google/AdsAsset.php @@ -6,16 +6,16 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Enums\AssetTypeEnum\AssetType; -use Google\Ads\GoogleAds\V16\Resources\Asset; -use Google\Ads\GoogleAds\V16\Services\AssetOperation; -use Google\Ads\GoogleAds\V16\Services\MutateGoogleAdsRequest; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Common\TextAsset; -use Google\Ads\GoogleAds\V16\Common\ImageAsset; -use Google\Ads\GoogleAds\V16\Common\CallToActionAsset; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Enums\AssetTypeEnum\AssetType; +use Google\Ads\GoogleAds\V18\Resources\Asset; +use Google\Ads\GoogleAds\V18\Services\AssetOperation; +use Google\Ads\GoogleAds\V18\Services\MutateGoogleAdsRequest; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Common\TextAsset; +use Google\Ads\GoogleAds\V18\Common\ImageAsset; +use Google\Ads\GoogleAds\V18\Common\CallToActionAsset; use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\WP; use Google\ApiCore\ApiException; use Exception; diff --git a/src/API/Google/AdsAssetGroup.php b/src/API/Google/AdsAssetGroup.php index e3c0d9e31e..39cec9c0c9 100644 --- a/src/API/Google/AdsAssetGroup.php +++ b/src/API/Google/AdsAssetGroup.php @@ -7,18 +7,18 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Enums\ListingGroupFilterListingSourceEnum\ListingGroupFilterListingSource; -use Google\Ads\GoogleAds\V16\Enums\AssetGroupStatusEnum\AssetGroupStatus; -use Google\Ads\GoogleAds\V16\Enums\ListingGroupFilterTypeEnum\ListingGroupFilterType; -use Google\Ads\GoogleAds\V16\Resources\AssetGroup; -use Google\Ads\GoogleAds\V16\Resources\AssetGroupListingGroupFilter; -use Google\Ads\GoogleAds\V16\Services\AssetGroupListingGroupFilterOperation; -use Google\Ads\GoogleAds\V16\Services\AssetGroupOperation; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Services\MutateGoogleAdsRequest; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; -use Google\Ads\GoogleAds\V16\Services\Client\AssetGroupServiceClient; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Enums\ListingGroupFilterListingSourceEnum\ListingGroupFilterListingSource; +use Google\Ads\GoogleAds\V18\Enums\AssetGroupStatusEnum\AssetGroupStatus; +use Google\Ads\GoogleAds\V18\Enums\ListingGroupFilterTypeEnum\ListingGroupFilterType; +use Google\Ads\GoogleAds\V18\Resources\AssetGroup; +use Google\Ads\GoogleAds\V18\Resources\AssetGroupListingGroupFilter; +use Google\Ads\GoogleAds\V18\Services\AssetGroupListingGroupFilterOperation; +use Google\Ads\GoogleAds\V18\Services\AssetGroupOperation; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Services\MutateGoogleAdsRequest; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; +use Google\Ads\GoogleAds\V18\Services\Client\AssetGroupServiceClient; use Google\ApiCore\ApiException; use Google\ApiCore\ValidationException; use Google\Protobuf\FieldMask; diff --git a/src/API/Google/AdsAssetGroupAsset.php b/src/API/Google/AdsAssetGroupAsset.php index 0136c797de..2cf80dd2c9 100644 --- a/src/API/Google/AdsAssetGroupAsset.php +++ b/src/API/Google/AdsAssetGroupAsset.php @@ -7,13 +7,13 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Resources\AssetGroupAsset; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Resources\AssetGroupAsset; use Google\ApiCore\ApiException; use Automattic\WooCommerce\GoogleListingsAndAds\Exception\ExceptionWithResponseData; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; -use Google\Ads\GoogleAds\V16\Services\AssetGroupAssetOperation; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; +use Google\Ads\GoogleAds\V18\Services\AssetGroupAssetOperation; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; @@ -22,7 +22,7 @@ * Class AdsAssetGroupAsset * * Use to get assets group assets for specific asset groups. - * https://developers.google.com/google-ads/api/fields/V16/asset_group_asset + * https://developers.google.com/google-ads/api/reference/rpc/v18/AssetGroupAsset * * @since 2.4.0 * diff --git a/src/API/Google/AdsCampaign.php b/src/API/Google/AdsCampaign.php index da7e718585..4aec3609d6 100644 --- a/src/API/Google/AdsCampaign.php +++ b/src/API/Google/AdsCampaign.php @@ -17,16 +17,16 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Options\TransientsInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\WC; use Google\Ads\GoogleAds\Util\FieldMasks; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Common\MaximizeConversionValue; -use Google\Ads\GoogleAds\V16\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType; -use Google\Ads\GoogleAds\V16\Resources\Campaign; -use Google\Ads\GoogleAds\V16\Resources\Campaign\ShoppingSetting; -use Google\Ads\GoogleAds\V16\Services\Client\CampaignServiceClient; -use Google\Ads\GoogleAds\V16\Services\CampaignOperation; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Services\MutateGoogleAdsRequest; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Common\MaximizeConversionValue; +use Google\Ads\GoogleAds\V18\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType; +use Google\Ads\GoogleAds\V18\Resources\Campaign; +use Google\Ads\GoogleAds\V18\Resources\Campaign\ShoppingSetting; +use Google\Ads\GoogleAds\V18\Services\Client\CampaignServiceClient; +use Google\Ads\GoogleAds\V18\Services\CampaignOperation; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Services\MutateGoogleAdsRequest; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; use Google\ApiCore\ApiException; use Google\ApiCore\ValidationException; use Exception; diff --git a/src/API/Google/AdsCampaignBudget.php b/src/API/Google/AdsCampaignBudget.php index d6bfc0fb7b..517539b914 100644 --- a/src/API/Google/AdsCampaignBudget.php +++ b/src/API/Google/AdsCampaignBudget.php @@ -9,11 +9,11 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; use Google\Ads\GoogleAds\Util\FieldMasks; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Resources\CampaignBudget; -use Google\Ads\GoogleAds\V16\Services\CampaignBudgetOperation; -use Google\Ads\GoogleAds\V16\Services\Client\CampaignBudgetServiceClient; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Resources\CampaignBudget; +use Google\Ads\GoogleAds\V18\Services\CampaignBudgetOperation; +use Google\Ads\GoogleAds\V18\Services\Client\CampaignBudgetServiceClient; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; use Google\ApiCore\ValidationException; use Exception; diff --git a/src/API/Google/AdsCampaignCriterion.php b/src/API/Google/AdsCampaignCriterion.php index 0cd93be9a8..ea299c64e4 100644 --- a/src/API/Google/AdsCampaignCriterion.php +++ b/src/API/Google/AdsCampaignCriterion.php @@ -3,12 +3,12 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Common\LocationInfo; -use Google\Ads\GoogleAds\V16\Enums\CampaignCriterionStatusEnum\CampaignCriterionStatus; -use Google\Ads\GoogleAds\V16\Resources\CampaignCriterion; -use Google\Ads\GoogleAds\V16\Services\CampaignCriterionOperation; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Common\LocationInfo; +use Google\Ads\GoogleAds\V18\Enums\CampaignCriterionStatusEnum\CampaignCriterionStatus; +use Google\Ads\GoogleAds\V18\Resources\CampaignCriterion; +use Google\Ads\GoogleAds\V18\Services\CampaignCriterionOperation; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; /** * Class AdsCampaignCriterion diff --git a/src/API/Google/AdsCampaignLabel.php b/src/API/Google/AdsCampaignLabel.php index c7ac7ed675..3cbee653ca 100644 --- a/src/API/Google/AdsCampaignLabel.php +++ b/src/API/Google/AdsCampaignLabel.php @@ -7,13 +7,13 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Resources\Label; -use Google\Ads\GoogleAds\V16\Resources\CampaignLabel; -use Google\Ads\GoogleAds\V16\Services\LabelOperation; -use Google\Ads\GoogleAds\V16\Services\CampaignLabelOperation; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; -use Google\Ads\GoogleAds\V16\Services\MutateGoogleAdsRequest; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Resources\Label; +use Google\Ads\GoogleAds\V18\Resources\CampaignLabel; +use Google\Ads\GoogleAds\V18\Services\LabelOperation; +use Google\Ads\GoogleAds\V18\Services\CampaignLabelOperation; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; +use Google\Ads\GoogleAds\V18\Services\MutateGoogleAdsRequest; /** * Class AdsCampaignLabel diff --git a/src/API/Google/AdsConversionAction.php b/src/API/Google/AdsConversionAction.php index f822db5057..4b16c97959 100644 --- a/src/API/Google/AdsConversionAction.php +++ b/src/API/Google/AdsConversionAction.php @@ -8,19 +8,19 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; use Exception; -use Google\Ads\GoogleAds\V16\Common\TagSnippet; -use Google\Ads\GoogleAds\V16\Enums\ConversionActionCategoryEnum\ConversionActionCategory; -use Google\Ads\GoogleAds\V16\Enums\ConversionActionStatusEnum\ConversionActionStatus; -use Google\Ads\GoogleAds\V16\Enums\ConversionActionTypeEnum\ConversionActionType; -use Google\Ads\GoogleAds\V16\Enums\TrackingCodePageFormatEnum\TrackingCodePageFormat; -use Google\Ads\GoogleAds\V16\Enums\TrackingCodeTypeEnum\TrackingCodeType; -use Google\Ads\GoogleAds\V16\Resources\ConversionAction; -use Google\Ads\GoogleAds\V16\Resources\ConversionAction\ValueSettings; -use Google\Ads\GoogleAds\V16\Services\ConversionActionOperation; -use Google\Ads\GoogleAds\V16\Services\Client\ConversionActionServiceClient; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Services\MutateConversionActionResult; -use Google\Ads\GoogleAds\V16\Services\MutateConversionActionsRequest; +use Google\Ads\GoogleAds\V18\Common\TagSnippet; +use Google\Ads\GoogleAds\V18\Enums\ConversionActionCategoryEnum\ConversionActionCategory; +use Google\Ads\GoogleAds\V18\Enums\ConversionActionStatusEnum\ConversionActionStatus; +use Google\Ads\GoogleAds\V18\Enums\ConversionActionTypeEnum\ConversionActionType; +use Google\Ads\GoogleAds\V18\Enums\TrackingCodePageFormatEnum\TrackingCodePageFormat; +use Google\Ads\GoogleAds\V18\Enums\TrackingCodeTypeEnum\TrackingCodeType; +use Google\Ads\GoogleAds\V18\Resources\ConversionAction; +use Google\Ads\GoogleAds\V18\Resources\ConversionAction\ValueSettings; +use Google\Ads\GoogleAds\V18\Services\ConversionActionOperation; +use Google\Ads\GoogleAds\V18\Services\Client\ConversionActionServiceClient; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Services\MutateConversionActionResult; +use Google\Ads\GoogleAds\V18\Services\MutateConversionActionsRequest; use Google\ApiCore\ApiException; /** diff --git a/src/API/Google/AdsReport.php b/src/API/Google/AdsReport.php index 49a7f9769a..b4c74ea864 100644 --- a/src/API/Google/AdsReport.php +++ b/src/API/Google/AdsReport.php @@ -15,8 +15,8 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait; use DateTime; -use Google\Ads\GoogleAds\V16\Common\Segments; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Common\Segments; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; use Google\ApiCore\ApiException; /** diff --git a/src/API/Google/AssetFieldType.php b/src/API/Google/AssetFieldType.php index 18e7778134..f2d9c92b54 100644 --- a/src/API/Google/AssetFieldType.php +++ b/src/API/Google/AssetFieldType.php @@ -3,14 +3,14 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google; -use Google\Ads\GoogleAds\V16\Enums\AssetFieldTypeEnum\AssetFieldType as AdsAssetFieldType; +use Google\Ads\GoogleAds\V18\Enums\AssetFieldTypeEnum\AssetFieldType as AdsAssetFieldType; use Automattic\WooCommerce\GoogleListingsAndAds\Internal\StatusMapping; use UnexpectedValueException; /** * Mapping between Google and internal AssetFieldTypes - * https://developers.google.com/google-ads/api/reference/rpc/V16/AssetFieldTypeEnum.AssetFieldType + * https://developers.google.com/google-ads/api/reference/rpc/v18/AssetFieldTypeEnum.AssetFieldType * * @since 2.4.0 * diff --git a/src/API/Google/BillingSetupStatus.php b/src/API/Google/BillingSetupStatus.php index 886059a85b..710f096db0 100644 --- a/src/API/Google/BillingSetupStatus.php +++ b/src/API/Google/BillingSetupStatus.php @@ -3,12 +3,12 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google; -use Google\Ads\GoogleAds\V16\Enums\BillingSetupStatusEnum\BillingSetupStatus as AdsBillingSetupStatus; +use Google\Ads\GoogleAds\V18\Enums\BillingSetupStatusEnum\BillingSetupStatus as AdsBillingSetupStatus; use Automattic\WooCommerce\GoogleListingsAndAds\Internal\StatusMapping; /** * Mapping between Google and internal BillingSetupStatus - * https://developers.google.com/google-ads/api/reference/rpc/v9/BillingSetupStatusEnum.BillingSetupStatus + * https://developers.google.com/google-ads/api/reference/rpc/v18/BillingSetupStatusEnum.BillingSetupStatus * * @package Automattic\WooCommerce\GoogleListingsAndAds\API\Google */ diff --git a/src/API/Google/CallToActionType.php b/src/API/Google/CallToActionType.php index 8a7bc15005..421dcbefff 100644 --- a/src/API/Google/CallToActionType.php +++ b/src/API/Google/CallToActionType.php @@ -3,13 +3,13 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google; -use Google\Ads\GoogleAds\V16\Enums\CallToActionTypeEnum\CallToActionType as AdsCallToActionType; +use Google\Ads\GoogleAds\V18\Enums\CallToActionTypeEnum\CallToActionType as AdsCallToActionType; use Automattic\WooCommerce\GoogleListingsAndAds\Internal\StatusMapping; /** * Mapping between Google and internal CallToActionType - * https://developers.google.com/google-ads/api/reference/rpc/V16/CallToActionTypeEnum.CallToActionType + * https://developers.google.com/google-ads/api/reference/rpc/v18/CallToActionTypeEnum.CallToActionType * * @since 2.4.0 * diff --git a/src/API/Google/CampaignStatus.php b/src/API/Google/CampaignStatus.php index 7c8813b0f8..5392dc381d 100644 --- a/src/API/Google/CampaignStatus.php +++ b/src/API/Google/CampaignStatus.php @@ -3,12 +3,12 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google; -use Google\Ads\GoogleAds\V16\Enums\CampaignStatusEnum\CampaignStatus as AdsCampaignStatus; +use Google\Ads\GoogleAds\V18\Enums\CampaignStatusEnum\CampaignStatus as AdsCampaignStatus; use Automattic\WooCommerce\GoogleListingsAndAds\Internal\StatusMapping; /** * Mapping between Google and internal CampaignStatus - * https://developers.google.com/google-ads/api/reference/rpc/v9/CampaignStatusEnum.CampaignStatus + * https://developers.google.com/google-ads/api/reference/rpc/v18/CampaignStatusEnum.CampaignStatus * * @package Automattic\WooCommerce\GoogleListingsAndAds\API\Google */ diff --git a/src/API/Google/CampaignType.php b/src/API/Google/CampaignType.php index d0d5f8a7f3..ad202bbc43 100644 --- a/src/API/Google/CampaignType.php +++ b/src/API/Google/CampaignType.php @@ -3,12 +3,12 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google; -use Google\Ads\GoogleAds\V16\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType as AdsCampaignType; +use Google\Ads\GoogleAds\V18\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType as AdsCampaignType; use Automattic\WooCommerce\GoogleListingsAndAds\Internal\StatusMapping; /** * Mapping between Google and internal CampaignTypes - * https://developers.google.com/google-ads/api/reference/rpc/v9/AdvertisingChannelTypeEnum.AdvertisingChannelType + * https://developers.google.com/google-ads/api/reference/rpc/v18/AdvertisingChannelTypeEnum.AdvertisingChannelType * * @since 1.12.2 * diff --git a/src/API/Google/ExceptionTrait.php b/src/API/Google/ExceptionTrait.php index f0b5090e2f..c7f06ff26c 100644 --- a/src/API/Google/ExceptionTrait.php +++ b/src/API/Google/ExceptionTrait.php @@ -54,9 +54,9 @@ protected function has_api_exception_error( ApiException $exception, string $err * The following are the example sources of ApiException, GoogleServiceException, * and other Exception in order: * - * @link https://github.com/googleads/google-ads-php/blob/v19.2.0/src/Google/Ads/GoogleAds/V16/Services/Gapic/CustomerServiceGapicClient.php#L391 - * @link https://github.com/googleapis/google-api-php-client/blob/v2.15.0/src/Http/REST.php#L119-L135 - * @link https://github.com/googleapis/google-api-php-client/blob/v2.15.0/src/Service/Resource.php#L86-L175 + * @link https://github.com/googleads/google-ads-php/blob/v25.0.0/src/Google/Ads/GoogleAds/V18/Services/Client/CustomerServiceClient.php#L303 + * @link https://github.com/googleapis/google-api-php-client/blob/v2.16.1/src/Http/REST.php#L119-L135 + * @link https://github.com/googleapis/google-api-php-client/blob/v2.16.1/src/Service/Resource.php#L86-L174 * * @param ApiException|GoogleServiceException|Exception $exception Exception to check. * diff --git a/src/API/Google/MerchantMetrics.php b/src/API/Google/MerchantMetrics.php index ca7ca7ae4c..998be9e34a 100644 --- a/src/API/Google/MerchantMetrics.php +++ b/src/API/Google/MerchantMetrics.php @@ -15,7 +15,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\SearchResponse; use DateTime; use Exception; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; use Google\ApiCore\PagedListResponse; /** diff --git a/src/API/Google/Query/AdsQuery.php b/src/API/Google/Query/AdsQuery.php index 8caaf0758d..b253c428c7 100644 --- a/src/API/Google/Query/AdsQuery.php +++ b/src/API/Google/Query/AdsQuery.php @@ -5,11 +5,9 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Exception\InvalidProperty; use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Services\SearchGoogleAdsRequest; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Services\SearchGoogleAdsRequest; use Google\ApiCore\ApiException; -use Google\ApiCore\PagedListResponse; - defined( 'ABSPATH' ) || exit; diff --git a/src/API/Google/Query/AdsReportQuery.php b/src/API/Google/Query/AdsReportQuery.php index a74648679b..d489545953 100644 --- a/src/API/Google/Query/AdsReportQuery.php +++ b/src/API/Google/Query/AdsReportQuery.php @@ -3,7 +3,7 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google\Query; -use Google\Ads\GoogleAds\V16\Resources\ShoppingPerformanceView; +use Google\Ads\GoogleAds\V18\Resources\ShoppingPerformanceView; defined( 'ABSPATH' ) || exit; diff --git a/src/API/Site/Controllers/Ads/AssetGroupController.php b/src/API/Site/Controllers/Ads/AssetGroupController.php index 703d92724d..4adc87c219 100644 --- a/src/API/Site/Controllers/Ads/AssetGroupController.php +++ b/src/API/Site/Controllers/Ads/AssetGroupController.php @@ -15,7 +15,7 @@ /** * Class for handling API requests related to the asset groups. - * See https://developers.google.com/google-ads/api/reference/rpc/V16/AssetGroup + * See https://developers.google.com/google-ads/api/reference/rpc/v18/AssetGroup * * @package Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\Ads */ diff --git a/src/Google/Ads/GoogleAdsClient.php b/src/Google/Ads/GoogleAdsClient.php index 485e70503a..004b53d71a 100644 --- a/src/Google/Ads/GoogleAdsClient.php +++ b/src/Google/Ads/GoogleAdsClient.php @@ -2,7 +2,7 @@ declare( strict_types=1 ); /** - * Overrides vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V16/GoogleAdsClient.php + * Overrides vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V18/GoogleAdsClient.php * * phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid * phpcs:disable WordPress.NamingConventions.ValidVariableName diff --git a/src/Google/Ads/ServiceClientFactoryTrait.php b/src/Google/Ads/ServiceClientFactoryTrait.php index e3bdc89f5b..e7a48c5039 100644 --- a/src/Google/Ads/ServiceClientFactoryTrait.php +++ b/src/Google/Ads/ServiceClientFactoryTrait.php @@ -2,7 +2,7 @@ declare( strict_types=1 ); /** - * Overrides vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V16/ServiceClientFactoryTrait.php + * Overrides vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V18/ServiceClientFactoryTrait.php * * phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid * phpcs:disable WordPress.NamingConventions.ValidVariableName @@ -13,24 +13,24 @@ use Google\Ads\GoogleAds\Constants; use Google\Ads\GoogleAds\Lib\ConfigurationTrait; -use Google\Ads\GoogleAds\V16\Services\Client\AccountLinkServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\AdGroupAdLabelServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\AdGroupAdServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\AdGroupCriterionServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\AdGroupServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\AdServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\AssetGroupListingGroupFilterServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\AssetGroupServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\BillingSetupServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\CampaignBudgetServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\CampaignCriterionServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\CampaignServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\ConversionActionServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\CustomerServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\CustomerUserAccessServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\GeoTargetConstantServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\GoogleAdsServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\ProductLinkInvitationServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AccountLinkServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AdGroupAdLabelServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AdGroupAdServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AdGroupCriterionServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AdGroupServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AdServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AssetGroupListingGroupFilterServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\AssetGroupServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\BillingSetupServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\CampaignBudgetServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\CampaignCriterionServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\CampaignServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\ConversionActionServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\CustomerServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\CustomerUserAccessServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\GeoTargetConstantServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\GoogleAdsServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\ProductLinkInvitationServiceClient; /** * Contains service client factory methods. diff --git a/src/Internal/DependencyManagement/GoogleServiceProvider.php b/src/Internal/DependencyManagement/GoogleServiceProvider.php index 3435720419..aed31605d2 100644 --- a/src/Internal/DependencyManagement/GoogleServiceProvider.php +++ b/src/Internal/DependencyManagement/GoogleServiceProvider.php @@ -46,7 +46,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Http\Message\RequestInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Http\Message\ResponseInterface; -use Google\Ads\GoogleAds\Util\V16\GoogleAdsFailures; +use Google\Ads\GoogleAds\Util\V18\GoogleAdsFailures; use Jetpack_Options; defined( 'ABSPATH' ) || exit; diff --git a/tests/Tools/HelperTrait/GoogleAdsClientTrait.php b/tests/Tools/HelperTrait/GoogleAdsClientTrait.php index d3443d4470..8d236e4199 100644 --- a/tests/Tools/HelperTrait/GoogleAdsClientTrait.php +++ b/tests/Tools/HelperTrait/GoogleAdsClientTrait.php @@ -10,53 +10,53 @@ use Automattic\WooCommerce\GoogleListingsAndAds\API\MicroTrait; use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Exception; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; -use Google\Ads\GoogleAds\V16\Common\LocationInfo; -use Google\Ads\GoogleAds\V16\Common\Metrics; -use Google\Ads\GoogleAds\V16\Common\Segments; -use Google\Ads\GoogleAds\V16\Common\TagSnippet; -use Google\Ads\GoogleAds\V16\Common\ImageAsset; -use Google\Ads\GoogleAds\V16\Common\TextAsset; -use Google\Ads\GoogleAds\V16\Common\CallToActionAsset; -use Google\Ads\GoogleAds\V16\Common\ImageDimension; -use Google\Ads\GoogleAds\V16\Enums\AccessRoleEnum\AccessRole; -use Google\Ads\GoogleAds\V16\Enums\CampaignStatusEnum\CampaignStatus as AdsCampaignStatus; -use Google\Ads\GoogleAds\V16\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType as AdsCampaignType; -use Google\Ads\GoogleAds\V16\Enums\AssetTypeEnum\AssetType; -use Google\Ads\GoogleAds\V16\Enums\TrackingCodePageFormatEnum\TrackingCodePageFormat; -use Google\Ads\GoogleAds\V16\Enums\TrackingCodeTypeEnum\TrackingCodeType; -use Google\Ads\GoogleAds\V16\Resources\BillingSetup; -use Google\Ads\GoogleAds\V16\Resources\Campaign; -use Google\Ads\GoogleAds\V16\Resources\Label; -use Google\Ads\GoogleAds\V16\Resources\Asset; -use Google\Ads\GoogleAds\V16\Resources\AssetGroup; -use Google\Ads\GoogleAds\V16\Resources\AssetGroupAsset; -use Google\Ads\GoogleAds\V16\Services\AssetGroupAssetOperation; -use Google\Ads\GoogleAds\V16\Resources\CampaignBudget; -use Google\Ads\GoogleAds\V16\Resources\CampaignCriterion; -use Google\Ads\GoogleAds\V16\Resources\Campaign\ShoppingSetting; -use Google\Ads\GoogleAds\V16\Resources\ConversionAction; -use Google\Ads\GoogleAds\V16\Resources\Customer; -use Google\Ads\GoogleAds\V16\Resources\CustomerUserAccess; -use Google\Ads\GoogleAds\V16\Resources\ShoppingPerformanceView; -use Google\Ads\GoogleAds\V16\Services\Client\ConversionActionServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\CustomerServiceClient; -use Google\Ads\GoogleAds\V16\Services\Client\ProductLinkInvitationServiceClient; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Services\Client\GoogleAdsServiceClient; -use Google\Ads\GoogleAds\V16\Services\ListAccessibleCustomersResponse; -use Google\Ads\GoogleAds\V16\Services\MutateCampaignResult; -use Google\Ads\GoogleAds\V16\Services\MutateLabelResult; -use Google\Ads\GoogleAds\V16\Services\MutateConversionActionResult; -use Google\Ads\GoogleAds\V16\Services\MutateConversionActionsRequest; -use Google\Ads\GoogleAds\V16\Services\MutateConversionActionsResponse; -use Google\Ads\GoogleAds\V16\Services\MutateGoogleAdsRequest; -use Google\Ads\GoogleAds\V16\Services\MutateGoogleAdsResponse; -use Google\Ads\GoogleAds\V16\Services\MutateOperationResponse; -use Google\Ads\GoogleAds\V16\Services\MutateOperation; -use Google\Ads\GoogleAds\V16\Services\MutateAssetGroupResult; -use Google\Ads\GoogleAds\V16\Services\MutateAssetResult; -use Google\Ads\GoogleAds\V16\Services\SearchGoogleAdsResponse; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; +use Google\Ads\GoogleAds\V18\Common\LocationInfo; +use Google\Ads\GoogleAds\V18\Common\Metrics; +use Google\Ads\GoogleAds\V18\Common\Segments; +use Google\Ads\GoogleAds\V18\Common\TagSnippet; +use Google\Ads\GoogleAds\V18\Common\ImageAsset; +use Google\Ads\GoogleAds\V18\Common\TextAsset; +use Google\Ads\GoogleAds\V18\Common\CallToActionAsset; +use Google\Ads\GoogleAds\V18\Common\ImageDimension; +use Google\Ads\GoogleAds\V18\Enums\AccessRoleEnum\AccessRole; +use Google\Ads\GoogleAds\V18\Enums\CampaignStatusEnum\CampaignStatus as AdsCampaignStatus; +use Google\Ads\GoogleAds\V18\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType as AdsCampaignType; +use Google\Ads\GoogleAds\V18\Enums\AssetTypeEnum\AssetType; +use Google\Ads\GoogleAds\V18\Enums\TrackingCodePageFormatEnum\TrackingCodePageFormat; +use Google\Ads\GoogleAds\V18\Enums\TrackingCodeTypeEnum\TrackingCodeType; +use Google\Ads\GoogleAds\V18\Resources\BillingSetup; +use Google\Ads\GoogleAds\V18\Resources\Campaign; +use Google\Ads\GoogleAds\V18\Resources\Label; +use Google\Ads\GoogleAds\V18\Resources\Asset; +use Google\Ads\GoogleAds\V18\Resources\AssetGroup; +use Google\Ads\GoogleAds\V18\Resources\AssetGroupAsset; +use Google\Ads\GoogleAds\V18\Services\AssetGroupAssetOperation; +use Google\Ads\GoogleAds\V18\Resources\CampaignBudget; +use Google\Ads\GoogleAds\V18\Resources\CampaignCriterion; +use Google\Ads\GoogleAds\V18\Resources\Campaign\ShoppingSetting; +use Google\Ads\GoogleAds\V18\Resources\ConversionAction; +use Google\Ads\GoogleAds\V18\Resources\Customer; +use Google\Ads\GoogleAds\V18\Resources\CustomerUserAccess; +use Google\Ads\GoogleAds\V18\Resources\ShoppingPerformanceView; +use Google\Ads\GoogleAds\V18\Services\Client\ConversionActionServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\CustomerServiceClient; +use Google\Ads\GoogleAds\V18\Services\Client\ProductLinkInvitationServiceClient; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Services\Client\GoogleAdsServiceClient; +use Google\Ads\GoogleAds\V18\Services\ListAccessibleCustomersResponse; +use Google\Ads\GoogleAds\V18\Services\MutateCampaignResult; +use Google\Ads\GoogleAds\V18\Services\MutateLabelResult; +use Google\Ads\GoogleAds\V18\Services\MutateConversionActionResult; +use Google\Ads\GoogleAds\V18\Services\MutateConversionActionsRequest; +use Google\Ads\GoogleAds\V18\Services\MutateConversionActionsResponse; +use Google\Ads\GoogleAds\V18\Services\MutateGoogleAdsRequest; +use Google\Ads\GoogleAds\V18\Services\MutateGoogleAdsResponse; +use Google\Ads\GoogleAds\V18\Services\MutateOperationResponse; +use Google\Ads\GoogleAds\V18\Services\MutateOperation; +use Google\Ads\GoogleAds\V18\Services\MutateAssetGroupResult; +use Google\Ads\GoogleAds\V18\Services\MutateAssetResult; +use Google\Ads\GoogleAds\V18\Services\SearchGoogleAdsResponse; use Google\ApiCore\ApiException; use Google\ApiCore\Page; use Google\ApiCore\PagedListResponse; diff --git a/tests/Unit/API/Google/AdsAssetGroupAssetTest.php b/tests/Unit/API/Google/AdsAssetGroupAssetTest.php index 6cb9c162f3..93c7f39dae 100644 --- a/tests/Unit/API/Google/AdsAssetGroupAssetTest.php +++ b/tests/Unit/API/Google/AdsAssetGroupAssetTest.php @@ -10,8 +10,8 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\GoogleAdsClientTrait; use PHPUnit\Framework\MockObject\MockObject; use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\AssetFieldType; -use Google\Ads\GoogleAds\V16\Enums\AssetTypeEnum\AssetType; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; +use Google\Ads\GoogleAds\V18\Enums\AssetTypeEnum\AssetType; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; defined( 'ABSPATH' ) || exit; diff --git a/tests/Unit/API/Google/AdsAssetGroupTest.php b/tests/Unit/API/Google/AdsAssetGroupTest.php index d429bdd788..b5d925b17f 100644 --- a/tests/Unit/API/Google/AdsAssetGroupTest.php +++ b/tests/Unit/API/Google/AdsAssetGroupTest.php @@ -8,9 +8,9 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\GoogleAdsClientTrait; -use Google\Ads\GoogleAds\V16\Enums\AssetGroupStatusEnum\AssetGroupStatus; -use Google\Ads\GoogleAds\V16\Enums\ListingGroupFilterListingSourceEnum\ListingGroupFilterListingSource; -use Google\Ads\GoogleAds\V16\Enums\ListingGroupFilterTypeEnum\ListingGroupFilterType; +use Google\Ads\GoogleAds\V18\Enums\AssetGroupStatusEnum\AssetGroupStatus; +use Google\Ads\GoogleAds\V18\Enums\ListingGroupFilterListingSourceEnum\ListingGroupFilterListingSource; +use Google\Ads\GoogleAds\V18\Enums\ListingGroupFilterTypeEnum\ListingGroupFilterType; use PHPUnit\Framework\MockObject\MockObject; use Google\ApiCore\ApiException; use Automattic\WooCommerce\GoogleListingsAndAds\Exception\ExceptionWithResponseData; diff --git a/tests/Unit/API/Google/AdsAssetTest.php b/tests/Unit/API/Google/AdsAssetTest.php index 4fe2aed41a..6534a9326e 100644 --- a/tests/Unit/API/Google/AdsAssetTest.php +++ b/tests/Unit/API/Google/AdsAssetTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\AssetFieldType; use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\CallToActionType; -use Google\Ads\GoogleAds\Util\V16\ResourceNames; +use Google\Ads\GoogleAds\Util\V18\ResourceNames; use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\WP; use Exception; use WP_Error; diff --git a/tests/Unit/API/Google/AdsCampaignCriterionTest.php b/tests/Unit/API/Google/AdsCampaignCriterionTest.php index 091b86f7c0..7d75588943 100644 --- a/tests/Unit/API/Google/AdsCampaignCriterionTest.php +++ b/tests/Unit/API/Google/AdsCampaignCriterionTest.php @@ -6,7 +6,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\AdsCampaignCriterion; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\GoogleAdsClientTrait; -use Google\Ads\GoogleAds\V16\Enums\CampaignCriterionStatusEnum\CampaignCriterionStatus; +use Google\Ads\GoogleAds\V18\Enums\CampaignCriterionStatusEnum\CampaignCriterionStatus; defined( 'ABSPATH' ) || exit; diff --git a/tests/Unit/API/Google/AdsConversionActionTest.php b/tests/Unit/API/Google/AdsConversionActionTest.php index e06000e7ce..04d1cac770 100644 --- a/tests/Unit/API/Google/AdsConversionActionTest.php +++ b/tests/Unit/API/Google/AdsConversionActionTest.php @@ -8,7 +8,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\GoogleAdsClientTrait; use Exception; -use Google\Ads\GoogleAds\V16\Enums\ConversionActionStatusEnum\ConversionActionStatus; +use Google\Ads\GoogleAds\V18\Enums\ConversionActionStatusEnum\ConversionActionStatus; use Google\ApiCore\ApiException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/API/Google/AdsTest.php b/tests/Unit/API/Google/AdsTest.php index b8e700b6e0..7c58a3fbee 100644 --- a/tests/Unit/API/Google/AdsTest.php +++ b/tests/Unit/API/Google/AdsTest.php @@ -10,10 +10,10 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\GoogleAdsClientTrait; use Exception; -use Google\Ads\GoogleAds\V16\Enums\BillingSetupStatusEnum\BillingSetupStatus as AdsBillingSetupStatus; -use Google\Ads\GoogleAds\V16\Enums\ProductLinkInvitationStatusEnum\ProductLinkInvitationStatus; -use Google\Ads\GoogleAds\V16\Resources\MerchantCenterLinkInvitationIdentifier; -use Google\Ads\GoogleAds\V16\Resources\ProductLinkInvitation; +use Google\Ads\GoogleAds\V18\Enums\BillingSetupStatusEnum\BillingSetupStatus as AdsBillingSetupStatus; +use Google\Ads\GoogleAds\V18\Enums\ProductLinkInvitationStatusEnum\ProductLinkInvitationStatus; +use Google\Ads\GoogleAds\V18\Resources\MerchantCenterLinkInvitationIdentifier; +use Google\Ads\GoogleAds\V18\Resources\ProductLinkInvitation; use Google\ApiCore\ApiException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/API/Google/MerchantMetricsTest.php b/tests/Unit/API/Google/MerchantMetricsTest.php index 8ab6475a48..a4cd52afe9 100644 --- a/tests/Unit/API/Google/MerchantMetricsTest.php +++ b/tests/Unit/API/Google/MerchantMetricsTest.php @@ -16,9 +16,9 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\SearchResponse; use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\Resource\Reports; use DateTime; -use Google\Ads\GoogleAds\V16\Common\Metrics as AdMetrics; -use Google\Ads\GoogleAds\V16\Services\GoogleAdsRow; -use Google\Ads\GoogleAds\V16\Services\Client\GoogleAdsServiceClient; +use Google\Ads\GoogleAds\V18\Common\Metrics as AdMetrics; +use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; +use Google\Ads\GoogleAds\V18\Services\Client\GoogleAdsServiceClient; use Google\ApiCore\Page; use Google\ApiCore\PagedListResponse; use PHPUnit\Framework\MockObject\MockObject; From 83f5606bdb227b91f193b83d83a8e5a16668bfa7 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 08:55:01 +0000 Subject: [PATCH 02/13] Cleanup Ads versions except V18 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1277099b4f..647e8de169 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "Google\\Task\\Composer::cleanup", "Automattic\\WooCommerce\\GoogleListingsAndAds\\Util\\SymfonyPolyfillCleanup::remove", "Automattic\\WooCommerce\\GoogleListingsAndAds\\Util\\GoogleAdsCleanupServices::remove", - "composer run-script remove-google-ads-api-version-support -- 14 15 17 18", + "composer run-script remove-google-ads-api-version-support -- 16 17", "php ./bin/prefix-vendor-namespace.php", "bash ./bin/cleanup-vendor-files.sh", "composer dump-autoload" From d9d8096390c978704be7b517ec1cfa3bbd03a795 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 09:15:56 +0000 Subject: [PATCH 03/13] Use new SearchSettings class for getting the total results --- src/API/Google/Query/AdsQuery.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/API/Google/Query/AdsQuery.php b/src/API/Google/Query/AdsQuery.php index b253c428c7..78da9203a0 100644 --- a/src/API/Google/Query/AdsQuery.php +++ b/src/API/Google/Query/AdsQuery.php @@ -7,6 +7,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; use Google\Ads\GoogleAds\V18\Services\SearchGoogleAdsRequest; +use Google\Ads\GoogleAds\V18\Services\SearchSettings; use Google\ApiCore\ApiException; defined( 'ABSPATH' ) || exit; @@ -89,8 +90,15 @@ protected function query_results() { } $request = new SearchGoogleAdsRequest(); + // Allow us to get the total number of results for pagination. - $request->setReturnTotalResultsCount( true ); + $request->setSearchSettings( + new SearchSettings( + [ + 'return_total_results_count' => true, + ] + ) + ); if ( ! empty( $this->search_args['pageSize'] ) ) { $request->setPageSize( $this->search_args['pageSize'] ); From c03786c9f72cf10826e405c3d6a8e48e9228b283 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 09:36:27 +0000 Subject: [PATCH 04/13] Remove unsupported page size from AdsQuery --- src/API/Google/Query/AdsQuery.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/API/Google/Query/AdsQuery.php b/src/API/Google/Query/AdsQuery.php index 78da9203a0..f6ad081353 100644 --- a/src/API/Google/Query/AdsQuery.php +++ b/src/API/Google/Query/AdsQuery.php @@ -100,10 +100,6 @@ protected function query_results() { ) ); - if ( ! empty( $this->search_args['pageSize'] ) ) { - $request->setPageSize( $this->search_args['pageSize'] ); - } - $request->setQuery( $this->build_query() ); $request->setCustomerId( $this->id ); From bb0e12baa3407118b0cb2223f488cdf8f3b5e352 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 10:16:00 +0000 Subject: [PATCH 05/13] Revert pagination for campaigns --- src/API/Google/AdsCampaign.php | 29 +++++-------------- src/API/Google/Query/AdsCampaignQuery.php | 9 +----- src/API/Google/Query/AdsQuery.php | 11 ------- .../Controllers/Ads/CampaignController.php | 24 ++------------- 4 files changed, 11 insertions(+), 62 deletions(-) diff --git a/src/API/Google/AdsCampaign.php b/src/API/Google/AdsCampaign.php index 4aec3609d6..24ebb4650b 100644 --- a/src/API/Google/AdsCampaign.php +++ b/src/API/Google/AdsCampaign.php @@ -106,17 +106,15 @@ public function __construct( GoogleAdsClient $client, AdsCampaignBudget $budget, /** * Returns a list of campaigns with targeted locations retrieved from campaign criterion. * - * @param bool $exclude_removed Exclude removed campaigns (default true). - * @param bool $fetch_criterion Combine the campaign data with criterion data (default true). - * @param array $args Arguments for the Ads Campaign Query for example: per_page for limiting the number of results. - * @param bool $return_pagination_params Whether to return pagination params (default false). + * @param bool $exclude_removed Exclude removed campaigns (default true). + * @param bool $fetch_criterion Combine the campaign data with criterion data (default true). * * @return array * @throws ExceptionWithResponseData When an ApiException is caught. */ - public function get_campaigns( bool $exclude_removed = true, bool $fetch_criterion = true, $args = [], $return_pagination_params = false ): array { + public function get_campaigns( bool $exclude_removed = true, bool $fetch_criterion = true ): array { try { - $query = ( new AdsCampaignQuery( $args ) )->set_client( $this->client, $this->options->get_ads_id() ); + $query = ( new AdsCampaignQuery() )->set_client( $this->client, $this->options->get_ads_id() ); if ( $exclude_removed ) { $query->where( 'campaign.status', 'REMOVED', '!=' ); @@ -126,10 +124,7 @@ public function get_campaigns( bool $exclude_removed = true, bool $fetch_criteri $campaign_results = $query->get_results(); $converted_campaigns = []; - /** @var Page $page */ - $page = $campaign_results->getPage(); - - foreach ( $page->getIterator() as $row ) { + foreach ( $campaign_results->iterateAllElements() as $row ) { ++$campaign_count; $campaign = $this->convert_campaign( $row ); $converted_campaigns[ $campaign['id'] ] = $campaign; @@ -148,16 +143,6 @@ public function get_campaigns( bool $exclude_removed = true, bool $fetch_criteri $converted_campaigns = $this->combine_campaigns_and_campaign_criterion_results( $converted_campaigns ); } - if ( $return_pagination_params ) { - // Total results across all pages. - $total_results = $page->getResponseObject()->getTotalResultsCount(); - $next_page_token = $page->getNextPageToken(); - return [ - 'campaigns' => array_values( $converted_campaigns ), - 'total_results' => $total_results, - 'next_page_token' => $next_page_token, - ]; - } return array_values( $converted_campaigns ); } catch ( ApiException $e ) { do_action( 'woocommerce_gla_ads_client_exception', $e, __METHOD__ ); @@ -183,14 +168,14 @@ public function get_campaigns( bool $exclude_removed = true, bool $fetch_criteri */ public function get_campaign( int $id ): array { try { - $campaign_results = ( new AdsCampaignQuery( [ 'per_page' => 1 ] ) )->set_client( $this->client, $this->options->get_ads_id() ) + $campaign_results = ( new AdsCampaignQuery() )->set_client( $this->client, $this->options->get_ads_id() ) ->where( 'campaign.id', $id, '=' ) ->get_results(); $converted_campaigns = []; // Get only the first element from campaign results - foreach ( $campaign_results->getPage()->getIterator() as $row ) { + foreach ( $campaign_results->iterateAllElements() as $row ) { $campaign = $this->convert_campaign( $row ); $converted_campaigns[ $campaign['id'] ] = $campaign; break; diff --git a/src/API/Google/Query/AdsCampaignQuery.php b/src/API/Google/Query/AdsCampaignQuery.php index d0c2509998..658960a327 100644 --- a/src/API/Google/Query/AdsCampaignQuery.php +++ b/src/API/Google/Query/AdsCampaignQuery.php @@ -12,15 +12,10 @@ */ class AdsCampaignQuery extends AdsQuery { - use ReportQueryTrait; - - /** * Query constructor. - * - * @param array $args Query arguments. */ - public function __construct( $args = [] ) { + public function __construct() { parent::__construct( 'campaign' ); $this->columns( [ @@ -32,7 +27,5 @@ public function __construct( $args = [] ) { 'campaign_budget.amount_micros', ] ); - - $this->handle_query_args( $args ); } } diff --git a/src/API/Google/Query/AdsQuery.php b/src/API/Google/Query/AdsQuery.php index f6ad081353..eefdc34771 100644 --- a/src/API/Google/Query/AdsQuery.php +++ b/src/API/Google/Query/AdsQuery.php @@ -7,7 +7,6 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; use Google\Ads\GoogleAds\V18\Services\SearchGoogleAdsRequest; -use Google\Ads\GoogleAds\V18\Services\SearchSettings; use Google\ApiCore\ApiException; defined( 'ABSPATH' ) || exit; @@ -90,16 +89,6 @@ protected function query_results() { } $request = new SearchGoogleAdsRequest(); - - // Allow us to get the total number of results for pagination. - $request->setSearchSettings( - new SearchSettings( - [ - 'return_total_results_count' => true, - ] - ) - ); - $request->setQuery( $this->build_query() ); $request->setCustomerId( $this->id ); diff --git a/src/API/Site/Controllers/Ads/CampaignController.php b/src/API/Site/Controllers/Ads/CampaignController.php index 6fefab6936..1cd67ec7e4 100644 --- a/src/API/Site/Controllers/Ads/CampaignController.php +++ b/src/API/Site/Controllers/Ads/CampaignController.php @@ -99,33 +99,15 @@ public function register_routes(): void { protected function get_campaigns_callback(): callable { return function ( Request $request ) { try { - $exclude_removed = $request->get_param( 'exclude_removed' ); - $return_pagination_params = true; - $campaign_data = $this->ads_campaign->get_campaigns( $exclude_removed, true, $request->get_params(), $return_pagination_params ); + $exclude_removed = $request->get_param( 'exclude_removed' ); - $campaigns = array_map( + return array_map( function ( $campaign ) use ( $request ) { $data = $this->prepare_item_for_response( $campaign, $request ); return $this->prepare_response_for_collection( $data ); }, - $campaign_data['campaigns'] + $this->ads_campaign->get_campaigns( $exclude_removed ) ); - - $response = rest_ensure_response( $campaigns ); - - $total_campaigns = (int) $campaign_data['total_results']; - $response->header( 'X-WP-Total', $total_campaigns ); - // If per_page is not set, then set it to total number of campaigns. - $per_page = $request->get_param( 'per_page' ) ?: $total_campaigns; - $max_pages = $per_page > 0 ? ceil( $total_campaigns / $per_page ) : 1; - $response->header( 'X-WP-TotalPages', (int) $max_pages ); - - if ( ! empty( $campaign_data['next_page_token'] ) ) { - $response->header( 'X-GLA-NextPageToken', $campaign_data['next_page_token'] ); - } - - return $response; - } catch ( Exception $e ) { return $this->response_from_exception( $e ); } From 93fd22bb7e2b38db9ca2078f166efd779419ecc2 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 10:28:21 +0000 Subject: [PATCH 06/13] Revert pagination for campaigns in unit tests --- .../HelperTrait/GoogleAdsClientTrait.php | 25 +--- tests/Unit/API/Google/AdsCampaignTest.php | 67 --------- .../Ads/CampaignControllerTest.php | 136 +----------------- 3 files changed, 6 insertions(+), 222 deletions(-) diff --git a/tests/Tools/HelperTrait/GoogleAdsClientTrait.php b/tests/Tools/HelperTrait/GoogleAdsClientTrait.php index 8d236e4199..6d8a9dd876 100644 --- a/tests/Tools/HelperTrait/GoogleAdsClientTrait.php +++ b/tests/Tools/HelperTrait/GoogleAdsClientTrait.php @@ -188,32 +188,17 @@ protected function generate_ads_multiple_query_mock( array $responses ) { * * @param array $campaigns_responses Set of campaign data to convert. * @param array $campaign_criterion_responses Set of campaign criterion data to convert. - * @param bool $assert_pagination Whether to assert pagination. */ - protected function generate_ads_campaign_query_mock( array $campaigns_responses, $campaign_criterion_responses, $assert_pagination = false ) { + protected function generate_ads_campaign_query_mock( array $campaigns_responses, $campaign_criterion_responses ) { $campaigns_row_mock = array_map( [ $this, 'generate_campaign_row_mock' ], $campaigns_responses ); $campaign_criterion_row_mock = array_map( [ $this, 'generate_campaign_criterion_row_mock' ], $campaign_criterion_responses ); $list_response = $this->createMock( PagedListResponse::class ); - $page = $this->createMock( Page::class ); - - if ( $assert_pagination ) { - $response_object = $this->createMock( SearchGoogleAdsResponse::class ); - $response_object->expects( $this->exactly( 1 ) )->method( 'getTotalResultsCount' )->willReturn( count( $campaigns_responses ) ); - $page->expects( $this->exactly( 1 ) )->method( 'getNextPageToken' )->willReturn( '' ); - $page->method( 'getResponseObject' )->willReturn( $response_object ); - } - - $page->method( 'getIterator' )->willReturn( + $list_response->method( 'iterateAllElements' )->willReturnOnConsecutiveCalls( $campaigns_row_mock, - ); - - $list_response->method( 'iterateAllElements' )->willReturn( $campaign_criterion_row_mock ); - $list_response->method( 'getPage' )->willReturn( $page ); - $this->service_client ->method( 'search' )->willReturn( $list_response ); } @@ -327,11 +312,9 @@ function ( MutateGoogleAdsRequest $request ) use ( $response, $label_id, $campai */ protected function generate_ads_campaign_query_mock_with_no_campaigns() { $list_response = $this->createMock( PagedListResponse::class ); - $page = $this->createMock( Page::class ); - $page->method( 'getIterator' )->willReturn( [] ); - $list_response->method( 'getPage' )->willReturn( $page ); + $list_response->method( 'iterateAllElements' )->willReturn( [] ); - // Method search() will only being called once by AdsCampaignQuery + // Method search() will only be called once by AdsCampaignQuery // since there were no campaigns returned by AdsCampaignQuery, it // won't be calling AdsCampaignCriterionQuery then. $this->service_client->expects( $this->once() ) diff --git a/tests/Unit/API/Google/AdsCampaignTest.php b/tests/Unit/API/Google/AdsCampaignTest.php index a18c23e2e6..c40859d942 100644 --- a/tests/Unit/API/Google/AdsCampaignTest.php +++ b/tests/Unit/API/Google/AdsCampaignTest.php @@ -141,73 +141,6 @@ public function test_get_campaigns() { $this->assertEquals( $campaigns_data, $this->campaign->get_campaigns() ); } - public function test_get_campaigns_with_search_args() { - $campaign_criterion_data = [ - [ - 'campaign_id' => self::TEST_CAMPAIGN_ID, - 'geo_target_constant' => 'geoTargetConstants/2158', - ], - [ - 'campaign_id' => 5678901234, - 'geo_target_constant' => 'geoTargetConstants/2344', - ], - [ - 'campaign_id' => 5678901234, - 'geo_target_constant' => 'geoTargetConstants/2826', - ], - ]; - - $campaigns_data = [ - [ - 'id' => self::TEST_CAMPAIGN_ID, - 'name' => 'Campaign One', - 'status' => 'paused', - 'type' => 'shopping', - 'amount' => 10, - 'country' => 'US', - 'targeted_locations' => [ 'TW' ], - ], - [ - 'id' => 5678901234, - 'name' => 'Campaign Two', - 'status' => 'enabled', - 'type' => 'performance_max', - 'amount' => 20, - 'country' => 'UK', - 'targeted_locations' => [ 'HK', 'GB' ], - ], - ]; - - $this->generate_ads_campaign_query_mock( $campaigns_data, $campaign_criterion_data, true ); - - $matcher = $this->exactly( 2 ); - $this->service_client - ->expects( $matcher ) - ->method( 'search' ) - ->willReturnCallback( - function ( $request ) use ( $matcher ) { - if ( $matcher->getInvocationCount() === 1 ) { - $this->assertEquals( 2, $request->getPageSize() ); // Campaigns - } - - if ( $matcher->getInvocationCount() === 2 ) { - $this->assertEquals( 0, $request->getPageSize() ); // Criterions - } - - return true; - } - ); - - $this->assertEquals( - [ - 'campaigns' => $campaigns_data, - 'total_results' => count( $campaigns_data ), - 'next_page_token' => '', - ], - $this->campaign->get_campaigns( true, true, [ 'per_page' => 2 ], true ) - ); - } - public function test_get_campaigns_with_nonexist_location_id() { $campaign_criterion_data = [ [ diff --git a/tests/Unit/API/Site/Controllers/Ads/CampaignControllerTest.php b/tests/Unit/API/Site/Controllers/Ads/CampaignControllerTest.php index 5491201228..3b7a95b184 100644 --- a/tests/Unit/API/Site/Controllers/Ads/CampaignControllerTest.php +++ b/tests/Unit/API/Site/Controllers/Ads/CampaignControllerTest.php @@ -86,23 +86,12 @@ public function test_get_campaigns() { $this->ads_campaign->expects( $this->once() ) ->method( 'get_campaigns' ) - ->willReturn( - [ - 'campaigns' => $campaigns_data, - 'total_results' => 2, - 'next_page_token' => '', - ] - ); + ->willReturn( $campaigns_data ); $response = $this->do_request( self::ROUTE_CAMPAIGNS, 'GET' ); $this->assertEquals( $campaigns_data, $response->get_data() ); $this->assertEquals( 200, $response->get_status() ); - - $headers = $response->get_headers(); - $this->assertEquals( 2, $headers['X-WP-Total'] ); - $this->assertEquals( 1, $headers['X-WP-TotalPages'] ); - $this->assertArrayNotHasKey( 'X-GLA-NextPageToken', $headers ); } public function test_get_campaigns_converted_names() { @@ -155,133 +144,12 @@ public function test_get_campaigns_converted_names() { $this->ads_campaign->expects( $this->once() ) ->method( 'get_campaigns' ) ->with( false ) - ->willReturn( - [ - 'campaigns' => $campaigns_data, - 'total_results' => 2, - 'next_page_token' => '', - ] - ); + ->willReturn( $campaigns_data ); $response = $this->do_request( self::ROUTE_CAMPAIGNS, 'GET', [ 'exclude_removed' => false ] ); $this->assertEquals( $expected, $response->get_data() ); $this->assertEquals( 200, $response->get_status() ); - - $headers = $response->get_headers(); - $this->assertEquals( 2, $headers['X-WP-Total'] ); - $this->assertEquals( 1, $headers['X-WP-TotalPages'] ); - $this->assertArrayNotHasKey( 'X-GLA-NextPageToken', $headers ); - } - - public function test_get_campaigns_with_args() { - $campaigns_data = [ - [ - 'id' => self::TEST_CAMPAIGN_ID, - 'name' => 'Test Campaign', - 'status' => 'removed', - 'type' => 'shopping', - 'amount' => 10, - 'country' => 'US', - 'targeted_locations' => [], - ], - [ - 'id' => 5678901234, - 'name' => 'PMax: Test Campaign', - 'status' => 'enabled', - 'type' => 'performance_max', - 'amount' => 20, - 'country' => 'UK', - 'targeted_locations' => [], - ], - ]; - - $expected = [ - [ - 'id' => self::TEST_CAMPAIGN_ID, - 'name' => 'Test Campaign', - 'status' => 'removed', - 'type' => 'shopping', - 'amount' => 10, - 'country' => 'US', - 'targeted_locations' => [], - ], - [ - 'id' => 5678901234, - 'name' => 'PMax: Test Campaign', - 'status' => 'enabled', - 'type' => 'performance_max', - 'amount' => 20, - 'country' => 'UK', - 'targeted_locations' => [], - ], - ]; - - $matcher = $this->exactly( 3 ); - $this->ads_campaign->expects( $matcher ) // We will make two requests with different per_page values. - ->method( 'get_campaigns' ) - ->willReturnCallback( - function ( $exclude_removed, $fetch_criterion, $args ) use ( $matcher ) { - $this->assertTrue( $exclude_removed ); - $this->assertTrue( $fetch_criterion ); - - if ( $matcher->getInvocationCount() === 1 ) { - $this->assertEquals( 2, $args['per_page'] ); // First request. - } - - if ( $matcher->getInvocationCount() === 2 ) { - $this->assertEquals( 1, $args['per_page'] ); // Second request. - } - - return true; - } - )->willReturnOnConsecutiveCalls( - [ - 'campaigns' => $campaigns_data, - 'total_results' => 2, - 'next_page_token' => '', - ], - [ - 'campaigns' => [ $campaigns_data[0] ], - 'total_results' => 3, - 'next_page_token' => 'pageToken', - ], - [ - 'campaigns' => [], - 'total_results' => 0, - 'next_page_token' => '', - ] - ); - - // First request. - $response = $this->do_request( self::ROUTE_CAMPAIGNS, 'GET', [ 'per_page' => 2 ] ); - $this->assertEquals( $expected, $response->get_data() ); - $this->assertEquals( 200, $response->get_status() ); - - $headers = $response->get_headers(); - $this->assertEquals( 2, $headers['X-WP-Total'] ); - $this->assertEquals( 1, $headers['X-WP-TotalPages'] ); - $this->assertArrayNotHasKey( 'X-GLA-NextPageToken', $headers ); - - // Second request. - $response = $this->do_request( self::ROUTE_CAMPAIGNS, 'GET', [ 'per_page' => 1 ] ); - $this->assertEquals( [ $expected[0] ], $response->get_data() ); - $this->assertEquals( 200, $response->get_status() ); - - $headers = $response->get_headers(); - $this->assertEquals( 3, $headers['X-WP-Total'] ); - $this->assertEquals( 3, $headers['X-WP-TotalPages'] ); - $this->assertEquals( 'pageToken', $headers['X-GLA-NextPageToken'] ); - - // Third request. - $response = $this->do_request( self::ROUTE_CAMPAIGNS, 'GET', [ 'per_page' => 1 ] ); - $this->assertEquals( [], $response->get_data() ); - $this->assertEquals( 200, $response->get_status() ); - - $headers = $response->get_headers(); - $this->assertEquals( 0, $headers['X-WP-Total'] ); - $this->assertEquals( 0, $headers['X-WP-TotalPages'] ); - $this->assertArrayNotHasKey( 'X-GLA-NextPageToken', $headers ); } public function test_get_campaigns_with_api_exception() { From b53bd41d1559f913eb121b27ae781e7d3ccd96a8 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 10:47:18 +0000 Subject: [PATCH 07/13] Set page token if needed --- src/API/Google/Query/AdsQuery.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/API/Google/Query/AdsQuery.php b/src/API/Google/Query/AdsQuery.php index eefdc34771..09d416c0fe 100644 --- a/src/API/Google/Query/AdsQuery.php +++ b/src/API/Google/Query/AdsQuery.php @@ -35,6 +35,9 @@ abstract class AdsQuery extends Query { /** * Arguments to add to the search query. * + * Note: While we allow pageSize to be set, we do not pass it to the API. + * pageSize has been deprecated in the API since V17 and is fixed to 10000 rows. + * * @var array */ protected $search_args = []; @@ -89,6 +92,11 @@ protected function query_results() { } $request = new SearchGoogleAdsRequest(); + + if ( ! empty( $this->search_args['pageToken'] ) ) { + $request->setPageToken( $this->search_args['pageToken'] ); + } + $request->setQuery( $this->build_query() ); $request->setCustomerId( $this->id ); From ca4df2ca5900b4f5b20e7c622ec0a0d2a171d3ab Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 12:22:49 +0000 Subject: [PATCH 08/13] Limit campaign results when per_page is set --- src/API/Google/AdsCampaign.php | 17 ++++++++++++----- src/API/Google/Query/AdsQuery.php | 10 ++++++++++ .../Site/Controllers/Ads/CampaignController.php | 4 ++-- .../Tools/HelperTrait/GoogleAdsClientTrait.php | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/API/Google/AdsCampaign.php b/src/API/Google/AdsCampaign.php index 24ebb4650b..728c8b4b08 100644 --- a/src/API/Google/AdsCampaign.php +++ b/src/API/Google/AdsCampaign.php @@ -106,13 +106,14 @@ public function __construct( GoogleAdsClient $client, AdsCampaignBudget $budget, /** * Returns a list of campaigns with targeted locations retrieved from campaign criterion. * - * @param bool $exclude_removed Exclude removed campaigns (default true). - * @param bool $fetch_criterion Combine the campaign data with criterion data (default true). + * @param bool $exclude_removed Exclude removed campaigns (default true). + * @param bool $fetch_criterion Combine the campaign data with criterion data (default true). + * @param array $args Arguments for fetching campaigns, for example: per_page for limiting the number of results. * * @return array * @throws ExceptionWithResponseData When an ApiException is caught. */ - public function get_campaigns( bool $exclude_removed = true, bool $fetch_criterion = true ): array { + public function get_campaigns( bool $exclude_removed = true, bool $fetch_criterion = true, array $args = [] ): array { try { $query = ( new AdsCampaignQuery() )->set_client( $this->client, $this->options->get_ads_id() ); @@ -120,18 +121,24 @@ public function get_campaigns( bool $exclude_removed = true, bool $fetch_criteri $query->where( 'campaign.status', 'REMOVED', '!=' ); } - $campaign_count = 0; + $count = 0; $campaign_results = $query->get_results(); $converted_campaigns = []; foreach ( $campaign_results->iterateAllElements() as $row ) { - ++$campaign_count; + ++$count; $campaign = $this->convert_campaign( $row ); $converted_campaigns[ $campaign['id'] ] = $campaign; + + // Break early if we request a limited result. + if ( ! empty( $args['per_page'] ) && $count >= $args['per_page'] ) { + break; + } } if ( $exclude_removed ) { // Cache campaign count. + $campaign_count = $campaign_results->getPage()->getResponseObject()->getTotalResultsCount(); $this->container->get( TransientsInterface::class )->set( TransientsInterface::ADS_CAMPAIGN_COUNT, $campaign_count, diff --git a/src/API/Google/Query/AdsQuery.php b/src/API/Google/Query/AdsQuery.php index 09d416c0fe..0bfa42a314 100644 --- a/src/API/Google/Query/AdsQuery.php +++ b/src/API/Google/Query/AdsQuery.php @@ -7,6 +7,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads\GoogleAdsClient; use Google\Ads\GoogleAds\V18\Services\GoogleAdsRow; use Google\Ads\GoogleAds\V18\Services\SearchGoogleAdsRequest; +use Google\Ads\GoogleAds\V18\Services\SearchSettings; use Google\ApiCore\ApiException; defined( 'ABSPATH' ) || exit; @@ -97,6 +98,15 @@ protected function query_results() { $request->setPageToken( $this->search_args['pageToken'] ); } + // Allow us to get the total number of results. + $request->setSearchSettings( + new SearchSettings( + [ + 'return_total_results_count' => true, + ] + ) + ); + $request->setQuery( $this->build_query() ); $request->setCustomerId( $this->id ); diff --git a/src/API/Site/Controllers/Ads/CampaignController.php b/src/API/Site/Controllers/Ads/CampaignController.php index 1cd67ec7e4..b57f161ff7 100644 --- a/src/API/Site/Controllers/Ads/CampaignController.php +++ b/src/API/Site/Controllers/Ads/CampaignController.php @@ -106,7 +106,7 @@ function ( $campaign ) use ( $request ) { $data = $this->prepare_item_for_response( $campaign, $request ); return $this->prepare_response_for_collection( $data ); }, - $this->ads_campaign->get_campaigns( $exclude_removed ) + $this->ads_campaign->get_campaigns( $exclude_removed, true, $request->get_params() ) ); } catch ( Exception $e ) { return $this->response_from_exception( $e ); @@ -326,7 +326,7 @@ public function get_collection_params(): array { 'description' => __( 'Maximum number of rows to be returned in result data.', 'google-listings-and-ads' ), 'type' => 'integer', 'minimum' => 1, - 'maximum' => 1000, + 'maximum' => 10000, 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg', ], diff --git a/tests/Tools/HelperTrait/GoogleAdsClientTrait.php b/tests/Tools/HelperTrait/GoogleAdsClientTrait.php index 6d8a9dd876..d53ff10ae5 100644 --- a/tests/Tools/HelperTrait/GoogleAdsClientTrait.php +++ b/tests/Tools/HelperTrait/GoogleAdsClientTrait.php @@ -199,6 +199,14 @@ protected function generate_ads_campaign_query_mock( array $campaigns_responses, $campaign_criterion_row_mock ); + $response_object = $this->createMock( SearchGoogleAdsResponse::class ); + $response_object->method( 'getTotalResultsCount' )->willReturn( count( $campaigns_responses ) ); + + $page = $this->createMock( Page::class ); + $page->method( 'getResponseObject' )->willReturn( $response_object ); + + $list_response->method( 'getPage' )->willReturn( $page ); + $this->service_client ->method( 'search' )->willReturn( $list_response ); } @@ -314,6 +322,14 @@ protected function generate_ads_campaign_query_mock_with_no_campaigns() { $list_response = $this->createMock( PagedListResponse::class ); $list_response->method( 'iterateAllElements' )->willReturn( [] ); + $response_object = $this->createMock( SearchGoogleAdsResponse::class ); + $response_object->method( 'getTotalResultsCount' )->willReturn( 0 ); + + $page = $this->createMock( Page::class ); + $page->method( 'getResponseObject' )->willReturn( $response_object ); + + $list_response->method( 'getPage' )->willReturn( $page ); + // Method search() will only be called once by AdsCampaignQuery // since there were no campaigns returned by AdsCampaignQuery, it // won't be calling AdsCampaignCriterionQuery then. From bab9b0f9067468b34703e189d94b4a4fc7a8bfc8 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 12:41:16 +0000 Subject: [PATCH 09/13] Add test to fetch limited results from campaigns. --- tests/Unit/API/Google/AdsCampaignTest.php | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Unit/API/Google/AdsCampaignTest.php b/tests/Unit/API/Google/AdsCampaignTest.php index c40859d942..27ba8b4f33 100644 --- a/tests/Unit/API/Google/AdsCampaignTest.php +++ b/tests/Unit/API/Google/AdsCampaignTest.php @@ -141,6 +141,39 @@ public function test_get_campaigns() { $this->assertEquals( $campaigns_data, $this->campaign->get_campaigns() ); } + public function test_get_campaigns_with_limited_results() { + $campaigns_data = [ + [ + 'id' => self::TEST_CAMPAIGN_ID, + 'name' => 'Campaign One', + 'status' => 'paused', + 'type' => 'shopping', + 'amount' => 10, + 'country' => 'US', + 'targeted_locations' => [], + ], + [ + 'id' => 5678901234, + 'name' => 'Campaign Two', + 'status' => 'enabled', + 'type' => 'performance_max', + 'amount' => 20, + 'country' => 'UK', + 'targeted_locations' => [], + ], + ]; + + $this->generate_ads_campaign_query_mock( $campaigns_data, [] ); + $this->assertEquals( + array_slice( $campaigns_data, 0, 1 ), // Only expect one result. + $this->campaign->get_campaigns( + true, + true, + [ 'per_page' => 1 ], + ) + ); + } + public function test_get_campaigns_with_nonexist_location_id() { $campaign_criterion_data = [ [ From c5cd9ba0842a3fb9a64bf99330adc40f6e070ff2 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 13:11:10 +0000 Subject: [PATCH 10/13] Limit to only one group asset without using pageSize parameter --- src/API/Google/AdsAssetGroup.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/API/Google/AdsAssetGroup.php b/src/API/Google/AdsAssetGroup.php index 39cec9c0c9..bd1604b089 100644 --- a/src/API/Google/AdsAssetGroup.php +++ b/src/API/Google/AdsAssetGroup.php @@ -49,11 +49,6 @@ class AdsAssetGroup implements OptionsAwareInterface { */ protected const TEMPORARY_ID = -3; - /** - * The page size for the AdsAssetGroupQuery. - */ - protected const PAGE_SIZE = 1; - /** * The Google Ads Client. * @@ -226,7 +221,7 @@ protected function temporary_resource_name() { } /** - * Get Asset Groups for a specific campaign. + * Get Asset Groups for a specific campaign. Limit to first AdsAssetGroup. * * @since 2.4.0 * @@ -240,7 +235,7 @@ public function get_asset_groups_by_campaign_id( int $campaign_id, bool $include try { $asset_groups_converted = []; - $asset_group_results = ( new AdsAssetGroupQuery( [ 'pageSize' => self::PAGE_SIZE ] ) ) + $asset_group_results = ( new AdsAssetGroupQuery() ) ->set_client( $this->client, $this->options->get_ads_id() ) ->add_columns( [ 'asset_group.path1', 'asset_group.path2', 'asset_group.id', 'asset_group.final_urls' ] ) ->where( 'campaign.id', $campaign_id ) @@ -250,6 +245,7 @@ public function get_asset_groups_by_campaign_id( int $campaign_id, bool $include /** @var GoogleAdsRow $row */ foreach ( $asset_group_results->getPage()->getIterator() as $row ) { $asset_groups_converted[ $row->getAssetGroup()->getId() ] = $this->convert_asset_group( $row ); + break; // Limit to only first asset group. } if ( $include_assets ) { From 2497604253b0fe3f481d4f6c12a6cd523dc7f46a Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 13:34:55 +0000 Subject: [PATCH 11/13] Tests for only one group asset --- tests/Unit/API/Google/AdsAssetGroupTest.php | 23 ++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/Unit/API/Google/AdsAssetGroupTest.php b/tests/Unit/API/Google/AdsAssetGroupTest.php index b5d925b17f..c6c1005354 100644 --- a/tests/Unit/API/Google/AdsAssetGroupTest.php +++ b/tests/Unit/API/Google/AdsAssetGroupTest.php @@ -90,14 +90,17 @@ public function test_get_asset_groups_by_campaign_id_with_assets() { self::TEST_ASSET_GROUP_ID => [ 'description' => [ 'id' => 22222, - 'content' => 'description 1', + 'content' => 'description text', + ], + 'headline' => [ + 'id' => 33333, + 'content' => 'headline text', ], - ], self::TEST_ASSET_GROUP_ID_2 => [ 'headline' => [ - 'id' => 33333, - 'content' => 'description 1', + 'id' => 44444, + 'content' => 'headline text', ], ], ]; @@ -119,11 +122,14 @@ public function test_get_asset_groups_by_campaign_id_with_assets() { $this->asset_group_asset->expects( $this->exactly( 1 ) ) ->method( 'get_assets_by_asset_group_ids' ) - ->with( [ self::TEST_ASSET_GROUP_ID, self::TEST_ASSET_GROUP_ID_2 ] ) + ->with( [ self::TEST_ASSET_GROUP_ID ] ) // Only fetch assets for first group. ->willReturn( $assets_data ); $this->generate_ads_asset_groups_query_mock( $asset_group_data ); - $this->assertEquals( $asset_group_data, $this->asset_group->get_asset_groups_by_campaign_id( self::TEST_CAMPAIGN_ID ) ); + $this->assertEquals( + array_slice( $asset_group_data, 0, 1 ), // Only expect one asset group. + $this->asset_group->get_asset_groups_by_campaign_id( self::TEST_CAMPAIGN_ID ) + ); } public function test_get_asset_groups_by_campaign_id_without_assets() { @@ -145,7 +151,10 @@ public function test_get_asset_groups_by_campaign_id_without_assets() { ->method( 'get_assets_by_asset_group_ids' ); $this->generate_ads_asset_groups_query_mock( $asset_group_data ); - $this->assertEquals( $asset_group_data, $this->asset_group->get_asset_groups_by_campaign_id( self::TEST_CAMPAIGN_ID, $include_assets ) ); + $this->assertEquals( + array_slice( $asset_group_data, 0, 1 ), // Only expect one asset group. + $this->asset_group->get_asset_groups_by_campaign_id( self::TEST_CAMPAIGN_ID, $include_assets ) + ); } public function test_edit_asset_group_with_asset() { From 3762038b1f2119d4adea55b70e615d6cb0092824 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 16:13:34 +0000 Subject: [PATCH 12/13] Increase coverage for Ads Services --- tests/Unit/API/Google/AdsTest.php | 85 +++++++++++++++++++++++++++++++ tests/Unit/Ads/AdsServiceTest.php | 27 ++++++++++ 2 files changed, 112 insertions(+) diff --git a/tests/Unit/API/Google/AdsTest.php b/tests/Unit/API/Google/AdsTest.php index 7c58a3fbee..e3eebb6567 100644 --- a/tests/Unit/API/Google/AdsTest.php +++ b/tests/Unit/API/Google/AdsTest.php @@ -137,6 +137,19 @@ public function test_get_ads_accounts_exception() { } } + public function test_get_ads_accounts_details_exception() { + $this->generate_customer_list_mock( + [ + 'customers/' . self::TEST_ADS_ID, + ] + ); + + $this->generate_ads_query_mock_exception( new ApiException( 'no customer details available', 14, 'UNAVAILABLE' ) ); + + // Get an empty list when not able to query customer details. + $this->assertEquals( [], $this->ads->get_ads_accounts() ); + } + public function test_get_billing_status_no_ads_id() { $this->options->expects( $this->once() ) ->method( 'get_ads_id' ) @@ -248,6 +261,40 @@ public function test_get_ads_currency() { $this->assertEquals( self::TEST_CURRENCY, $this->ads->get_ads_currency() ); } + public function test_get_ads_currency_and_request_ads_currency() { + $this->options->method( 'get_ads_id' )->willReturn( self::TEST_ADS_ID ); + + $invoked_count = $this->exactly( 2 ); + $this->options->expects( $invoked_count ) + ->method( 'get' ) + ->willReturnCallback( + function ( string $option ) use ( $invoked_count ) { + if ( $option === OptionsInterface::ADS_ACCOUNT_CURRENCY ) { + if ( 1 === $invoked_count->getInvocationCount() ) { + return false; + } + + if ( 2 === $invoked_count->getInvocationCount() ) { + return self::TEST_CURRENCY; + } + } + } + ); + + $this->generate_customers_mock( + [ + [ 'currency' => self::TEST_CURRENCY ], + ] + ); + + $this->options->expects( $this->once() ) + ->method( 'update' ) + ->with( OptionsInterface::ADS_ACCOUNT_CURRENCY, self::TEST_CURRENCY ) + ->willReturn( true ); + + $this->assertEquals( self::TEST_CURRENCY, $this->ads->get_ads_currency() ); + } + public function test_request_ads_currency() { $this->options->method( 'get_ads_id' )->willReturn( self::TEST_ADS_ID ); $this->generate_customers_mock( @@ -305,6 +352,22 @@ public function test_update_ads_id() { $this->assertTrue( $this->ads->update_ads_id( self::TEST_ADS_ID ) ); } + public function test_ads_id_exists() { + $this->options->expects( $this->once() ) + ->method( 'get' ) + ->with( OptionsInterface::ADS_ID ) + ->willReturn( self::TEST_ADS_ID ); + $this->assertTrue( $this->ads->ads_id_exists() ); + } + + public function test_ads_id_does_not_exist() { + $this->options->expects( $this->once() ) + ->method( 'get' ) + ->with( OptionsInterface::ADS_ID ) + ->willReturn( false ); + $this->assertFalse( $this->ads->ads_id_exists() ); + } + public function test_update_billing_url() { $this->options->expects( $this->once() ) ->method( 'update' ) @@ -312,4 +375,26 @@ public function test_update_billing_url() { ->willReturn( true ); $this->assertTrue( $this->ads->update_billing_url( self::TEST_BILLING_URL ) ); } + + public function test_update_ocid_from_billing_url_no_query_string() { + $this->assertFalse( + $this->ads->update_ocid_from_billing_url( self::TEST_BILLING_URL ) + ); + } + + public function test_update_ocid_from_billing_url_no_ocid() { + $this->assertFalse( + $this->ads->update_ocid_from_billing_url( self::TEST_BILLING_URL . '?foo=bar' ) + ); + } + + public function test_update_ocid_from_billing_url() { + $this->options->expects( $this->once() ) + ->method( 'update' ) + ->with( OptionsInterface::ADS_ACCOUNT_OCID, 12345 ) + ->willReturn( true ); + $this->assertTrue( + $this->ads->update_ocid_from_billing_url( self::TEST_BILLING_URL . '?ocid=12345' ) + ); + } } diff --git a/tests/Unit/Ads/AdsServiceTest.php b/tests/Unit/Ads/AdsServiceTest.php index 90c3b04c3f..e070a01863 100644 --- a/tests/Unit/Ads/AdsServiceTest.php +++ b/tests/Unit/Ads/AdsServiceTest.php @@ -66,6 +66,33 @@ public function test_is_setup_started_already_completed() { $this->assertFalse( $this->ads_service->is_setup_started() ); } + public function test_is_not_connected() { + $this->options->method( 'get' ) + ->with( OptionsInterface::GOOGLE_CONNECTED ) + ->willReturn( false ); + + $this->assertFalse( $this->ads_service->is_connected() ); + } + + public function test_is_connected() { + $invoked_count = $this->exactly( 2 ); + $this->options->expects( $invoked_count ) + ->method( 'get' ) + ->willReturnCallback( + function ( string $option ) use ( $invoked_count ) { + if ( $option === OptionsInterface::GOOGLE_CONNECTED && 1 === $invoked_count->getInvocationCount() ) { + return true; + } + + if ( $option === OptionsInterface::ADS_SETUP_COMPLETED_AT && 2 === $invoked_count->getInvocationCount() ) { + return true; + } + } + ); + + $this->assertTrue( $this->ads_service->is_connected() ); + } + public function test_connected_account_without_ads_id() { $this->options->method( 'get_ads_id' )->willReturn( 0 ); From 59a62224a21cc11cbf5953287d793176dff248e6 Mon Sep 17 00:00:00 2001 From: mikkamp Date: Thu, 19 Dec 2024 17:31:03 +0000 Subject: [PATCH 13/13] Hide pagination for list of campaigns --- js/src/pages/dashboard/all-programs-table-card/index.scss | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/src/pages/dashboard/all-programs-table-card/index.scss b/js/src/pages/dashboard/all-programs-table-card/index.scss index 019c1e2cc7..4075203f27 100644 --- a/js/src/pages/dashboard/all-programs-table-card/index.scss +++ b/js/src/pages/dashboard/all-programs-table-card/index.scss @@ -5,6 +5,12 @@ } } + .components-card-footer { + .woocommerce-pagination { + display: none; + } + } + .program-actions { display: flex; justify-content: space-between;