Commit d099975b authored by generalredneck's avatar generalredneck

Adding a few failing tests. TDD :P

parent 35f5a822
langcode: en
status: true
name: 'Views Natural Sort Test Content'
type: views_natural_sort_test_content
description: 'Content type used for testing the basic functionality of the Views Natural Sort module.'
help: ''
new_revision: false
preview_mode: 1
display_submitted: true
langcode: en
status: true
dependencies:
config:
- node.type.views_natural_sort_test_content
module:
- node
- user
- views_natural_sort
id: views_natural_sort_test
label: 'Views Natural Sort Test'
module: views
description: 'View used to test the basic functionality of the Views Natural Sort module.'
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: none
options:
offset: 0
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
fields:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
click_sort_column: value
type: string
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
filters:
type:
id: type
table: node_field_data
field: type
relationship: none
group_type: group
admin_label: ''
operator: in
value:
views_natural_sort_test_content: views_natural_sort_test_content
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: node
entity_field: type
plugin_id: bundle
sorts:
title:
id: title
table: node_field_data
field: title
relationship: none
group_type: group
admin_label: ''
order: NASC
exposed: false
expose:
label: ''
entity_type: node
entity_field: title
plugin_id: natural
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- 'user.node_grants:view'
- user.permissions
tags: { }
name: Views Natural Sort Test
type: module
description: Set up module for Views Natural Sort testing.
core: 8.x
package: Testing
dependencies:
- views_natural_sort
<?php
/**
* @file
* Contains views_natural_sort_test.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function views_natural_sort_test_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the views_natural_sort_test module.
case 'help.page.views_natural_sort_test':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Set up module for Views Natural Sort testing.') . '</p>';
return $output;
default:
}
}
<?php
namespace Drupal\Tests\views_natural_sort\Kernel;
use Drupal\node\Entity\Node;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* @group views_natural_sort
*/
class BasicTest extends ViewsKernelTestBase {
public static $modules = ['node', 'field', 'text', 'user', 'views_natural_sort', 'views_natural_sort_test'];
public static $testViews = ['views_natural_sort_test'];
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installConfig(['node', 'field']);
ViewTestData::createTestViews(get_class($this), ['views_natural_sort_test']);
}
public function testNaturalSortDefaultBeginningWords() {
$node1 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'A Stripped Zebra',
]);
$node1->save();
$node2 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'Oklahoma',
]);
$node2->save();
$node3 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'The King And I',
]);
$node3->save();
$view = Views::getView('views_natural_sort_test');
$view->setDisplay();
$view->preview('default');
$this->assertIdenticalResultset(
$view,
[
['title' => 'The King And I'],
['title' => 'Oklahoma!'],
['title' => 'A Stripped Zebra'],
],
['title' => 'title']
);
}
public function testNaturalSortDefaultWords() {
$node1 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'Red of Purple',
]);
$node1->save();
$node2 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'Red or Green',
]);
$node2->save();
$node3 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'Red and Blue',
]);
$node3->save();
$view = Views::getView('views_natural_sort_test');
$view->setDisplay();
$view->preview('default');
$this->assertIdenticalResultset(
$view,
[
['title' => 'Red and Blue'],
['title' => 'Red or Green'],
['title' => 'Red of Purple'],
],
['title' => 'title']
);
}
public function testNaturalSortDefaultSymbols() {
$node1 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'A(Z',
]);
$node1->save();
$node2 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'A[B',
]);
$node2->save();
$node3 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => 'A\\C',
]);
$node3->save();
$view = Views::getView('views_natural_sort_test');
$view->setDisplay();
$view->preview('default');
$this->assertIdenticalResultset(
$view,
[
['title' => 'A[B'],
['title' => 'A\\C'],
['title' => 'A(Z'],
],
['title' => 'title']
);
}
public function testNaturalSortNumbers() {
$node1 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '1 apple',
]);
$node1->save();
$node2 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '2 apples',
]);
$node2->save();
$node3 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '10 apples',
]);
$node3->save();
$node4 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '-1 apples',
]);
$node4->save();
$node5 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '-10 apples',
]);
$node5->save();
$node6 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '-2 apples',
]);
$node6->save();
$node7 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '-3.550 apples',
]);
$node7->save();
$node8 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '-3.5501 apples',
]);
$node8->save();
$node9 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '3.5501 apples',
]);
$node9->save();
$node0 = Node::create([
'type' => 'views_natural_sort_test_content',
'title' => '3.550 apples',
]);
$node0->save();
$view = Views::getView('views_natural_sort_test');
$view->setDisplay();
$view->preview('default');
$this->assertIdenticalResultset(
$view,
[
['title' => '-10 apples'],
['title' => '-3.5501 apples'],
['title' => '-3.550 apples'],
['title' => '-2 apples'],
['title' => '-1 apples'],
['title' => '1 apple'],
['title' => '2 apples'],
['title' => '3.550 apples'],
['title' => '3.5501 apples'],
['title' => '10 apples'],
],
['title' => '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