Commit d5e48efe authored by catch's avatar catch

Issue #2872151 by Lendude, phenaproxima, dawehner: Database/DrupalKernel:...

Issue #2872151 by Lendude, phenaproxima, dawehner: Database/DrupalKernel: Convert system functional tests to PHPUnit
parent 7c486399
......@@ -2,11 +2,16 @@
namespace Drupal\system\Tests\Database;
@trigger_error(__NAMESPACE__ . '\DatabaseWebTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\system\Functional\Database\DatabaseTestBase', E_USER_DEPRECATED);
use Drupal\KernelTests\Core\Database\DatabaseTestBase;
use Drupal\simpletest\WebTestBase;
/**
* Base class for databases database tests.
*
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead
* use \Drupal\Tests\system\Functional\Database\DatabaseTestBase.
*/
abstract class DatabaseWebTestBase extends WebTestBase {
......
......@@ -2,11 +2,16 @@
namespace Drupal\system\Tests\Database;
@trigger_error(__NAMESPACE__ . '\FakeRecord is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\system\Functional\Database\FakeRecord', E_USER_DEPRECATED);
/**
* Fetches into a class.
*
* PDO supports using a new instance of an arbitrary class for records
* rather than just a stdClass or array. This class is for testing that
* functionality. (See testQueryFetchClass() below)
*
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead
* use \Drupal\Tests\system\Functional\Database\FakeRecord.
*/
class FakeRecord { }
<?php
namespace Drupal\Tests\system\Functional\Database;
use Drupal\KernelTests\Core\Database\DatabaseTestBase as DatabaseKernelTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Base class for databases database tests.
*/
abstract class DatabaseTestBase extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['database_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
DatabaseKernelTestBase::addSampleData();
}
}
<?php
namespace Drupal\Tests\system\Functional\Database;
/**
* Fetches into a class.
*
* PDO supports using a new instance of an arbitrary class for records
* rather than just a stdClass or array. This class is for testing that
* functionality. (See testQueryFetchClass() below)
*/
class FakeRecord {}
<?php
namespace Drupal\system\Tests\Database;
namespace Drupal\Tests\system\Functional\Database;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -8,7 +9,7 @@
*
* @group Database
*/
class SelectPagerDefaultTest extends DatabaseWebTestBase {
class SelectPagerDefaultTest extends DatabaseTestBase {
/**
* Confirms that a pager query returns the correct results.
......@@ -34,13 +35,13 @@ public function testEvenPagerQuery() {
for ($page = 0; $page <= $num_pages; ++$page) {
$this->drupalGet('database_test/pager_query_even/' . $limit, ['query' => ['page' => $page]]);
$data = json_decode($this->getRawContent());
$data = json_decode($this->getSession()->getPage()->getContent());
if ($page == $num_pages) {
$correct_number = $count - ($limit * $page);
}
$this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number]));
$this->assertCount($correct_number, $data->names, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number]));
}
}
......@@ -68,13 +69,13 @@ public function testOddPagerQuery() {
for ($page = 0; $page <= $num_pages; ++$page) {
$this->drupalGet('database_test/pager_query_odd/' . $limit, ['query' => ['page' => $page]]);
$data = json_decode($this->getRawContent());
$data = json_decode($this->getSession()->getPage()->getContent());
if ($page == $num_pages) {
$correct_number = $count - ($limit * $page);
}
$this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number]));
$this->assertCount($correct_number, $data->names, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number]));
}
}
......
<?php
namespace Drupal\system\Tests\Database;
namespace Drupal\Tests\system\Functional\Database;
/**
* Tests the tablesort query extender.
*
* @group Database
*/
class SelectTableSortDefaultTest extends DatabaseWebTestBase {
class SelectTableSortDefaultTest extends DatabaseTestBase {
/**
* Confirms that a tablesort query returns the correct results.
......@@ -27,7 +27,7 @@ public function testTableSortQuery() {
foreach ($sorts as $sort) {
$this->drupalGet('database_test/tablesort/', ['query' => ['order' => $sort['field'], 'sort' => $sort['sort']]]);
$data = json_decode($this->getRawContent());
$data = json_decode($this->getSession()->getPage()->getContent());
$first = array_shift($data->tasks);
$last = array_pop($data->tasks);
......@@ -55,7 +55,7 @@ public function testTableSortQueryFirst() {
foreach ($sorts as $sort) {
$this->drupalGet('database_test/tablesort_first/', ['query' => ['order' => $sort['field'], 'sort' => $sort['sort']]]);
$data = json_decode($this->getRawContent());
$data = json_decode($this->getSession()->getPage()->getContent());
$first = array_shift($data->tasks);
$last = array_pop($data->tasks);
......@@ -72,16 +72,18 @@ public function testTableSortQueryFirst() {
* are correct.
*/
public function testTableSortDefaultSort() {
$assert = $this->assertSession();
$this->drupalGet('database_test/tablesort_default_sort');
// Verify that the table was displayed. Just the header is checked for
// because if there were any fatal errors or exceptions in displaying the
// sorted table, it would not print the table.
$this->assertText(t('Username'));
$assert->pageTextContains(t('Username'));
// Verify that the header links are built properly.
$this->assertLinkByHref('database_test/tablesort_default_sort');
$this->assertPattern('/\<a.*title\=\"' . t('sort by Username') . '\".*\>/');
$assert->linkByHrefExists('database_test/tablesort_default_sort');
$assert->responseMatches('/\<a.*title\=\"' . t('sort by Username') . '\".*\>/');
}
}
<?php
namespace Drupal\system\Tests\Database;
namespace Drupal\Tests\system\Functional\Database;
/**
* Tests the temporary query functionality.
*
* @group Database
*/
class TemporaryQueryTest extends DatabaseWebTestBase {
class TemporaryQueryTest extends DatabaseTestBase {
/**
* Modules to enable.
*
* @var array
* {@inheritdoc}
*/
public static $modules = ['database_test'];
......@@ -28,7 +26,7 @@ public function countTableRows($table_name) {
*/
public function testTemporaryQuery() {
$this->drupalGet('database_test/db_query_temporary');
$data = json_decode($this->getRawContent());
$data = json_decode($this->getSession()->getPage()->getContent());
if ($data) {
$this->assertEqual($this->countTableRows('test'), $data->row_count, 'The temporary table contains the correct amount of rows.');
$this->assertFalse(db_table_exists($data->table_name), 'The temporary table is, indeed, temporary.');
......
<?php
namespace Drupal\system\Tests\DrupalKernel;
namespace Drupal\Tests\system\Functional\DrupalKernel;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Ensures that the container rebuild works as expected.
*
* @group DrupalKernel
*/
class ContainerRebuildWebTest extends WebTestBase {
class ContainerRebuildWebTest extends BrowserTestBase {
/**
* {@inheritdoc}
......@@ -20,36 +20,40 @@ class ContainerRebuildWebTest extends WebTestBase {
* Sets a different deployment identifier.
*/
public function testSetContainerRebuildWithDifferentDeploymentIdentifier() {
$assert = $this->assertSession();
// Ensure the parameter is not set.
$this->drupalGet('<front>');
$this->assertHeader('container_rebuild_indicator', FALSE);
$assert->responseHeaderEquals('container_rebuild_indicator', NULL);
$this->writeSettings(['settings' => ['deployment_identifier' => (object) ['value' => 'new-identifier', 'required' => TRUE]]]);
$this->drupalGet('<front>');
$this->assertHeader('container_rebuild_indicator', 'new-identifier');
$assert->responseHeaderEquals('container_rebuild_indicator', 'new-identifier');
}
/**
* Tests container invalidation.
*/
public function testContainerInvalidation() {
$assert = $this->assertSession();
// Ensure that parameter is not set.
$this->drupalGet('<front>');
$this->assertHeader('container_rebuild_test_parameter', FALSE);
$assert->responseHeaderEquals('container_rebuild_test_parameter', NULL);
// Ensure that after setting the parameter, without a container rebuild the
// parameter is still not set.
$this->writeSettings(['settings' => ['container_rebuild_test_parameter' => (object) ['value' => 'rebuild_me_please', 'required' => TRUE]]]);
$this->drupalGet('<front>');
$this->assertHeader('container_rebuild_test_parameter', FALSE);
$assert->responseHeaderEquals('container_rebuild_test_parameter', NULL);
// Ensure that after container invalidation the parameter is set.
\Drupal::service('kernel')->invalidateContainer();
$this->drupalGet('<front>');
$this->assertHeader('container_rebuild_test_parameter', 'rebuild_me_please');
$assert->responseHeaderEquals('container_rebuild_test_parameter', 'rebuild_me_please');
}
}
......@@ -4,7 +4,7 @@
use Drupal\Core\Database\RowCountException;
use Drupal\Core\Database\StatementInterface;
use Drupal\system\Tests\Database\FakeRecord;
use Drupal\Tests\system\Functional\Database\FakeRecord;
/**
* Tests the Database system's various fetch capabilities.
......@@ -69,7 +69,7 @@ public function testQueryFetchArray() {
*/
public function testQueryFetchClass() {
$records = [];
$result = db_query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => 'Drupal\system\Tests\Database\FakeRecord']);
$result = db_query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => FakeRecord::class]);
foreach ($result as $record) {
$records[] = $record;
if ($this->assertTrue($record instanceof FakeRecord, 'Record is an object of class FakeRecord.')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment