Skip to content

Commit

Permalink
Add tests for the new method.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-manuilov committed Mar 29, 2023
1 parent 2a2d97e commit 97e835a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/phpunit/integration/Modules/Analytics_4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Google\Site_Kit\Core\Modules\Module_With_Service_Entity;
use Google\Site_Kit\Core\Modules\Modules;
use Google\Site_Kit\Core\Permissions\Permissions;
use Google\Site_Kit\Core\REST_API\Data_Request;
use Google\Site_Kit\Core\Storage\Options;
use Google\Site_Kit\Core\Storage\User_Options;
use Google\Site_Kit\Modules\Analytics;
Expand All @@ -37,6 +38,8 @@
use Google\Site_Kit\Tests\TestCase;
use Google\Site_Kit\Tests\UserAuthenticationTrait;
use Google\Site_Kit_Dependencies\Google\Service\Exception;
use Google\Site_Kit_Dependencies\Google\Service\AnalyticsData\RunReportResponse;
use Google\Site_Kit_Dependencies\Google\Service\AnalyticsData\MetricHeader;
use Google\Site_Kit_Dependencies\Google\Service\GoogleAnalyticsAdmin\GoogleAnalyticsAdminV1betaConversionEvent;
use Google\Site_Kit_Dependencies\Google\Service\GoogleAnalyticsAdmin\GoogleAnalyticsAdminV1betaDataStream;
use Google\Site_Kit_Dependencies\Google\Service\GoogleAnalyticsAdmin\GoogleAnalyticsAdminV1betaDataStreamWebStreamData;
Expand Down Expand Up @@ -1142,6 +1145,44 @@ public function test_get_report__dimensions_as_single_object( $access_token ) {
);
}

public function test_get_report__missing_rows() {
$report_args = array(
'startDate' => '2023-02-01',
'endDate' => '2023-02-03',
'compareStartDate' => '2023-01-01',
'compareEndDate' => '2023-01-03',
'dimensions' => 'date',
);

$first_metric = new MetricHeader();
$first_metric->setType( 'TYPE_INTEGER' );

$second_metric = new MetricHeader();
$second_metric->setType( 'TYPE_KILOMETERS' );

$data = new Data_Request( '', '', '', '', $report_args );
$response = new RunReportResponse();
$response->setMetricHeaders( array( $first_metric, $second_metric ) );

$reflected_parse_report_response_method = new \ReflectionMethod( Analytics_4::class, 'parse_report_response' );
$reflected_parse_report_response_method->setAccessible( true );
$response = $reflected_parse_report_response_method->invoke( $this->analytics, $data, $response );

$this->assertEquals( 6, $response->getRowCount() );

foreach ( $response->getRows() as $i => $row ) {
$date = strtotime( $i < 3 ? '2023-02-01' : '2023-01-01' ) + ( $i % 3 ) * DAY_IN_SECONDS;
$date = gmdate( 'Ymd', $date );

$dimension_values = $row->getDimensionValues();
$this->assertEquals( $date, $dimension_values[0]->getValue() );

$metric_values = $row->getMetricValues();
$this->assertEquals( 0, $metric_values[0]->getValue() );
$this->assertNull( $metric_values[1]->getValue() );
}
}

/**
* @dataProvider data_access_token
*
Expand Down

0 comments on commit 97e835a

Please sign in to comment.