Commit 0aadc79b authored by catch's avatar catch

Issue #1989806 by damiankloip: Rename ViewsDataCache to ViewsData.

parent eea18a48
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\views\Tests; namespace Drupal\views\Tests;
use Drupal\Core\Cache\MemoryCounterBackend; use Drupal\Core\Cache\MemoryCounterBackend;
use Drupal\views\ViewsDataCache; use Drupal\views\ViewsData;
/** /**
* Tests the fetching of views data. * Tests the fetching of views data.
...@@ -20,9 +20,9 @@ class ViewsDataTest extends ViewUnitTestBase { ...@@ -20,9 +20,9 @@ class ViewsDataTest extends ViewUnitTestBase {
/** /**
* Stores the views data cache service used by this test. * Stores the views data cache service used by this test.
* *
* @var \Drupal\views\ViewsDataCache * @var \Drupal\views\ViewsData
*/ */
protected $viewsDataCache; protected $viewsData;
/** /**
* Stores a count for hook_views_data being invoked. * Stores a count for hook_views_data being invoked.
...@@ -40,7 +40,7 @@ class ViewsDataTest extends ViewUnitTestBase { ...@@ -40,7 +40,7 @@ class ViewsDataTest extends ViewUnitTestBase {
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'Table Data', 'name' => 'Views data',
'description' => 'Tests the fetching of views data.', 'description' => 'Tests the fetching of views data.',
'group' => 'Views', 'group' => 'Views',
); );
...@@ -52,13 +52,13 @@ protected function setUp() { ...@@ -52,13 +52,13 @@ protected function setUp() {
$this->memoryCounterBackend = new MemoryCounterBackend('views_info'); $this->memoryCounterBackend = new MemoryCounterBackend('views_info');
$this->state = $this->container->get('state'); $this->state = $this->container->get('state');
$this->initViewsDataCache(); $this->initViewsData();
} }
/** /**
* Tests the views.views_data service. * Tests the views.views_data service.
* *
* @see \Drupal\views\ViewsDataCache * @see \Drupal\views\ViewsData
*/ */
public function testViewsFetchData() { public function testViewsFetchData() {
$table_name = 'views_test_data'; $table_name = 'views_test_data';
...@@ -69,62 +69,62 @@ public function testViewsFetchData() { ...@@ -69,62 +69,62 @@ public function testViewsFetchData() {
// Verify that views_test_data_views_data() has only been called once after // Verify that views_test_data_views_data() has only been called once after
// calling clear(). // calling clear().
$this->startCount(); $this->startCount();
$this->viewsDataCache->get(); $this->viewsData->get();
// Test views data has been invoked. // Test views data has been invoked.
$this->assertCountIncrement(); $this->assertCountIncrement();
// Clear the storage/cache. // Clear the storage/cache.
$this->viewsDataCache->clear(); $this->viewsData->clear();
// Get the data again. // Get the data again.
$this->viewsDataCache->get(); $this->viewsData->get();
$this->viewsDataCache->get($table_name); $this->viewsData->get($table_name);
$this->viewsDataCache->get($random_table_name); $this->viewsData->get($random_table_name);
// Verify that view_test_data_views_data() has run once. // Verify that view_test_data_views_data() has run once.
$this->assertCountIncrement(); $this->assertCountIncrement();
// Get the data again. // Get the data again.
$this->viewsDataCache->get(); $this->viewsData->get();
$this->viewsDataCache->get($table_name); $this->viewsData->get($table_name);
$this->viewsDataCache->get($random_table_name); $this->viewsData->get($random_table_name);
// Verify that view_test_data_views_data() has not run again. // Verify that view_test_data_views_data() has not run again.
$this->assertCountIncrement(FALSE); $this->assertCountIncrement(FALSE);
// Clear the views data, and test all table data. // Clear the views data, and test all table data.
$this->viewsDataCache->clear(); $this->viewsData->clear();
$this->startCount(); $this->startCount();
$data = $this->viewsDataCache->get(); $data = $this->viewsData->get();
$this->assertEqual($data, $expected_data, 'Make sure fetching all views data by works as expected.'); $this->assertEqual($data, $expected_data, 'Make sure fetching all views data by works as expected.');
// Views data should be invoked once. // Views data should be invoked once.
$this->assertCountIncrement(); $this->assertCountIncrement();
// Calling get() again, the count for this table should stay the same. // Calling get() again, the count for this table should stay the same.
$data = $this->viewsDataCache->get(); $data = $this->viewsData->get();
$this->assertEqual($data, $expected_data, 'Make sure fetching all cached views data works as expected.'); $this->assertEqual($data, $expected_data, 'Make sure fetching all cached views data works as expected.');
$this->assertCountIncrement(FALSE); $this->assertCountIncrement(FALSE);
// Clear the views data, and test data for a specific table. // Clear the views data, and test data for a specific table.
$this->viewsDataCache->clear(); $this->viewsData->clear();
$this->startCount(); $this->startCount();
$data = $this->viewsDataCache->get($table_name); $data = $this->viewsData->get($table_name);
$this->assertEqual($data, $expected_data[$table_name], 'Make sure fetching views data by table works as expected.'); $this->assertEqual($data, $expected_data[$table_name], 'Make sure fetching views data by table works as expected.');
// Views data should be invoked once. // Views data should be invoked once.
$this->assertCountIncrement(); $this->assertCountIncrement();
// Calling get() again, the count for this table should stay the same. // Calling get() again, the count for this table should stay the same.
$data = $this->viewsDataCache->get($table_name); $data = $this->viewsData->get($table_name);
$this->assertEqual($data, $expected_data[$table_name], 'Make sure fetching cached views data by table works as expected.'); $this->assertEqual($data, $expected_data[$table_name], 'Make sure fetching cached views data by table works as expected.');
$this->assertCountIncrement(FALSE); $this->assertCountIncrement(FALSE);
// Test that this data is present if all views data is returned. // Test that this data is present if all views data is returned.
$data = $this->viewsDataCache->get(); $data = $this->viewsData->get();
$this->assertTrue(isset($data[$table_name]), 'Make sure the views_test_data info appears in the total views data.'); $this->assertTrue(isset($data[$table_name]), 'Make sure the views_test_data info appears in the total views data.');
$this->assertEqual($data[$table_name], $expected_data[$table_name], 'Make sure the views_test_data has the expected values.'); $this->assertEqual($data[$table_name], $expected_data[$table_name], 'Make sure the views_test_data has the expected values.');
// Clear the views data, and test data for an invalid table. // Clear the views data, and test data for an invalid table.
$this->viewsDataCache->clear(); $this->viewsData->clear();
$this->startCount(); $this->startCount();
// All views data should be requested on the first try. // All views data should be requested on the first try.
$data = $this->viewsDataCache->get($random_table_name); $data = $this->viewsData->get($random_table_name);
$this->assertEqual($data, array(), 'Make sure fetching views data for an invalid table returns an empty array.'); $this->assertEqual($data, array(), 'Make sure fetching views data for an invalid table returns an empty array.');
$this->assertCountIncrement(); $this->assertCountIncrement();
// Test no data is rebuilt when requesting an invalid table again. // Test no data is rebuilt when requesting an invalid table again.
$data = $this->viewsDataCache->get($random_table_name); $data = $this->viewsData->get($random_table_name);
$this->assertEqual($data, array(), 'Make sure fetching views data for an invalid table returns an empty array.'); $this->assertEqual($data, array(), 'Make sure fetching views data for an invalid table returns an empty array.');
$this->assertCountIncrement(FALSE); $this->assertCountIncrement(FALSE);
} }
...@@ -140,7 +140,7 @@ public function testCacheRequests() { ...@@ -140,7 +140,7 @@ public function testCacheRequests() {
// and writes a cache entry for all tables and the requested table. // and writes a cache entry for all tables and the requested table.
$table_name = 'views_test_data'; $table_name = 'views_test_data';
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$this->viewsDataCache->get($table_name); $this->viewsData->get($table_name);
} }
// Assert cache set and get calls. // Assert cache set and get calls.
...@@ -152,9 +152,9 @@ public function testCacheRequests() { ...@@ -152,9 +152,9 @@ public function testCacheRequests() {
// Re-initialize the views data cache to simulate a new request and repeat. // Re-initialize the views data cache to simulate a new request and repeat.
// We have a warm cache now, so this will only request the tables-specific // We have a warm cache now, so this will only request the tables-specific
// cache entry and return that. // cache entry and return that.
$this->initViewsDataCache(); $this->initViewsData();
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$this->viewsDataCache->get($table_name); $this->viewsData->get($table_name);
} }
// Assert cache set and get calls. // Assert cache set and get calls.
...@@ -167,10 +167,10 @@ public function testCacheRequests() { ...@@ -167,10 +167,10 @@ public function testCacheRequests() {
// a different table. This will fail to get a table specific cache entry, // a different table. This will fail to get a table specific cache entry,
// load the cache entry for all tables and save a cache entry for this table // load the cache entry for all tables and save a cache entry for this table
// but not all. // but not all.
$this->initViewsDataCache(); $this->initViewsData();
$another_table_name = 'views'; $another_table_name = 'views';
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$this->viewsDataCache->get($another_table_name); $this->viewsData->get($another_table_name);
} }
// Assert cache set and get calls. // Assert cache set and get calls.
...@@ -184,10 +184,10 @@ public function testCacheRequests() { ...@@ -184,10 +184,10 @@ public function testCacheRequests() {
// explicitly write an empty cache entry for non-existing tables to avoid // explicitly write an empty cache entry for non-existing tables to avoid
// unecessary requests in those situations. We do have to load the cache // unecessary requests in those situations. We do have to load the cache
// entry for all tables to check if the table does exist or not. // entry for all tables to check if the table does exist or not.
$this->initViewsDataCache(); $this->initViewsData();
$non_existing_table = $this->randomName(); $non_existing_table = $this->randomName();
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$this->viewsDataCache->get($non_existing_table); $this->viewsData->get($non_existing_table);
} }
// Assert cache set and get calls. // Assert cache set and get calls.
...@@ -199,9 +199,9 @@ public function testCacheRequests() { ...@@ -199,9 +199,9 @@ public function testCacheRequests() {
// Re-initialize the views data cache to simulate a new request and request // Re-initialize the views data cache to simulate a new request and request
// the same non-existing table. This will load the table-specific cache // the same non-existing table. This will load the table-specific cache
// entry and return the stored empty array for that. // entry and return the stored empty array for that.
$this->initViewsDataCache(); $this->initViewsData();
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$this->viewsDataCache->get($non_existing_table); $this->viewsData->get($non_existing_table);
} }
// Assert cache set and get calls. // Assert cache set and get calls.
...@@ -212,9 +212,9 @@ public function testCacheRequests() { ...@@ -212,9 +212,9 @@ public function testCacheRequests() {
// Re-initialize the views data cache and repeat with no specified table. // Re-initialize the views data cache and repeat with no specified table.
// This should only load the cache entry for all tables. // This should only load the cache entry for all tables.
$this->initViewsDataCache(); $this->initViewsData();
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$this->viewsDataCache->get(); $this->viewsData->get();
} }
// This only requested the full information. No other cache requests should // This only requested the full information. No other cache requests should
...@@ -227,11 +227,11 @@ public function testCacheRequests() { ...@@ -227,11 +227,11 @@ public function testCacheRequests() {
} }
/** /**
* Initializes a new ViewsDataCache instance and resets the cache backend. * Initializes a new ViewsData instance and resets the cache backend.
*/ */
protected function initViewsDataCache() { protected function initViewsData() {
$this->memoryCounterBackend->resetCounter(); $this->memoryCounterBackend->resetCounter();
$this->viewsDataCache = new ViewsDataCache($this->memoryCounterBackend, $this->container->get('config.factory'), $this->container->get('module_handler')); $this->viewsData = new ViewsData($this->memoryCounterBackend, $this->container->get('config.factory'), $this->container->get('module_handler'));
} }
/** /**
...@@ -357,8 +357,8 @@ public function testViewsFetchFields() { ...@@ -357,8 +357,8 @@ public function testViewsFetchFields() {
public function testFetchBaseTables() { public function testFetchBaseTables() {
// Enabled node module so there is more than 1 base table to test. // Enabled node module so there is more than 1 base table to test.
$this->enableModules(array('node')); $this->enableModules(array('node'));
$data = $this->viewsDataCache->get(); $data = $this->viewsData->get();
$base_tables = $this->viewsDataCache->fetchBaseTables(); $base_tables = $this->viewsData->fetchBaseTables();
// Test the number of tables returned and their order. // Test the number of tables returned and their order.
$this->assertEqual(count($base_tables), 3, 'The correct amount of base tables were returned.'); $this->assertEqual(count($base_tables), 3, 'The correct amount of base tables were returned.');
......
...@@ -17,7 +17,7 @@ class Views { ...@@ -17,7 +17,7 @@ class Views {
/** /**
* Returns the views data service. * Returns the views data service.
* *
* @return \Drupal\views\ViewsDataCache * @return \Drupal\views\ViewsData
* Returns a views data cache object. * Returns a views data cache object.
*/ */
public static function viewsData() { public static function viewsData() {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains \Drupal\views\ViewsDataCache. * Contains \Drupal\views\ViewsData.
*/ */
namespace Drupal\views; namespace Drupal\views;
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* the requested table based on this cached data. Table data is only rebuilt * the requested table based on this cached data. Table data is only rebuilt
* when no cache entry for all table data can be retrieved. * when no cache entry for all table data can be retrieved.
*/ */
class ViewsDataCache { class ViewsData {
/** /**
* The base cache ID to use. * The base cache ID to use.
...@@ -71,7 +71,7 @@ class ViewsDataCache { ...@@ -71,7 +71,7 @@ class ViewsDataCache {
protected $moduleHandler; protected $moduleHandler;
/** /**
* Constructs this ViewsDataCache object. * Constructs this ViewsData object.
* *
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* The cache backend to use. * The cache backend to use.
......
...@@ -16,7 +16,7 @@ function views_test_data_views_data() { ...@@ -16,7 +16,7 @@ function views_test_data_views_data() {
$state->set('views_hook_test_views_data', TRUE); $state->set('views_hook_test_views_data', TRUE);
// We use a state variable to keep track of how many times this function is // We use a state variable to keep track of how many times this function is
// called so we can assert that calls to // called so we can assert that calls to
// \Drupal\views\ViewsDataCache::delete() trigger a rebuild of views data. // \Drupal\views\ViewsData::delete() trigger a rebuild of views data.
if (!($count = $state->get('views_test_data_views_data_count'))) { if (!($count = $state->get('views_test_data_views_data_count'))) {
$count = 0; $count = 0;
} }
......
...@@ -57,7 +57,7 @@ services: ...@@ -57,7 +57,7 @@ services:
class: Drupal\views\Plugin\ViewsPluginManager class: Drupal\views\Plugin\ViewsPluginManager
arguments: [wizard, '@container.namespaces'] arguments: [wizard, '@container.namespaces']
views.views_data: views.views_data:
class: Drupal\views\ViewsDataCache class: Drupal\views\ViewsData
arguments: ['@cache.views_info', '@config.factory', '@module_handler'] arguments: ['@cache.views_info', '@config.factory', '@module_handler']
views.executable: views.executable:
class: Drupal\views\ViewExecutableFactory class: Drupal\views\ViewExecutableFactory
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\ViewStorageInterface; use Drupal\views\ViewStorageInterface;
use Drupal\views_ui\ViewUI; use Drupal\views_ui\ViewUI;
use Drupal\views\ViewsDataCache; use Drupal\views\ViewsData;
use Drupal\user\TempStore; use Drupal\user\TempStore;
use Drupal\user\TempStoreFactory; use Drupal\user\TempStoreFactory;
use Drupal\Core\ControllerInterface; use Drupal\Core\ControllerInterface;
...@@ -37,7 +37,7 @@ class ViewsUIController implements ControllerInterface { ...@@ -37,7 +37,7 @@ class ViewsUIController implements ControllerInterface {
/** /**
* Stores the Views data cache object. * Stores the Views data cache object.
* *
* @var \Drupal\views\ViewsDataCache * @var \Drupal\views\ViewsData
*/ */
protected $viewsData; protected $viewsData;
...@@ -53,12 +53,12 @@ class ViewsUIController implements ControllerInterface { ...@@ -53,12 +53,12 @@ class ViewsUIController implements ControllerInterface {
* *
* @param \Drupal\Core\Entity\EntityManager $entity_manager * @param \Drupal\Core\Entity\EntityManager $entity_manager
* The Entity manager. * The Entity manager.
* @param \Drupal\views\ViewsDataCache views_data * @param \Drupal\views\ViewsData views_data
* The Views data cache object. * The Views data cache object.
* @param \Drupal\user\TempStoreFactory $temp_store_factory * @param \Drupal\user\TempStoreFactory $temp_store_factory
* The factory for the temp store object. * The factory for the temp store object.
*/ */
public function __construct(EntityManager $entity_manager, ViewsDataCache $views_data, TempStoreFactory $temp_store_factory) { public function __construct(EntityManager $entity_manager, ViewsData $views_data, TempStoreFactory $temp_store_factory) {
$this->entityManager = $entity_manager; $this->entityManager = $entity_manager;
$this->viewsData = $views_data; $this->viewsData = $views_data;
$this->tempStore = $temp_store_factory->get('views'); $this->tempStore = $temp_store_factory->get('views');
......
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