Skip to content

Commit

Permalink
QueryDownloadControllerTest throws deprecation error (#4104)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m committed Jan 26, 2024
1 parent aff77c6 commit 5a99938
Showing 1 changed file with 5 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
use Drupal\metastore\Storage\DataFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\common\Storage\SelectFactory;
use Drupal\Core\Database\Query\Select;
use Drupal\Tests\common\Unit\Connection;

/**
*
* @group dkan
* @group datastore
*/
class QueryDownloadControllerTest extends TestCase {

Expand All @@ -46,8 +46,6 @@ protected function setUp(): void {
->add(ContainerInterface::class, 'get', $options)
->add(CacheContextsManager::class, 'assertValidTokens', TRUE);
\Drupal::setContainer($chain->getMock());
$this->selectFactory = $this->getSelectFactory();

}

protected function tearDown(): void {
Expand All @@ -60,19 +58,13 @@ protected function tearDown(): void {
*/
private function queryResultCompare($data, $resource = NULL) {
$request = $this->mockRequest($data);
$dataDictionaryFields = [
'name' => 'date',
'type' => 'date',
'format '=>'%m/%d/%Y'
];
$qController = QueryController::create($this->getQueryContainer(500));
$response = $resource ? $qController->queryResource($resource, $request) : $qController->query($request);
$csv = $response->getContent();

$dController = QueryDownloadController::create($this->getQueryContainer(25));
ob_start(['self', 'getBuffer']);
ob_start([self::class, 'getBuffer']);
$streamResponse = $resource ? $dController->queryResource($resource, $request) : $dController->query($request);
$streamResponse->dataDictionaryFields = $dataDictionaryFields;
$streamResponse->sendContent();
$streamedCsv = $this->buffer;
ob_get_clean();
Expand All @@ -98,35 +90,6 @@ public function testStreamedQueryCsv() {
$this->queryResultCompare($data);
}

public function queryResultReformatted($data){
$request = $this->mockRequest($data);
$dataDictionaryFields = [
'name' => 'date',
'type' => 'date',
'format '=>'%m/%d/%Y'
];
$qController = QueryController::create($this->getQueryContainer(500));
$response = $qController->query($request);
$csv = $response->getContent();

$dController = QueryDownloadController::create($this->getQueryContainer(25));
ob_start(['self', 'getBuffer']);
$streamResponse = $dController->query($request);
$streamResponse->dataDictionaryFields = $dataDictionaryFields;
//$streamResponse->sendContent();
$this->selectFactory->create($streamResponse);

$this->assertEquals(count(explode("\n", $csv)), count(explode("\n", $streamedCsv)));
$this->assertEquals($csv, $streamedCsv);
}

/**
*
*/
private function getSelectFactory() {
return new SelectFactory($this->getConnection());
}

/**
*
*/
Expand Down Expand Up @@ -282,7 +245,7 @@ public function testStreamedLimit() {
$container = $this->getQueryContainer($pageLimit);
$downloadController = QueryDownloadController::create($container);
$request = $this->mockRequest($data);
ob_start(['self', 'getBuffer']);
ob_start([self::class, 'getBuffer']);
$streamResponse = $downloadController->query($request);
$this->assertEquals(200, $streamResponse->getStatusCode());
$streamResponse->sendContent();
Expand Down Expand Up @@ -371,7 +334,7 @@ public function testStreamedBadSchema() {
];
$request = $this->mockRequest($data);
$dController = QueryDownloadController::create($this->getQueryContainer(25));
ob_start(['self', 'getBuffer']);
ob_start([self::class, 'getBuffer']);
$streamResponse = $dController->query($request);
$streamResponse->sendContent();
$streamedCsv = $this->buffer;
Expand Down

0 comments on commit 5a99938

Please sign in to comment.