diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php b/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php new file mode 100644 index 0000000..efd9f5a --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php @@ -0,0 +1,212 @@ + 'Basic test table for Views tests.', + 'fields' => array( + 'id' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'name' => array( + 'description' => "A person's name", + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'age' => array( + 'description' => "The person's age", + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0), + 'job' => array( + 'description' => "The person's job", + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => 'Undefined', + ), + 'created' => array( + 'description' => "The creation date of this record", + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('id'), + 'unique keys' => array( + 'name' => array('name') + ), + 'indexes' => array( + 'ages' => array('age'), + ), + ); + return $schema; + } + + /** + * The views data definition. + */ + public static function viewsData() { + // Declaration of the base table. + $data['views_test_data']['table'] = array( + 'group' => t('Views test'), + 'base' => array( + 'field' => 'id', + 'title' => t('Views test data'), + 'help' => t('Users who have created accounts on your site.'), + ), + ); + + // Declaration of fields. + $data['views_test_data']['id'] = array( + 'title' => t('ID'), + 'help' => t('The test data ID'), + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['views_test_data']['name'] = array( + 'title' => t('Name'), + 'help' => t('The name of the person'), + 'field' => array( + 'id' => 'standard', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['views_test_data']['age'] = array( + 'title' => t('Age'), + 'help' => t('The age of the person'), + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['views_test_data']['job'] = array( + 'title' => t('Job'), + 'help' => t('The job of the person'), + 'field' => array( + 'id' => 'standard', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + $data['views_test_data']['created'] = array( + 'title' => t('Created'), + 'help' => t('The creation date of this record'), + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + 'sort' => array( + 'id' => 'date', + ), + ); + return $data; + } + + /** + * A very simple test dataset. + */ + public static function dataSet() { + return array( + array( + 'name' => 'John', + 'age' => 25, + 'job' => 'Singer', + 'created' => gmmktime(0, 0, 0, 1, 1, 2000), + ), + array( + 'name' => 'George', + 'age' => 27, + 'job' => 'Singer', + 'created' => gmmktime(0, 0, 0, 1, 2, 2000), + ), + array( + 'name' => 'Ringo', + 'age' => 28, + 'job' => 'Drummer', + 'created' => gmmktime(6, 30, 30, 1, 1, 2000), + ), + array( + 'name' => 'Paul', + 'age' => 26, + 'job' => 'Songwriter', + 'created' => gmmktime(6, 0, 0, 1, 1, 2000), + ), + array( + 'name' => 'Meredith', + 'age' => 30, + 'job' => 'Speaker', + 'created' => gmmktime(6, 30, 10, 1, 1, 2000), + ), + ); + } +} + diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index fdb819a..e6ffc68 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -137,6 +137,13 @@ protected $verboseDirectoryUrl; /** + * The drupal container used for the test. + * + * @var \Symfony\Component\DependencyInjection\Container + */ + protected $container; + + /** * Constructor for Test. * * @param $test_id diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php index 392256b..b2f1925 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php @@ -183,192 +183,21 @@ protected function getBasicPageView() { * The schema definition. */ protected function schemaDefinition() { - $schema['views_test_data'] = array( - 'description' => 'Basic test table for Views tests.', - 'fields' => array( - 'id' => array( - 'type' => 'serial', - 'unsigned' => TRUE, - 'not null' => TRUE, - ), - 'name' => array( - 'description' => "A person's name", - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'age' => array( - 'description' => "The person's age", - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0), - 'job' => array( - 'description' => "The person's job", - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => 'Undefined', - ), - 'created' => array( - 'description' => "The creation date of this record", - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('id'), - 'unique keys' => array( - 'name' => array('name') - ), - 'indexes' => array( - 'ages' => array('age'), - ), - ); - return $schema; + return ViewTestData::schemaDefinition(); } /** * The views data definition. */ protected function viewsData() { - // Declaration of the base table. - $data['views_test_data']['table'] = array( - 'group' => t('Views test'), - 'base' => array( - 'field' => 'id', - 'title' => t('Views test data'), - 'help' => t('Users who have created accounts on your site.'), - ), - ); - - // Declaration of fields. - $data['views_test_data']['id'] = array( - 'title' => t('ID'), - 'help' => t('The test data ID'), - 'field' => array( - 'id' => 'numeric', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'numeric', - ), - 'filter' => array( - 'id' => 'numeric', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['name'] = array( - 'title' => t('Name'), - 'help' => t('The name of the person'), - 'field' => array( - 'id' => 'standard', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'string', - ), - 'filter' => array( - 'id' => 'string', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['age'] = array( - 'title' => t('Age'), - 'help' => t('The age of the person'), - 'field' => array( - 'id' => 'numeric', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'numeric', - ), - 'filter' => array( - 'id' => 'numeric', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['job'] = array( - 'title' => t('Job'), - 'help' => t('The job of the person'), - 'field' => array( - 'id' => 'standard', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'string', - ), - 'filter' => array( - 'id' => 'string', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['created'] = array( - 'title' => t('Created'), - 'help' => t('The creation date of this record'), - 'field' => array( - 'id' => 'date', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'date', - ), - 'filter' => array( - 'id' => 'date', - ), - 'sort' => array( - 'id' => 'date', - ), - ); - return $data; + return ViewTestData::viewsData(); } /** * A very simple test dataset. */ protected function dataSet() { - return array( - array( - 'name' => 'John', - 'age' => 25, - 'job' => 'Singer', - 'created' => gmmktime(0, 0, 0, 1, 1, 2000), - ), - array( - 'name' => 'George', - 'age' => 27, - 'job' => 'Singer', - 'created' => gmmktime(0, 0, 0, 1, 2, 2000), - ), - array( - 'name' => 'Ringo', - 'age' => 28, - 'job' => 'Drummer', - 'created' => gmmktime(6, 30, 30, 1, 1, 2000), - ), - array( - 'name' => 'Paul', - 'age' => 26, - 'job' => 'Songwriter', - 'created' => gmmktime(6, 0, 0, 1, 1, 2000), - ), - array( - 'name' => 'Meredith', - 'age' => 30, - 'job' => 'Speaker', - 'created' => gmmktime(6, 30, 10, 1, 1, 2000), - ), - ); + return ViewTestData::dataSet(); } /** diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php b/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php index 2e90bff..17b9371 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests; use Drupal\views\ViewExecutable; +use Drupal\views\ViewsBundle; use Drupal\simpletest\DrupalUnitTestBase; use Symfony\Component\HttpFoundation\Request; @@ -35,18 +36,8 @@ protected function setUp() { $this->enableModules(array('views', 'views_test_config', 'views_test_data')); - foreach (ViewExecutable::getPluginTypes() as $type) { - if ($type == 'join') { - $this->container->register('plugin.manager.views.join', 'Drupal\views\Plugin\Type\JoinManager'); - } - elseif ($type == 'wizard') { - $this->container->register('plugin.manager.views.wizard', 'Drupal\views\Plugin\Type\WizardManager'); - } - else { - $this->container->register("plugin.manager.views.$type", 'Drupal\views\Plugin\Type\PluginManager') - ->addArgument($type); - } - } + $views_bundle = new ViewsBundle(); + $views_bundle->build($this->container); // Load the test dataset. $data_set = $this->dataSet(); @@ -157,192 +148,21 @@ protected function executeView($view, $args = array()) { * The schema definition. */ protected function schemaDefinition() { - $schema['views_test_data'] = array( - 'description' => 'Basic test table for Views tests.', - 'fields' => array( - 'id' => array( - 'type' => 'serial', - 'unsigned' => TRUE, - 'not null' => TRUE, - ), - 'name' => array( - 'description' => "A person's name", - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'age' => array( - 'description' => "The person's age", - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0), - 'job' => array( - 'description' => "The person's job", - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => 'Undefined', - ), - 'created' => array( - 'description' => "The creation date of this record", - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('id'), - 'unique keys' => array( - 'name' => array('name') - ), - 'indexes' => array( - 'ages' => array('age'), - ), - ); - return $schema; + return ViewTestData::schemaDefinition(); } /** * The views data definition. */ protected function viewsData() { - // Declaration of the base table. - $data['views_test_data']['table'] = array( - 'group' => t('Views test'), - 'base' => array( - 'field' => 'id', - 'title' => t('Views test data'), - 'help' => t('Users who have created accounts on your site.'), - ), - ); - - // Declaration of fields. - $data['views_test_data']['id'] = array( - 'title' => t('ID'), - 'help' => t('The test data ID'), - 'field' => array( - 'id' => 'numeric', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'numeric', - ), - 'filter' => array( - 'id' => 'numeric', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['name'] = array( - 'title' => t('Name'), - 'help' => t('The name of the person'), - 'field' => array( - 'id' => 'standard', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'string', - ), - 'filter' => array( - 'id' => 'string', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['age'] = array( - 'title' => t('Age'), - 'help' => t('The age of the person'), - 'field' => array( - 'id' => 'numeric', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'numeric', - ), - 'filter' => array( - 'id' => 'numeric', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['job'] = array( - 'title' => t('Job'), - 'help' => t('The job of the person'), - 'field' => array( - 'id' => 'standard', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'string', - ), - 'filter' => array( - 'id' => 'string', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['views_test_data']['created'] = array( - 'title' => t('Created'), - 'help' => t('The creation date of this record'), - 'field' => array( - 'id' => 'date', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'date', - ), - 'filter' => array( - 'id' => 'date', - ), - 'sort' => array( - 'id' => 'date', - ), - ); - return $data; + return ViewTestData::viewsData(); } /** * A very simple test dataset. */ protected function dataSet() { - return array( - array( - 'name' => 'John', - 'age' => 25, - 'job' => 'Singer', - 'created' => gmmktime(0, 0, 0, 1, 1, 2000), - ), - array( - 'name' => 'George', - 'age' => 27, - 'job' => 'Singer', - 'created' => gmmktime(0, 0, 0, 1, 2, 2000), - ), - array( - 'name' => 'Ringo', - 'age' => 28, - 'job' => 'Drummer', - 'created' => gmmktime(6, 30, 30, 1, 1, 2000), - ), - array( - 'name' => 'Paul', - 'age' => 26, - 'job' => 'Songwriter', - 'created' => gmmktime(6, 0, 0, 1, 1, 2000), - ), - array( - 'name' => 'Meredith', - 'age' => 30, - 'job' => 'Speaker', - 'created' => gmmktime(6, 30, 10, 1, 1, 2000), - ), - ); + return ViewTestData::dataSet(); } }