Commit 480c749a authored by generalredneck's avatar generalredneck

Adding Tests for vns_text_field so I can more easily test problems.

parent e901b17a
name = Views Natural Sort Text Field Test
description = Set up module for Views Natural Sort Text Field testing.
package = Testing
core = 7.x
dependencies[] = views_natural_sort_text_field
hidden = TRUE
<?php
/**
* @file
* Install file for the testing module for Views Natural Sort Text Field.
*/
/**
* Implements hook_install().
*/
function views_natural_sort_text_field_test_install() {
node_types_rebuild();
$field_name = 'field_test_vns_sort';
// Make sure the field doesn't already exist.
if (!field_info_field($field_name)) {
// Create the field.
$field = array(
'field_name' => $field_name,
'type' => 'text',
'views_natural_sort_enable_sort' => TRUE,
'settings' => array(
'max_length' => 64,
),
);
field_create_field($field);
// Create the instance.
$instance = array( 'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'vns_text_field_test_content',
'label' => 'Test VNS Sort',
'description' => 'Test text to test Views Natural Sort functionality.',
'required' => TRUE,
);
field_create_instance($instance);
}
}
<?php
/**
* @file
* Testing module for Views Natural Sort Text Field.
*/
/**
* Implements hook_form().
*/
function views_natural_sort_text_field_test_form($node, $form_state) {
return node_content_form($node, $form_state);
}
/**
* Implements hook_node_info().
*/
function views_natural_sort_text_field_test_node_info() {
return array(
'vns_text_field_test_content' => array(
'name' => t('Views Natural Sort Text Field Test Content'),
'base' => 'node_content',
'description' => t('Content type used for testing the basic functionality of the Views Natural Sort Text Field module.'),
),
);
}
/**
* Implements hook_views_api().
*/
function views_natural_sort_text_field_test_views_api() {
return array(
'api' => 3.0,
'path' => drupal_get_path('module', 'views_natural_sort_text_field_test'),
);
}
/**
* Implements hook_views_default_views().
*/
function views_natural_sort_text_field_test_views_default_views() {
$view = new view();
$view->name = 'views_natural_sort_text_field_test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Views Natural Sort Text Field Test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Test VNS Sort */
$handler->display->display_options['fields']['field_test_vns_sort']['id'] = 'field_test_vns_sort';
$handler->display->display_options['fields']['field_test_vns_sort']['table'] = 'field_data_field_test_vns_sort';
$handler->display->display_options['fields']['field_test_vns_sort']['field'] = 'field_test_vns_sort';
$handler->display->display_options['fields']['field_test_vns_sort']['label'] = '';
$handler->display->display_options['fields']['field_test_vns_sort']['element_label_colon'] = FALSE;
/* Sort criterion: Content: Test VNS Sort (field_test_vns_sort) */
$handler->display->display_options['sorts']['field_test_vns_sort_value']['id'] = 'field_test_vns_sort_value';
$handler->display->display_options['sorts']['field_test_vns_sort_value']['table'] = 'field_data_field_test_vns_sort';
$handler->display->display_options['sorts']['field_test_vns_sort_value']['field'] = 'field_test_vns_sort_value';
$handler->display->display_options['sorts']['field_test_vns_sort_value']['order'] = 'NASC';
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'vns_text_field_test_content' => 'vns_text_field_test_content',
);
$views[$view->name] = $view;
return $views;
}
/**
* A convieance function that will create content used for testing.
*/
function views_natural_sort_text_field_test_views_create_test_content() {
$titles = array(
'1 apple',
'2 apples',
'10 apples',
'-1 apples',
'-10 apples',
'-2 apples',
'-3.550 apples',
'-3.5501 apples',
'3.5501 apples',
'3.550 apples',
'A(Z',
'A[B',
'A\\C',
'A Stripped Zebra',
'Oklahoma',
'The King And I',
);
foreach ($titles as $title) {
$node = new stdClass();
$node->type = 'vns_text_field_test_content';
$node->title = $title;
$node->field_test_vns_sort[LANGUAGE_NONE][0]['value'] = $title;
node_object_prepare($node);
$node = node_submit($node);
node_save($node);
}
}
name = Views Natural Sort Text Field Support name = Views Natural Sort Text Field Support
description = Sort results naturally on a text field skipping articles like "the" and "a." description = Sort results naturally on a text field skipping articles like "the" and "a."
dependencies[] = views_natural_sort dependencies[] = views_natural_sort
dependencies[] = text
package = Views package = Views
core = 7.x core = 7.x
; Views handlers ; Views handlers
files[] = handlers/views_natural_sort_handler_sort_text_field.inc files[] = handlers/views_natural_sort_handler_sort_text_field.inc
files[] = views_natural_sort_text_field.test
<?php
/**
* @file
* Tests for the Views Natural Sort Text Field module.
*/
module_load_include('test', 'views', 'tests/views_query');
/**
* Basic tests for the Views Natural Sort Text Field Module.
*/
class ViewsNaturalSortTextFieldBasicTest extends ViewsTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Views Natural Sort Text Field Basic Test',
'description' => 'Tests basic functionality of View Natural Sort Text Field',
'group' => 'Views Natural Sort',
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp('views', 'field', 'text', 'views_natural_sort', 'views_natural_sort_text_field', 'views_natural_sort_text_field_test');
}
/**
* Test the default settings for stripping out the words A, An, and The.
*/
public function testNaturalSortDefaultBeginningWords() {
$titles = array(
'A Stripped Zebra',
'Oklahoma',
'The King And I',
);
$nodes = array();
foreach ($titles as $title) {
$nodes[] = $this->drupalCreateNode(array(
'type' => 'vns_text_field_test_content',
'field_test_vns_sort' => array(
LANGUAGE_NONE => array(
array('value' => $title),
),
),
));
}
$view = views_get_view('views_natural_sort_text_field_test');
$this->executeView($view);
$this->verbose("<pre>QUERY:\n" . (string) $view->build_info['query'] . "\nRESULTS:\n" . print_r($view->result, TRUE) . "\nPotential fields:\n" . print_r(views_natrual_sort_text_get_potential_fields(), TRUE) . "\nConfigured Fields\n" . print_r(views_natural_sort_text_field_get_configured_fields(), TRUE) . "</pre>");
$this->verbose("<pre>Views Data:\n" . print_r(views_fetch_data(), TRUE) . "</pre>");
$this->assertIdenticalResultset(
$view,
array(
array('title' => 'The King And I'),
array('title' => 'Oklahoma'),
array('title' => 'A Stripped Zebra'),
),
array('field_data_field_test_vns_sort_field_test_vns_sort_value' => 'title')
);
}
/**
* Test the default settings for symbol removal in sorting.
*/
public function testNaturalSortDefaultSymbols() {
$titles = array(
'A(Z',
'A[B',
'A\\C',
);
foreach ($titles as $title) {
$nodes[] = $this->drupalCreateNode(array(
'type' => 'vns_text_field_test_content',
'field_test_vns_sort' => array(
LANGUAGE_NONE => array(
array('value' => $title),
),
),
));
}
$view = views_get_view('views_natural_sort_text_field_test');
$this->executeView($view);
$this->assertIdenticalResultset(
$view,
array(
array('title' => 'A[B'),
array('title' => 'A\\C'),
array('title' => 'A(Z'),
),
array('field_data_field_test_vns_sort_field_test_vns_sort_value' => 'title')
);
}
/**
* Test Unicode symbol removal in sorting.
*/
public function testNaturalSortUnicodeSymbols() {
$symbols = variable_set('views_natural_sort_symbols_remove', "#…\",'\\()[]«?!»¡¿");
$titles = array(
'Cuando… se abre, ¿dará algún tipo de señal?',
);
$expected = array(
'Cuando se abre dará algún tipo de señal',
);
foreach ($titles as $key => $title) {
$this->assertEqual(views_natural_sort_remove_symbols($title), $expected[$key]);
}
}
/**
* Test sorting strings that contain numbers in them.
*/
public function testNaturalSortNumbers() {
$titles = array(
'1 apple',
'2 apples',
'10 apples',
'-1 apples',
'-10 apples',
'-2 apples',
'-3.550 apples',
'-3.5501 apples',
'3.5501 apples',
'3.550 apples',
);
foreach ($titles as $title) {
$nodes[] = $this->drupalCreateNode(array(
'type' => 'vns_text_field_test_content',
'field_test_vns_sort' => array(
LANGUAGE_NONE => array(
array('value' => $title),
),
),
));
}
$view = views_get_view('views_natural_sort_text_field_test');
$this->executeView($view);
$this->assertIdenticalResultset(
$view,
array(
array('title' => '-10 apples'),
array('title' => '-3.5501 apples'),
array('title' => '-3.550 apples'),
array('title' => '-2 apples'),
array('title' => '-1 apples'),
array('title' => '1 apple'),
array('title' => '2 apples'),
array('title' => '3.550 apples'),
array('title' => '3.5501 apples'),
array('title' => '10 apples'),
),
array('field_data_field_test_vns_sort_field_test_vns_sort_value' => 'title')
);
}
}
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