From d618000592167255a9b595026cd8f805e50dc2a9 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Tue, 15 Oct 2024 16:20:04 +0300 Subject: [PATCH 1/2] add columns to the semrush api request --- src/actions/semrush/semrush-phrases-action.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/semrush/semrush-phrases-action.php b/src/actions/semrush/semrush-phrases-action.php index 3c702245a65..0212589c00e 100644 --- a/src/actions/semrush/semrush-phrases-action.php +++ b/src/actions/semrush/semrush-phrases-action.php @@ -51,7 +51,7 @@ public function get_related_keyphrases( $keyphrase, $database ) { $transient_key = \sprintf( static::TRANSIENT_CACHE_KEY, $keyphrase, $database ); $transient = \get_transient( $transient_key ); - if ( $transient !== false ) { + if ( $transient !== false && \count( $transient['data']['columnNames'] ) === 5 ) { return $this->to_result_object( $transient ); } @@ -59,7 +59,7 @@ public function get_related_keyphrases( $keyphrase, $database ) { 'params' => [ 'phrase' => $keyphrase, 'database' => $database, - 'export_columns' => 'Ph,Nq,Td', + 'export_columns' => 'Ph,Nq,Td,In,Kd', 'display_limit' => 10, 'display_offset' => 0, 'display_sort' => 'nq_desc', From 08b3b2bba84e8e3808235a890b6bfc33fd4d1b8f Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Tue, 15 Oct 2024 16:42:18 +0300 Subject: [PATCH 2/2] fix test --- src/actions/semrush/semrush-phrases-action.php | 2 +- .../Actions/SEMrush/SEMrush_Phrases_Action_Test.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/actions/semrush/semrush-phrases-action.php b/src/actions/semrush/semrush-phrases-action.php index 0212589c00e..2586db9bc4f 100644 --- a/src/actions/semrush/semrush-phrases-action.php +++ b/src/actions/semrush/semrush-phrases-action.php @@ -51,7 +51,7 @@ public function get_related_keyphrases( $keyphrase, $database ) { $transient_key = \sprintf( static::TRANSIENT_CACHE_KEY, $keyphrase, $database ); $transient = \get_transient( $transient_key ); - if ( $transient !== false && \count( $transient['data']['columnNames'] ) === 5 ) { + if ( $transient !== false && isset( $transient['data']['columnNames'] ) && \count( $transient['data']['columnNames'] ) === 5 ) { return $this->to_result_object( $transient ); } diff --git a/tests/Unit/Actions/SEMrush/SEMrush_Phrases_Action_Test.php b/tests/Unit/Actions/SEMrush/SEMrush_Phrases_Action_Test.php index f8d8b725d00..e4be85ce41f 100644 --- a/tests/Unit/Actions/SEMrush/SEMrush_Phrases_Action_Test.php +++ b/tests/Unit/Actions/SEMrush/SEMrush_Phrases_Action_Test.php @@ -77,7 +77,7 @@ public function test_get_related_keyphrases_from_api() { 'params' => [ 'phrase' => $keyphrase, 'database' => $country_code, - 'export_columns' => 'Ph,Nq,Td', + 'export_columns' => 'Ph,Nq,Td,In,Kd', 'display_limit' => 10, 'display_offset' => 0, 'display_sort' => 'nq_desc', @@ -131,8 +131,8 @@ public function test_get_related_keyphrases_from_cache() { ->andReturn( [ 'data' => [ - 'column_names' => [], - 'rows' => [], + 'columnNames' => [ 'Ph', 'Nq', 'Td', 'In', 'Kd' ], + 'rows' => [], ], 'status' => 200, ] @@ -145,8 +145,8 @@ public function test_get_related_keyphrases_from_cache() { $this->assertEquals( (object) [ 'results' => [ - 'column_names' => [], - 'rows' => [], + 'columnNames' => [ 'Ph', 'Nq', 'Td', 'In', 'Kd' ], + 'rows' => [], ], 'status' => 200, ],