Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
|
@ -0,0 +1,130 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- user
|
||||
id: token_views_test
|
||||
label: token_views_test
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: users_field_data
|
||||
base_field: uid
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
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: some
|
||||
options:
|
||||
items_per_page: 5
|
||||
offset: 0
|
||||
style:
|
||||
type: default
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
default_field_elements: true
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
fields:
|
||||
name:
|
||||
id: name
|
||||
table: users_field_data
|
||||
field: name
|
||||
entity_type: user
|
||||
entity_field: name
|
||||
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
|
||||
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: user_name
|
||||
settings: { }
|
||||
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: { }
|
||||
sorts: { }
|
||||
title: token_views_test
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
tags: { }
|
||||
block_1:
|
||||
display_plugin: block
|
||||
id: block_1
|
||||
display_title: Block
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
|
|
@ -5,8 +5,8 @@ package: Testing
|
|||
# core: 8.x
|
||||
hidden: TRUE
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-29
|
||||
version: '8.x-1.0'
|
||||
# Information added by Drupal.org packaging script on 2018-09-21
|
||||
version: '8.x-1.5'
|
||||
core: '8.x'
|
||||
project: 'token'
|
||||
datestamp: 1493466847
|
||||
datestamp: 1537557488
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@
|
|||
* @file
|
||||
* Helper module for token tests.
|
||||
*/
|
||||
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_page_attachments().
|
||||
*/
|
||||
function token_module_test_page_attachments() {
|
||||
if ($debug = \Drupal::state()->get('token_page_tokens', array())) {
|
||||
$debug += array('tokens' => array(), 'data' => array(), 'options' => array());
|
||||
if ($debug = \Drupal::state()->get('token_page_tokens', [])) {
|
||||
$debug += ['tokens' => [], 'data' => [], 'options' => []];
|
||||
foreach (array_keys($debug['tokens']) as $token) {
|
||||
$debug['values'][$token] = \Drupal::token()->replace($token, $debug['data'], $debug['options']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
* Implements hook_token_info()
|
||||
*/
|
||||
function token_module_test_token_info() {
|
||||
$info['tokens']['node']['colons:in:name'] = array(
|
||||
$info['tokens']['node']['colons:in:name'] = [
|
||||
'name' => t('A test token with colons in the name'),
|
||||
'description' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ hidden: TRUE
|
|||
dependencies:
|
||||
- image
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-29
|
||||
version: '8.x-1.0'
|
||||
# Information added by Drupal.org packaging script on 2018-09-21
|
||||
version: '8.x-1.5'
|
||||
core: '8.x'
|
||||
project: 'token'
|
||||
datestamp: 1493466847
|
||||
datestamp: 1537557488
|
||||
|
|
|
|||
137
web/modules/contrib/token/tests/src/Functional/UrlTest.php
Normal file
137
web/modules/contrib/token/tests/src/Functional/UrlTest.php
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\token\Functional;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Tests URL tokens.
|
||||
*
|
||||
* @group token
|
||||
*/
|
||||
class UrlTest extends BrowserTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* The first testing node.
|
||||
*
|
||||
* @var \Drupal\node\NodeInterface
|
||||
*/
|
||||
protected $node1;
|
||||
|
||||
/**
|
||||
* The second testing node.
|
||||
*
|
||||
* @var \Drupal\node\NodeInterface
|
||||
*/
|
||||
protected $node2;
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['node', 'token', 'block'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$node_type = NodeType::create(['type' => 'article', 'name' => 'Article']);
|
||||
$node_type->save();
|
||||
|
||||
$this->node1 = Node::create([
|
||||
'type' => 'article',
|
||||
'title' => 'Test Node 1',
|
||||
]);
|
||||
$this->node1->save();
|
||||
|
||||
$this->node2 = Node::create([
|
||||
'type' => 'article',
|
||||
'title' => 'Test Node 2',
|
||||
]);
|
||||
$this->node2->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a block with token for title and tests cache contexts.
|
||||
*
|
||||
* @throws \Behat\Mink\Exception\ElementHtmlException
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
*/
|
||||
public function testBlockUrlTokenReplacement() {
|
||||
|
||||
$node1_url = $this->node1->toUrl();
|
||||
$node2_url = $this->node2->toUrl();
|
||||
|
||||
// Using a @dataprovider causes repeated database installations and takes a
|
||||
// very long time.
|
||||
$tests = [];
|
||||
$tests[] = [
|
||||
'token' => 'prefix_[current-page:url:path]_suffix',
|
||||
'expected1' => 'prefix_/' . $node1_url->getInternalPath() . '_suffix',
|
||||
'expected2' => 'prefix_/' . $node2_url->getInternalPath() . '_suffix',
|
||||
// A path can only be generated from a routed path.
|
||||
'expected3' => 'prefix_/_suffix',
|
||||
];
|
||||
$tests[] = [
|
||||
'token' => 'prefix_[current-page:url]_suffix',
|
||||
'expected1' => 'prefix_' . $node1_url->setAbsolute()->toString() . '_suffix',
|
||||
'expected2' => 'prefix_' . $node2_url->setAbsolute()->toString() . '_suffix',
|
||||
'expected3' => 'prefix_' . $this->getAbsoluteUrl('does-not-exist') . '_suffix',
|
||||
];
|
||||
|
||||
// Place a standard block and use a token in the label.
|
||||
$edit = [
|
||||
'id' => 'token_url_test_block',
|
||||
'label' => 'label',
|
||||
'label_display' => TRUE,
|
||||
];
|
||||
$this->placeBlock('system_powered_by_block', $edit);
|
||||
$block = Block::load('token_url_test_block');
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
foreach ($tests as $test) {
|
||||
// Set the block label.
|
||||
$block->getPlugin()->setConfigurationValue('label', $test['token']);
|
||||
$block->save();
|
||||
|
||||
// Go to the first node page and test that the token is correct.
|
||||
$this->drupalGet($node1_url);
|
||||
$assert_session->elementContains('css', '#block-token-url-test-block', $test['expected1']);
|
||||
|
||||
// Go to the second node page and check that the block title has changed.
|
||||
$this->drupalGet($node2_url);
|
||||
$assert_session->elementContains('css', '#block-token-url-test-block', $test['expected2']);
|
||||
|
||||
// Test the current page url on a 404 page.
|
||||
$this->drupalGet('does-not-exist');
|
||||
$assert_session->statusCodeEquals(404);
|
||||
$assert_session->elementContains('css', '#block-token-url-test-block', $test['expected3']);
|
||||
}
|
||||
|
||||
|
||||
// Can't do this test in the for loop above, it's too different.
|
||||
$block->getPlugin()->setConfigurationValue('label', 'prefix_[current-page:query:unicorns]_suffix');
|
||||
$block->save();
|
||||
|
||||
// Test the parameter token.
|
||||
$this->drupalGet($node1_url->setOption('query', ['unicorns' => 'fluffy']));
|
||||
$this->assertCacheContext('url.query_args');
|
||||
$assert_session->elementContains('css', '#block-token-url-test-block', 'prefix_fluffy_suffix');
|
||||
|
||||
// Change the parameter on the same page.
|
||||
$this->drupalGet($node1_url->setOption('query', ['unicorns' => 'dead']));
|
||||
$assert_session->elementContains('css', '#block-token-url-test-block', 'prefix_dead_suffix');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,8 +11,8 @@ class ArrayTest extends KernelTestBase {
|
|||
|
||||
function testArrayTokens() {
|
||||
// Test a simple array.
|
||||
$array = array(0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd');
|
||||
$tokens = array(
|
||||
$array = [0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd'];
|
||||
$tokens = [
|
||||
'first' => 'a',
|
||||
'last' => 'd',
|
||||
'value:0' => 'a',
|
||||
|
|
@ -27,19 +27,19 @@ class ArrayTest extends KernelTestBase {
|
|||
'join' => 'abcd',
|
||||
'join:, ' => 'a, b, c, d',
|
||||
'join: ' => 'a b c d',
|
||||
);
|
||||
$this->assertTokens('array', array('array' => $array), $tokens);
|
||||
];
|
||||
$this->assertTokens('array', ['array' => $array], $tokens);
|
||||
|
||||
// Test a mixed simple and render array.
|
||||
// 2 => c, 0 => a, 4 => d, 1 => b
|
||||
$array = array(
|
||||
$array = [
|
||||
'#property' => 'value',
|
||||
0 => 'a',
|
||||
1 => array('#markup' => 'b', '#weight' => 0.01),
|
||||
2 => array('#markup' => 'c', '#weight' => -10),
|
||||
4 => array('#markup' => 'd', '#weight' => 0),
|
||||
);
|
||||
$tokens = array(
|
||||
1 => ['#markup' => 'b', '#weight' => 0.01],
|
||||
2 => ['#markup' => 'c', '#weight' => -10],
|
||||
4 => ['#markup' => 'd', '#weight' => 0],
|
||||
];
|
||||
$tokens = [
|
||||
'first' => 'c',
|
||||
'last' => 'b',
|
||||
'value:0' => 'a',
|
||||
|
|
@ -54,7 +54,8 @@ class ArrayTest extends KernelTestBase {
|
|||
'join' => 'cadb',
|
||||
'join:, ' => 'c, a, d, b',
|
||||
'join: ' => 'c a d b',
|
||||
);
|
||||
$this->assertTokens('array', array('array' => $array), $tokens);
|
||||
];
|
||||
$this->assertTokens('array', ['array' => $array], $tokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ class BookTest extends KernelTestBase {
|
|||
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('node');
|
||||
$this->installSchema('book', array('book'));
|
||||
$this->installSchema('node', array('node_access'));
|
||||
$this->installConfig(array('node', 'book', 'field'));
|
||||
$this->installSchema('book', ['book']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installConfig(['node', 'book', 'field']);
|
||||
}
|
||||
|
||||
function testBookTokens() {
|
||||
|
|
@ -63,12 +63,12 @@ class BookTest extends KernelTestBase {
|
|||
'book:root' => $book_title,
|
||||
'book:root:nid' => $book->id(),
|
||||
'book:root:title' => $book_title,
|
||||
'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
|
||||
'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
|
||||
'book:root:content-type' => 'Book page',
|
||||
'book:parent' => null,
|
||||
'book:parents' => null,
|
||||
];
|
||||
$this->assertTokens('node', array('node' => $book), $tokens);
|
||||
$this->assertTokens('node', ['node' => $book], $tokens);
|
||||
|
||||
$tokens = [
|
||||
'nid' => $page1->id(),
|
||||
|
|
@ -77,15 +77,15 @@ class BookTest extends KernelTestBase {
|
|||
'book:root' => $book_title,
|
||||
'book:root:nid' => $book->id(),
|
||||
'book:root:title' => $book_title,
|
||||
'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
|
||||
'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
|
||||
'book:root:content-type' => 'Book page',
|
||||
'book:parent:nid' => $book->id(),
|
||||
'book:parent:title' => $book_title,
|
||||
'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
|
||||
'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
|
||||
'book:parents:count' => 1,
|
||||
'book:parents:join:/' => $book_title,
|
||||
];
|
||||
$this->assertTokens('node', array('node' => $page1), $tokens);
|
||||
$this->assertTokens('node', ['node' => $page1], $tokens);
|
||||
|
||||
$tokens = [
|
||||
'nid' => $page2->id(),
|
||||
|
|
@ -94,14 +94,15 @@ class BookTest extends KernelTestBase {
|
|||
'book:root' => $book_title,
|
||||
'book:root:nid' => $book->id(),
|
||||
'book:root:title' => $book_title,
|
||||
'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
|
||||
'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
|
||||
'book:root:content-type' => 'Book page',
|
||||
'book:parent:nid' => $page1->id(),
|
||||
'book:parent:title' => $page1->getTitle(),
|
||||
'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $page1->id()], array('absolute' => TRUE))->toString(),
|
||||
'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $page1->id()], ['absolute' => TRUE])->toString(),
|
||||
'book:parents:count' => 2,
|
||||
'book:parents:join:/' => $book_title . '/' . $page1->getTitle(),
|
||||
];
|
||||
$this->assertTokens('node', array('node' => $page2), $tokens);
|
||||
$this->assertTokens('node', ['node' => $page2], $tokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,21 +64,20 @@ class CommentTest extends KernelTestBase {
|
|||
// Fix http://example.com/index.php/comment/1 fails 'url:path' test.
|
||||
$parent_comment_path = $parent_comment->url();
|
||||
|
||||
$tokens = array(
|
||||
'url' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:absolute' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:relative' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->toString(),
|
||||
$tokens = [
|
||||
'url' => $parent_comment->toUrl('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:absolute' => $parent_comment->toUrl('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:relative' => $parent_comment->toUrl('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->toString(),
|
||||
'url:path' => $parent_comment_path,
|
||||
'parent:url:absolute' => NULL,
|
||||
);
|
||||
$this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
|
||||
];
|
||||
$this->assertTokens('comment', ['comment' => $parent_comment], $tokens);
|
||||
|
||||
$comment = Comment::create([
|
||||
'entity_id' => $node->id(),
|
||||
'pid' => $parent_comment->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'uid' => 1,
|
||||
'name' => 'anonymous user',
|
||||
'mail' => 'anonymous@example.com',
|
||||
'subject' => $this->randomMachineName(),
|
||||
|
|
@ -87,16 +86,16 @@ class CommentTest extends KernelTestBase {
|
|||
$comment->save();
|
||||
|
||||
// Fix http://example.com/index.php/comment/1 fails 'url:path' test.
|
||||
$comment_path = Url::fromRoute('entity.comment.canonical', array('comment' => $comment->id()))->toString();
|
||||
$comment_path = Url::fromRoute('entity.comment.canonical', ['comment' => $comment->id()])->toString();
|
||||
|
||||
$tokens = array(
|
||||
'url' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:absolute' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:relative' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->toString(),
|
||||
$tokens = [
|
||||
'url' => $comment->toUrl('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:absolute' => $comment->toUrl('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
|
||||
'url:relative' => $comment->toUrl('canonical', ['fragment' => "comment-{$comment->id()}"])->toString(),
|
||||
'url:path' => $comment_path,
|
||||
'parent:url:absolute' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
|
||||
);
|
||||
$this->assertTokens('comment', array('comment' => $comment), $tokens);
|
||||
'parent:url:absolute' => $parent_comment->toUrl('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
|
||||
];
|
||||
$this->assertTokens('comment', ['comment' => $comment], $tokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,12 @@ class DateTest extends KernelTestBase {
|
|||
}
|
||||
|
||||
function testDateTokens() {
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'token_module_test' => '1984',
|
||||
'invalid_format' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
$this->assertTokens('date', array('date' => 453859200), $tokens);
|
||||
$this->assertTokens('date', ['date' => 453859200], $tokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\token\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\taxonomy\VocabularyInterface;
|
||||
|
||||
|
|
@ -55,20 +55,21 @@ class EntityTest extends KernelTestBase {
|
|||
$this->assertIdentical($mapper->getTokenTypeForEntityType('invalid'), FALSE);
|
||||
$this->assertIdentical($mapper->getTokenTypeForEntityType('invalid', TRUE), 'invalid');
|
||||
|
||||
// Test that when we send the mis-matched entity type into token_replace()
|
||||
// that we still get the tokens replaced.
|
||||
$vocabulary = entity_load('taxonomy_vocabulary', 'tags');
|
||||
// Test that when we send the mis-matched entity type into
|
||||
// Drupal\Core\Utility\Token::replace() that we still get the tokens
|
||||
// replaced.
|
||||
$vocabulary = Vocabulary::load('tags');
|
||||
$term = $this->addTerm($vocabulary);
|
||||
$this->assertIdentical(\Drupal::token()->replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->label());
|
||||
$this->assertIdentical(\Drupal::token()->replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->label() . $vocabulary->label());
|
||||
$this->assertIdentical(\Drupal::token()->replace('[vocabulary:name]', ['taxonomy_vocabulary' => $vocabulary]), $vocabulary->label());
|
||||
$this->assertIdentical(\Drupal::token()->replace('[term:name][term:vocabulary:name]', ['taxonomy_term' => $term]), $term->label() . $vocabulary->label());
|
||||
}
|
||||
|
||||
function addTerm(VocabularyInterface $vocabulary, array $term = array()) {
|
||||
$term += array(
|
||||
'name' => Unicode::strtolower($this->randomMachineName(5)),
|
||||
function addTerm(VocabularyInterface $vocabulary, array $term = []) {
|
||||
$term += [
|
||||
'name' => mb_strtolower($this->randomMachineName(5)),
|
||||
'vid' => $vocabulary->id(),
|
||||
);
|
||||
$term = entity_create('taxonomy_term', $term);
|
||||
];
|
||||
$term = Term::create($term);
|
||||
$term->save();
|
||||
return $term;
|
||||
}
|
||||
|
|
@ -80,25 +81,26 @@ class EntityTest extends KernelTestBase {
|
|||
$node = Node::create(['type' => 'page', 'title' => 'Original title']);
|
||||
$node->save();
|
||||
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'nid' => $node->id(),
|
||||
'title' => 'Original title',
|
||||
'original' => NULL,
|
||||
'original:nid' => NULL,
|
||||
);
|
||||
$this->assertTokens('node', array('node' => $node), $tokens);
|
||||
];
|
||||
$this->assertTokens('node', ['node' => $node], $tokens);
|
||||
|
||||
// Emulate the original entity property that would be available from
|
||||
// node_save() and change the title for the node.
|
||||
$node->original = entity_load_unchanged('node', $node->id());
|
||||
$node->original = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($node->id());
|
||||
$node->title = 'New title';
|
||||
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'nid' => $node->id(),
|
||||
'title' => 'New title',
|
||||
'original' => 'Original title',
|
||||
'original:nid' => $node->id(),
|
||||
);
|
||||
$this->assertTokens('node', array('node' => $node), $tokens);
|
||||
];
|
||||
$this->assertTokens('node', ['node' => $node], $tokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ use Drupal\node\Entity\NodeType;
|
|||
use Drupal\contact\Entity\Message;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
|
||||
|
||||
/**
|
||||
* Tests field tokens.
|
||||
|
|
@ -191,30 +191,32 @@ class FieldTest extends KernelTestBase {
|
|||
$language->save();
|
||||
|
||||
// Add a datetime field.
|
||||
$field_datetime_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => 'field_datetime',
|
||||
'type' => 'datetime',
|
||||
'entity_type' => 'node',
|
||||
'settings' => array('datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME),
|
||||
));
|
||||
$field_datetime_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'field_datetime',
|
||||
'type' => 'datetime',
|
||||
'entity_type' => 'node',
|
||||
'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
]);
|
||||
$field_datetime_storage->save();
|
||||
$field_datetime = FieldConfig::create([
|
||||
'field_storage' => $field_datetime_storage,
|
||||
'bundle' => 'article',
|
||||
'field_storage' => $field_datetime_storage,
|
||||
'bundle' => 'article',
|
||||
]);
|
||||
$field_datetime->save();
|
||||
|
||||
// Add a daterange field.
|
||||
$field_daterange_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => 'field_daterange',
|
||||
'type' => 'daterange',
|
||||
'entity_type' => 'node',
|
||||
'settings' => array('datetime_type' => DateRangeItem::DATETIME_TYPE_DATETIME),
|
||||
));
|
||||
$field_daterange_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'field_daterange',
|
||||
'type' => 'daterange',
|
||||
'entity_type' => 'node',
|
||||
'settings' => ['datetime_type' => DateRangeItem::DATETIME_TYPE_DATETIME],
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
]);
|
||||
$field_daterange_storage->save();
|
||||
$field_daterange = FieldConfig::create([
|
||||
'field_storage' => $field_daterange_storage,
|
||||
'bundle' => 'article',
|
||||
'field_storage' => $field_daterange_storage,
|
||||
'bundle' => 'article',
|
||||
]);
|
||||
$field_daterange->save();
|
||||
}
|
||||
|
|
@ -676,11 +678,17 @@ class FieldTest extends KernelTestBase {
|
|||
'type' => 'article',
|
||||
]);
|
||||
|
||||
$node->set('field_datetime', '1925-09-28T00:00:00')->save();
|
||||
$node->set('field_datetime', ['1925-09-28T00:00:00', '1930-10-28T00:00:00'])->save();
|
||||
$this->assertTokens('node', ['node' => $node], [
|
||||
'field_datetime:date:custom:Y' => '1925',
|
||||
'field_datetime:date:html_month' => '1925-09',
|
||||
'field_datetime:date' => $node->field_datetime->date->getTimestamp(),
|
||||
'field_datetime:date' => $node->get('field_datetime')->date->getTimestamp(),
|
||||
'field_datetime:0:date:custom:Y' => '1925',
|
||||
'field_datetime:0:date:html_month' => '1925-09',
|
||||
'field_datetime:0:date' => $node->get('field_datetime')->date->getTimestamp(),
|
||||
'field_datetime:1:date:custom:Y' => '1930',
|
||||
'field_datetime:1:date:html_month' => '1930-10',
|
||||
'field_datetime:1:date' => $node->get('field_datetime')->get(1)->date->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -689,19 +697,34 @@ class FieldTest extends KernelTestBase {
|
|||
*/
|
||||
public function testDatetimeRangeFieldTokens() {
|
||||
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$node = Node::create([
|
||||
'title' => 'Node for daterange field',
|
||||
'type' => 'article',
|
||||
]);
|
||||
|
||||
$node->field_daterange->value = '2013-12-22T00:00:00';
|
||||
$node->field_daterange->end_value = '2016-08-26T00:00:00';
|
||||
$node->get('field_daterange')->value = '2013-12-22T00:00:00';
|
||||
$node->get('field_daterange')->end_value = '2016-08-26T00:00:00';
|
||||
$node->get('field_daterange')->appendItem([
|
||||
'value' => '2014-08-22T00:00:00',
|
||||
'end_value' => '2017-12-20T00:00:00',
|
||||
]);
|
||||
$node->get('field_daterange')->value = '2013-12-22T00:00:00';
|
||||
$node->get('field_daterange')->end_value = '2016-08-26T00:00:00';
|
||||
$node->save();
|
||||
$this->assertTokens('node', ['node' => $node], [
|
||||
'field_daterange:start_date:html_month' => '2013-12',
|
||||
'field_daterange:start_date:custom:Y' => '2013',
|
||||
'field_daterange:end_date:custom:Y' => '2016',
|
||||
'field_daterange:start_date' => $node->field_daterange->start_date->getTimestamp(),
|
||||
'field_daterange:start_date' => $node->get('field_daterange')->start_date->getTimestamp(),
|
||||
'field_daterange:0:start_date:html_month' => '2013-12',
|
||||
'field_daterange:0:start_date:custom:Y' => '2013',
|
||||
'field_daterange:0:end_date:custom:Y' => '2016',
|
||||
'field_daterange:0:start_date' => $node->get('field_daterange')->start_date->getTimestamp(),
|
||||
'field_daterange:1:start_date:html_month' => '2014-08',
|
||||
'field_daterange:1:start_date:custom:Y' => '2014',
|
||||
'field_daterange:1:end_date:custom:Y' => '2017',
|
||||
'field_daterange:1:end_date' => $node->get('field_daterange')->get(1)->end_date->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\token\Kernel;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
/**
|
||||
* Tests file tokens.
|
||||
*
|
||||
|
|
@ -14,7 +15,7 @@ class FileTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('file');
|
||||
public static $modules = ['file'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -26,30 +27,31 @@ class FileTest extends KernelTestBase {
|
|||
|
||||
function testFileTokens() {
|
||||
// Create a test file object.
|
||||
$file = entity_create('file', array(
|
||||
$file = File::create([
|
||||
'fid' => 1,
|
||||
'filename' => 'test.png',
|
||||
'filesize' => 100,
|
||||
'uri' => 'public://images/test.png',
|
||||
'filemime' => 'image/png',
|
||||
));
|
||||
]);
|
||||
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'basename' => 'test.png',
|
||||
'extension' => 'png',
|
||||
'size-raw' => 100,
|
||||
);
|
||||
$this->assertTokens('file', array('file' => $file), $tokens);
|
||||
];
|
||||
$this->assertTokens('file', ['file' => $file], $tokens);
|
||||
|
||||
// Test a file with no extension and a fake name.
|
||||
$file->filename = 'Test PNG image';
|
||||
$file->uri = 'public://images/test';
|
||||
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'basename' => 'test',
|
||||
'extension' => '',
|
||||
'size-raw' => 100,
|
||||
);
|
||||
$this->assertTokens('file', array('file' => $file), $tokens);
|
||||
];
|
||||
$this->assertTokens('file', ['file' => $file], $tokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,52 +48,53 @@ class NodeTest extends KernelTestBase {
|
|||
'type' => 'page',
|
||||
'title' => 'Source Title',
|
||||
'revision_log' => $this->randomMachineName(),
|
||||
'path' => array('alias' => '/content/source-node')
|
||||
'path' => ['alias' => '/content/source-node']
|
||||
]);
|
||||
$page->save();
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'log' => $page->revision_log->value,
|
||||
'url:path' => '/content/source-node',
|
||||
'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], array('absolute' => TRUE))->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], array('absolute' => FALSE))->toString(),
|
||||
'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], ['absolute' => TRUE])->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], ['absolute' => FALSE])->toString(),
|
||||
'url:unaliased:path' => "/node/{$page->id()}",
|
||||
'content-type' => 'Basic page',
|
||||
'content-type:name' => 'Basic page',
|
||||
'content-type:machine-name' => 'page',
|
||||
'content-type:description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.",
|
||||
'content-type:node-count' => 1,
|
||||
'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'page'], array('absolute' => TRUE))->toString(),
|
||||
'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'page'], ['absolute' => TRUE])->toString(),
|
||||
'source:title' => 'Source Title',
|
||||
// Deprecated tokens.
|
||||
'type' => 'page',
|
||||
'type-name' => 'Basic page',
|
||||
'url:alias' => '/content/source-node',
|
||||
);
|
||||
$this->assertTokens('node', array('node' => $page), $tokens);
|
||||
];
|
||||
$this->assertTokens('node', ['node' => $page], $tokens);
|
||||
|
||||
$article = Node::create([
|
||||
'type' => 'article',
|
||||
'title' => 'Source Title',
|
||||
]);
|
||||
$article->save();
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'log' => '',
|
||||
'url:path' => "/node/{$article->id()}",
|
||||
'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], array('absolute' => TRUE))->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], array('absolute' => FALSE))->toString(),
|
||||
'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], ['absolute' => TRUE])->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], ['absolute' => FALSE])->toString(),
|
||||
'url:unaliased:path' => "/node/{$article->id()}",
|
||||
'content-type' => 'Article',
|
||||
'content-type:name' => 'Article',
|
||||
'content-type:machine-name' => 'article',
|
||||
'content-type:description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.",
|
||||
'content-type:node-count' => 1,
|
||||
'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'article'], array('absolute' => TRUE))->toString(),
|
||||
'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'article'], ['absolute' => TRUE])->toString(),
|
||||
'source:title' => 'Source Title',
|
||||
// Deprecated tokens.
|
||||
'type' => 'article',
|
||||
'type-name' => 'Article',
|
||||
'url:alias' => "/node/{$article->id()}",
|
||||
);
|
||||
$this->assertTokens('node', array('node' => $article), $tokens);
|
||||
];
|
||||
$this->assertTokens('node', ['node' => $article], $tokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,18 +10,19 @@ namespace Drupal\Tests\token\Kernel;
|
|||
class RandomTest extends KernelTestBase {
|
||||
|
||||
function testRandomTokens() {
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'number' => '[0-9]{1,}',
|
||||
'hash:md5' => '[0-9a-f]{32}',
|
||||
'hash:sha1' => '[0-9a-f]{40}',
|
||||
'hash:sha256' => '[0-9a-f]{64}',
|
||||
'hash:invalid-algo' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
$first_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
|
||||
$second_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
|
||||
$first_set = $this->assertTokens('random', [], $tokens, ['regex' => TRUE]);
|
||||
$second_set = $this->assertTokens('random', [], $tokens, ['regex' => TRUE]);
|
||||
foreach ($first_set as $token => $value) {
|
||||
$this->assertNotIdentical($first_set[$token], $second_set[$token]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\token\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Core\Url;
|
||||
|
|
@ -13,6 +13,7 @@ use Drupal\Core\Url;
|
|||
* @group token
|
||||
*/
|
||||
class TaxonomyTest extends KernelTestBase {
|
||||
|
||||
protected $vocab;
|
||||
|
||||
/**
|
||||
|
|
@ -20,7 +21,7 @@ class TaxonomyTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('taxonomy', 'text', 'language');
|
||||
public static $modules = ['taxonomy', 'text', 'language'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -43,31 +44,31 @@ class TaxonomyTest extends KernelTestBase {
|
|||
* Test the additional taxonomy term tokens.
|
||||
*/
|
||||
function testTaxonomyTokens() {
|
||||
$root_term = $this->addTerm($this->vocab, array('name' => 'Root term', 'path' => array('alias' => '/root-term')));
|
||||
$tokens = array(
|
||||
'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
|
||||
'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => FALSE))->toString(),
|
||||
$root_term = $this->addTerm($this->vocab, ['name' => 'Root term', 'path' => ['alias' => '/root-term']]);
|
||||
$tokens = [
|
||||
'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
|
||||
'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => FALSE])->toString(),
|
||||
'url:path' => '/root-term',
|
||||
'url:unaliased:path' => "/taxonomy/term/{$root_term->id()}",
|
||||
'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
|
||||
'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
|
||||
'parents' => NULL,
|
||||
'parents:count' => NULL,
|
||||
'parents:keys' => NULL,
|
||||
'root' => NULL,
|
||||
// Deprecated tokens
|
||||
'url:alias' => '/root-term',
|
||||
);
|
||||
$this->assertTokens('term', array('term' => $root_term), $tokens);
|
||||
];
|
||||
$this->assertTokens('term', ['term' => $root_term], $tokens);
|
||||
|
||||
$parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->id()));
|
||||
$tokens = array(
|
||||
'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
|
||||
'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => FALSE))->toString(),
|
||||
$parent_term = $this->addTerm($this->vocab, ['name' => 'Parent term', 'parent' => $root_term->id()]);
|
||||
$tokens = [
|
||||
'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
|
||||
'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
|
||||
'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => FALSE])->toString(),
|
||||
'url:path' => "/taxonomy/term/{$parent_term->id()}",
|
||||
'url:unaliased:path' => "/taxonomy/term/{$parent_term->id()}",
|
||||
'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
|
||||
'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
|
||||
'parents' => 'Root term',
|
||||
'parents:count' => 1,
|
||||
'parents:keys' => $root_term->id(),
|
||||
|
|
@ -75,16 +76,16 @@ class TaxonomyTest extends KernelTestBase {
|
|||
'root:tid' => $root_term->id(),
|
||||
// Deprecated tokens
|
||||
'url:alias' => "/taxonomy/term/{$parent_term->id()}",
|
||||
);
|
||||
$this->assertTokens('term', array('term' => $parent_term), $tokens);
|
||||
];
|
||||
$this->assertTokens('term', ['term' => $parent_term], $tokens);
|
||||
|
||||
$term = $this->addTerm($this->vocab, array('name' => 'Test term', 'parent' => $parent_term->id()));
|
||||
$tokens = array(
|
||||
$term = $this->addTerm($this->vocab, ['name' => 'Test term', 'parent' => $parent_term->id()]);
|
||||
$tokens = [
|
||||
'parents' => 'Root term, Parent term',
|
||||
'parents:count' => 2,
|
||||
'parents:keys' => implode(', ', array($root_term->id(), $parent_term->id())),
|
||||
);
|
||||
$this->assertTokens('term', array('term' => $term), $tokens);
|
||||
'parents:keys' => implode(', ', [$root_term->id(), $parent_term->id()]),
|
||||
];
|
||||
$this->assertTokens('term', ['term' => $term], $tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,28 +93,28 @@ class TaxonomyTest extends KernelTestBase {
|
|||
*/
|
||||
function testVocabularyTokens() {
|
||||
$vocabulary = $this->vocab;
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'machine-name' => 'tags',
|
||||
'edit-url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], array('absolute' => TRUE))->toString(),
|
||||
);
|
||||
$this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens);
|
||||
'edit-url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], ['absolute' => TRUE])->toString(),
|
||||
];
|
||||
$this->assertTokens('vocabulary', ['vocabulary' => $vocabulary], $tokens);
|
||||
}
|
||||
|
||||
function addVocabulary(array $vocabulary = array()) {
|
||||
$vocabulary += array(
|
||||
'name' => Unicode::strtolower($this->randomMachineName(5)),
|
||||
'nodes' => array('article' => 'article'),
|
||||
);
|
||||
$vocabulary = entity_create('taxonomy_vocabulary', $vocabulary)->save();
|
||||
function addVocabulary(array $vocabulary = []) {
|
||||
$vocabulary += [
|
||||
'name' => mb_strtolower($this->randomMachineName(5)),
|
||||
'nodes' => ['article' => 'article'],
|
||||
];
|
||||
$vocabulary = Vocabulary::create($vocabulary)->save();
|
||||
return $vocabulary;
|
||||
}
|
||||
|
||||
function addTerm($vocabulary, array $term = array()) {
|
||||
$term += array(
|
||||
'name' => Unicode::strtolower($this->randomMachineName(5)),
|
||||
function addTerm($vocabulary, array $term = []) {
|
||||
$term += [
|
||||
'name' => mb_strtolower($this->randomMachineName(5)),
|
||||
'vid' => $vocabulary->id(),
|
||||
);
|
||||
$term = entity_create('taxonomy_term', $term);
|
||||
];
|
||||
$term = Term::create($term);
|
||||
$term->save();
|
||||
return $term;
|
||||
}
|
||||
|
|
@ -146,6 +147,8 @@ class TaxonomyTest extends KernelTestBase {
|
|||
])->save();
|
||||
|
||||
// Expect the parent term to be in the specified language.
|
||||
$this->assertTokens('term', array('term' => $child_term), ['parents' => 'german-parent-term'], ['langcode' => 'de']);
|
||||
$this->assertTokens('term', ['term' => $child_term], ['parents' => 'german-parent-term'], ['langcode' => 'de']);
|
||||
$this->assertTokens('term', ['term' => $child_term], ['root' => 'german-parent-term'], ['langcode' => 'de']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ class UnitTest extends KernelTestBase {
|
|||
* Test invalid tokens.
|
||||
*/
|
||||
public function testGetInvalidTokens() {
|
||||
$tests = array();
|
||||
$tests[] = array(
|
||||
'valid tokens' => array(
|
||||
$tests = [];
|
||||
$tests[] = [
|
||||
'valid tokens' => [
|
||||
'[node:title]',
|
||||
'[node:created:short]',
|
||||
'[node:created:custom:invalid]',
|
||||
|
|
@ -46,8 +46,8 @@ class UnitTest extends KernelTestBase {
|
|||
'[current-date:short]',
|
||||
'[current-user:uid]',
|
||||
'[current-user:ip-address]',
|
||||
),
|
||||
'invalid tokens' => array(
|
||||
],
|
||||
'invalid tokens' => [
|
||||
'[node:title:invalid]',
|
||||
'[node:created:invalid]',
|
||||
'[node:created:short:invalid]',
|
||||
|
|
@ -62,11 +62,11 @@ class UnitTest extends KernelTestBase {
|
|||
'[node:type]',
|
||||
'[node:type-name]',
|
||||
'[date:short]',
|
||||
),
|
||||
'types' => array('node'),
|
||||
);
|
||||
$tests[] = array(
|
||||
'valid tokens' => array(
|
||||
],
|
||||
'types' => ['node'],
|
||||
];
|
||||
$tests[] = [
|
||||
'valid tokens' => [
|
||||
'[node:title]',
|
||||
'[node:created:short]',
|
||||
'[node:created:custom:invalid]',
|
||||
|
|
@ -77,8 +77,8 @@ class UnitTest extends KernelTestBase {
|
|||
'[user:uid]',
|
||||
'[current-date:short]',
|
||||
'[current-user:uid]',
|
||||
),
|
||||
'invalid tokens' => array(
|
||||
],
|
||||
'invalid tokens' => [
|
||||
'[node:title:invalid]',
|
||||
'[node:created:invalid]',
|
||||
'[node:created:short:invalid]',
|
||||
|
|
@ -91,9 +91,9 @@ class UnitTest extends KernelTestBase {
|
|||
'[node:tnid]',
|
||||
'[node:type]',
|
||||
'[node:type-name]',
|
||||
),
|
||||
'types' => array('all'),
|
||||
);
|
||||
],
|
||||
'types' => ['all'],
|
||||
];
|
||||
|
||||
foreach ($tests as $test) {
|
||||
$tokens = array_merge($test['valid tokens'], $test['invalid tokens']);
|
||||
|
|
@ -116,4 +116,5 @@ class UnitTest extends KernelTestBase {
|
|||
$this->assertNull($this->tokenService->getTokenInfo('user_role', 'url'));
|
||||
$this->assertNull($this->tokenService->getTypeInfo('user_role'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
88
web/modules/contrib/token/tests/src/Kernel/UrlTest.php
Normal file
88
web/modules/contrib/token/tests/src/Kernel/UrlTest.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\token\Kernel;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Test generic url token replacements.
|
||||
*
|
||||
* @group token
|
||||
*/
|
||||
class UrlTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* The token service.
|
||||
*
|
||||
* @var \Drupal\Core\Utility\Token
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* The current request stack.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
* The current route match.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\CurrentRouteMatch
|
||||
*/
|
||||
protected $currentRouteMatch;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->token = $this->container->get('token');
|
||||
$this->requestStack = $this->container->get('request_stack');
|
||||
$this->currentRouteMatch = $this->container->get('current_route_match');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the url token replacements for current requests.
|
||||
*
|
||||
* The method ::expectedCurrentRequestUrlResults() is not declared
|
||||
* as a regular data provider, because it might use services from
|
||||
* the global Drupal container, which is not initialized yet during
|
||||
* the invocation of data providers.
|
||||
*/
|
||||
public function testCurrentRequestUrls() {
|
||||
foreach ($this->expectedCurrentRequestUrlResults() as $data_set) {
|
||||
list ($request, $text, $data, $options, $expected_output) = $data_set;
|
||||
// Set the request as the current one.
|
||||
$this->requestStack->pop();
|
||||
$this->requestStack->push($request);
|
||||
$this->currentRouteMatch->resetRouteMatch();
|
||||
|
||||
$this->assertEquals($expected_output, $this->token->replace($text, $data, $options));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of results to expect for ::testRequestUrls().
|
||||
*
|
||||
* Each data set of this array holds the following order:
|
||||
* - The request object to test for.
|
||||
* - The input text as string.
|
||||
* - The token data as array.
|
||||
* - Further options for the token replacement as array.
|
||||
* - The output to expect after token replacement.
|
||||
*
|
||||
* @return array
|
||||
* The list of results to expect.
|
||||
*/
|
||||
public function expectedCurrentRequestUrlResults() {
|
||||
return [
|
||||
[Request::createFromGlobals(), '[current-page:url]', [], [], Url::createFromRequest(Request::createFromGlobals())->setAbsolute()->toString()],
|
||||
[Request::create('/should-not-exist'), '[current-page:url:path]', [], [], '/'],
|
||||
[Request::create('/https://drupal.org/'), '[current-page:url:absolute]', [], [], '[current-page:url:absolute]'],
|
||||
[Request::create('/https://drupal.org/'), '[current-page:url:absolute]', [], ['clear' => TRUE], ''],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
50
web/modules/contrib/token/tests/src/Kernel/ViewsTest.php
Normal file
50
web/modules/contrib/token/tests/src/Kernel/ViewsTest.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\token\Kernel;
|
||||
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Test the views tokens.
|
||||
*
|
||||
* @group token
|
||||
*/
|
||||
class ViewsTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['views', 'block'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['token_views_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
ViewTestData::createTestViews(get_class($this), ['token_module_test']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests path token replacements generated from a view without a path.
|
||||
*/
|
||||
public function testTokenReplacementNoPath() {
|
||||
$token_handler = \Drupal::token();
|
||||
$view = Views::getView('token_views_test');
|
||||
$view->setDisplay('block_1');
|
||||
$view->execute();
|
||||
|
||||
$this->assertSame('', $token_handler->replace('[view:url]', ['view' => $view]), 'Token [view:url] is empty for views without path.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue