Tests basic functions from the Views module.
Expanded class hierarchy of ModuleTest
class ModuleTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array(
'test_view_status',
);
public static function getInfo() {
return array(
'name' => 'Views Module tests',
'description' => 'Tests some basic functions of views.module.',
'group' => 'Views',
);
}
public function test_views_trim_text() {
// Test unicode, @see http://drupal.org/node/513396#comment-2839416
$text = array(
'Tuy nhiên, những hi vọng',
'Giả sử chúng tôi có 3 Apple',
'siêu nhỏ này là bộ xử lý',
'Di động của nhà sản xuất Phần Lan',
'khoảng cách từ đại lí đến',
'của hãng bao gồm ba dòng',
'сд асд асд ас',
'асд асд асд ас',
);
// Just test maxlength without word boundry.
$alter = array(
'max_length' => 10,
);
$expect = array(
'Tuy nhiên,',
'Giả sử chú',
'siêu nhỏ n',
'Di động củ',
'khoảng các',
'của hãng b',
'сд асд асд',
'асд асд ас',
);
foreach ($text as $key => $line) {
$result_text = views_trim_text($alter, $line);
$this
->assertEqual($result_text, $expect[$key]);
}
// Test also word_boundary
$alter['word_boundary'] = TRUE;
$expect = array(
'Tuy nhiên',
'Giả sử',
'siêu nhỏ',
'Di động',
'khoảng',
'của hãng',
'сд асд',
'асд асд',
);
foreach ($text as $key => $line) {
$result_text = views_trim_text($alter, $line);
$this
->assertEqual($result_text, $expect[$key]);
}
}
/**
* Tests the views_get_handler method.
*/
function testviews_get_handler() {
$types = array(
'field',
'area',
'filter',
);
foreach ($types as $type) {
$handler = views_get_handler($this
->randomName(), $this
->randomName(), $type);
$this
->assertEqual('Drupal\\views\\Plugin\\views\\' . $type . '\\Broken', get_class($handler), t('Make sure that a broken handler of type: @type are created', array(
'@type' => $type,
)));
}
$views_data = $this
->viewsData();
$test_tables = array(
'views_test_data' => array(
'id',
'name',
),
);
foreach ($test_tables as $table => $fields) {
foreach ($fields as $field) {
$data = $views_data[$table][$field];
foreach ($data as $id => $field_data) {
if (!in_array($id, array(
'title',
'help',
))) {
$handler = views_get_handler($table, $field, $id);
$this
->assertInstanceHandler($handler, $table, $field, $id);
}
}
}
}
// Test the override handler feature.
$handler = views_get_handler('views_test_data', 'job', 'filter', 'standard');
$this
->assertEqual('Drupal\\views\\Plugin\\views\\filter\\Standard', get_class($handler));
}
/**
* Tests the load wrapper/helper functions.
*/
public function testLoadFunctions() {
$this
->enableModules(array(
'node',
), FALSE);
$controller = entity_get_controller('view');
// Test views_view_is_enabled/disabled.
$load = $controller
->load(array(
'archive',
));
$archive = reset($load);
$this
->assertTrue(views_view_is_disabled($archive), 'views_view_is_disabled works as expected.');
// Enable the view and check this.
$archive
->enable();
$this
->assertTrue(views_view_is_enabled($archive), ' views_view_is_enabled works as expected.');
// We can store this now, as we have enabled/disabled above.
$all_views = $controller
->load();
// Test views_get_all_views().
$this
->assertIdentical(array_keys($all_views), array_keys(views_get_all_views()), 'views_get_all_views works as expected.');
// Test views_get_enabled_views().
$expected_enabled = array_filter($all_views, function ($view) {
return views_view_is_enabled($view);
});
$this
->assertIdentical(array_keys($expected_enabled), array_keys(views_get_enabled_views()), 'Expected enabled views returned.');
// Test views_get_disabled_views().
$expected_disabled = array_filter($all_views, function ($view) {
return views_view_is_disabled($view);
});
$this
->assertIdentical(array_keys($expected_disabled), array_keys(views_get_disabled_views()), 'Expected disabled views returned.');
// Test views_get_views_as_options().
// Test the $views_only parameter.
$this
->assertIdentical(array_keys($all_views), array_keys(views_get_views_as_options(TRUE)), 'Expected option keys for all views were returned.');
$expected_options = array();
foreach ($all_views as $id => $view) {
$expected_options[$id] = $view
->getHumanName();
}
$this
->assertIdentical($expected_options, views_get_views_as_options(TRUE), 'Expected options array was returned.');
// Test the default.
$this
->assertIdentical($this
->formatViewOptions($all_views), views_get_views_as_options(), 'Expected options array for all views was returned.');
// Test enabled views.
$this
->assertIdentical($this
->formatViewOptions($expected_enabled), views_get_views_as_options(FALSE, 'enabled'), 'Expected enabled options array was returned.');
// Test disabled views.
$this
->assertIdentical($this
->formatViewOptions($expected_disabled), views_get_views_as_options(FALSE, 'disabled'), 'Expected disabled options array was returned.');
// Test the sort parameter.
$all_views_sorted = $all_views;
ksort($all_views_sorted);
$this
->assertIdentical(array_keys($all_views_sorted), array_keys(views_get_views_as_options(TRUE, 'all', NULL, FALSE, TRUE)), 'All view id keys returned in expected sort order');
// Test $exclude_view parameter.
$this
->assertFalse(array_key_exists('archive', views_get_views_as_options(TRUE, 'all', 'archive')), 'View excluded from options based on name');
$this
->assertFalse(array_key_exists('archive:default', views_get_views_as_options(FALSE, 'all', 'archive:default')), 'View display excluded from options based on name');
$this
->assertFalse(array_key_exists('archive', views_get_views_as_options(TRUE, 'all', $archive
->get('executable'))), 'View excluded from options based on object');
// Test the $opt_group parameter.
$expected_opt_groups = array();
foreach ($all_views as $id => $view) {
foreach ($view
->get('display') as $display_id => $display) {
$expected_opt_groups[$view
->id()][$view
->id() . ':' . $display['id']] = t('@view : @display', array(
'@view' => $view
->id(),
'@display' => $display['id'],
));
}
}
$this
->assertIdentical($expected_opt_groups, views_get_views_as_options(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
}
/**
* Tests view enable and disable procedural wrapper functions.
*/
function testStatusFunctions() {
$view = views_get_view('test_view_status')->storage;
$this
->assertFalse($view
->isEnabled(), 'The view status is disabled.');
views_enable_view($view);
$this
->assertTrue($view
->isEnabled(), 'A view has been enabled.');
$this
->assertEqual($view
->isEnabled(), views_view_is_enabled($view), 'views_view_is_enabled is correct.');
views_disable_view($view);
$this
->assertFalse($view
->isEnabled(), 'A view has been disabled.');
$this
->assertEqual(!$view
->isEnabled(), views_view_is_disabled($view), 'views_view_is_disabled is correct.');
}
/**
* Helper to return an expected views option array.
*
* @param array $views
* An array of Drupal\views\Plugin\Core\Entity\View objects for which to
* create an options array.
*
* @return array
* A formatted options array that matches the expected output.
*/
protected function formatViewOptions(array $views = array()) {
$expected_options = array();
foreach ($views as $id => $view) {
foreach ($view
->get('display') as $display_id => $display) {
$expected_options[$view
->id() . ':' . $display['id']] = t('View: @view - Display: @display', array(
'@view' => $view->name,
'@display' => $display['id'],
));
}
}
return $expected_options;
}
/**
* Ensure that a certain handler is a instance of a certain table/field.
*/
function assertInstanceHandler($handler, $table, $field, $id) {
$table_data = views_fetch_data($table);
$field_data = $table_data[$field][$id];
$this
->assertEqual($field_data['id'], $handler
->getPluginId());
}
}
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalUnitTestBase:: |
private | property | ||
DrupalUnitTestBase:: |
private | property | Fixed module list being used by this test. | |
DrupalUnitTestBase:: |
public static | property | Modules to enable. | 6 |
DrupalUnitTestBase:: |
private | property | ||
DrupalUnitTestBase:: |
private | property | ||
DrupalUnitTestBase:: |
public | function | Sets up the base service container for this test. | |
DrupalUnitTestBase:: |
protected | function | Enables modules for this test. | |
DrupalUnitTestBase:: |
protected | function | Installs a specific table from a module schema definition. | |
ModuleTest:: |
public static | property | Views used by this test. | |
ModuleTest:: |
function | Ensure that a certain handler is a instance of a certain table/field. | ||
ModuleTest:: |
protected | function | Helper to return an expected views option array. | |
ModuleTest:: |
public static | function | ||
ModuleTest:: |
public | function | Tests the load wrapper/helper functions. | |
ModuleTest:: |
function | Tests view enable and disable procedural wrapper functions. | ||
ModuleTest:: |
function | Tests the views_get_handler method. | ||
ModuleTest:: |
public | function | ||
TestBase:: |
protected | property | Assertions thrown in that test case. | |
TestBase:: |
protected | property | The database prefix of this test run. | |
TestBase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
TestBase:: |
protected | property | The original database prefix when running inside Simpletest. | |
TestBase:: |
public | property | Current results of this test case. | |
TestBase:: |
protected | property | Flag to indicate whether the test has been set up. | |
TestBase:: |
protected | property | ||
TestBase:: |
protected | property | ||
TestBase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
TestBase:: |
protected | property | The test run ID. | |
TestBase:: |
protected | property | Time limit for the test. | |
TestBase:: |
protected | property | TRUE if verbose debugging is enabled. | |
TestBase:: |
protected | property | Safe class name for use in verbose output filenames. | |
TestBase:: |
protected | property | Directory where verbose output files are put. | |
TestBase:: |
protected | property | URL to the verbose output file directory. | |
TestBase:: |
protected | property | Incrementing identifier for verbose output filenames. | |
TestBase:: |
protected | function | Internal helper: stores the assert. | |
TestBase:: |
protected | function | Check to see if two values are equal. | |
TestBase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
TestBase:: |
protected | function | Check to see if two values are identical. | |
TestBase:: |
protected | function | Checks to see if two objects are identical. | |
TestBase:: |
protected | function | Check to see if two values are not equal. | |
TestBase:: |
protected | function | Check to see if two values are not identical. | |
TestBase:: |
protected | function | Check to see if a value is not NULL. | |
TestBase:: |
protected | function | Check to see if a value is NULL. | |
TestBase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
TestBase:: |
protected | function | Changes the database connection to the prefixed one. | |
TestBase:: |
protected | function | Checks the matching requirements for Test. | 3 |
TestBase:: |
public static | function | Delete an assertion record by message ID. | |
TestBase:: |
protected | function | Fire an error assertion. | 1 |
TestBase:: |
public | function | Handle errors during test runs. | |
TestBase:: |
protected | function | Handle exceptions. | |
TestBase:: |
protected | function | Fire an assertion that is always negative. | |
TestBase:: |
public static | function | Ensures test files are deletable within file_unmanaged_delete_recursive(). | |
TestBase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
TestBase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
TestBase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
TestBase:: |
public static | function | Store an assertion from outside the testing context. | |
TestBase:: |
protected | function | Fire an assertion that is always positive. | |
TestBase:: |
protected | function | Generates a database prefix for running tests. | |
TestBase:: |
protected | function | Prepares the current environment for running the test. | |
TestBase:: |
public static | function | Generates a random string containing letters and numbers. | |
TestBase:: |
public static | function | Generates a random PHP object. | |
TestBase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
TestBase:: |
protected | function | Rebuild drupal_container(). | |
TestBase:: |
public | function | Run all tests in this class. | |
TestBase:: |
protected | function | Deletes created files, database tables, and reverts all environment changes. | 10 |
TestBase:: |
protected | function | Logs verbose message in a text file. | |
UnitTestBase:: |
protected | property | ||
UnitTestBase:: |
function |
Constructor for UnitTestBase. Overrides TestBase:: |
6 | |
ViewUnitTestBase:: |
protected | function | Verifies that a result set returned by a View matches expected values. | |
ViewUnitTestBase:: |
protected | function | Performs View result assertions. | |
ViewUnitTestBase:: |
protected | function | Verifies that a result set returned by a View differs from certain values. | |
ViewUnitTestBase:: |
protected | function | Returns a very simple test dataset. | 6 |
ViewUnitTestBase:: |
protected | function | Executes a view with debugging. | |
ViewUnitTestBase:: |
protected | function | Orders a nested array containing a result set based on a given column. | |
ViewUnitTestBase:: |
protected | function | Returns the schema definition. | 4 |
ViewUnitTestBase:: |
protected | function |
Sets up Drupal unit test environment. Overrides DrupalUnitTestBase:: |
13 |
ViewUnitTestBase:: |
protected | function | Returns the views data definition. | 17 |