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,13 @@
|
|||
name: 'Pathauto testing module'
|
||||
type: module
|
||||
# core: '8.x'
|
||||
description: 'Pathauto for Entity with string ID.'
|
||||
package: Testing
|
||||
dependencies:
|
||||
- token
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-09-08
|
||||
version: '8.x-1.3'
|
||||
core: '8.x'
|
||||
project: 'pathauto'
|
||||
datestamp: 1536407890
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\pathauto_string_id_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
||||
/**
|
||||
* Defines a test entity with a string ID.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "pathauto_string_id_test",
|
||||
* label = @Translation("Test entity with string ID"),
|
||||
* handlers = {
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "pathauto_string_id_test",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "name",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/pathauto_string_id_test/{pathauto_string_id_test}",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class PathautoStringIdTest extends ContentEntityBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields['id'] = BaseFieldDefinition::create('string')
|
||||
->setLabel('ID')
|
||||
->setReadOnly(TRUE)
|
||||
// A bigger value will not be allowed to build the index.
|
||||
->setSetting('max_length', 191);
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel('Name');
|
||||
$fields['path'] = BaseFieldDefinition::create('path')
|
||||
->setLabel('Path')
|
||||
->setComputed(TRUE);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,8 +7,8 @@ package: Testing
|
|||
dependencies:
|
||||
- views
|
||||
|
||||
# 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-08
|
||||
version: '8.x-1.3'
|
||||
core: '8.x'
|
||||
project: 'pathauto'
|
||||
datestamp: 1493468049
|
||||
datestamp: 1536407890
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\pathauto\Kernel;
|
||||
|
||||
use Drupal\Component\Serialization\PhpSerialize;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\KeyValueStore\KeyValueDatabaseFactory;
|
||||
use Drupal\pathauto\PathautoState;
|
||||
use Drupal\pathauto\Tests\PathautoTestHelperTrait;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\pathauto_string_id_test\Entity\PathautoStringIdTest;
|
||||
|
||||
/**
|
||||
* Tests auto-aliasing of entities that use string IDs.
|
||||
*
|
||||
* @group pathauto
|
||||
*/
|
||||
class PathautoEntityWithStringIdTest extends KernelTestBase {
|
||||
|
||||
use PathautoTestHelperTrait;
|
||||
|
||||
/**
|
||||
* The alias type plugin instance.
|
||||
*
|
||||
* @var \Drupal\pathauto\AliasTypeBatchUpdateInterface
|
||||
*/
|
||||
protected $aliasType;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = [
|
||||
'system',
|
||||
'user',
|
||||
'field',
|
||||
'token',
|
||||
'path',
|
||||
'pathauto',
|
||||
'pathauto_string_id_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
parent::register($container);
|
||||
// Kernel tests are using the 'keyvalue.memory' store but we want to test
|
||||
// against the 'keyvalue.database'.
|
||||
$container
|
||||
->register('keyvalue.database', KeyValueDatabaseFactory::class)
|
||||
->addArgument(new PhpSerialize())
|
||||
->addArgument($container->get('database'))
|
||||
->addTag('persist');
|
||||
$container->setAlias('keyvalue', 'keyvalue.database');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', ['key_value']);
|
||||
$this->installConfig(['system', 'pathauto']);
|
||||
$this->installEntitySchema('pathauto_string_id_test');
|
||||
$this->createPattern('pathauto_string_id_test', '/[pathauto_string_id_test:name]');
|
||||
/** @var \Drupal\pathauto\AliasTypeManager $alias_type_manager */
|
||||
$alias_type_manager = $this->container->get('plugin.manager.alias_type');
|
||||
$this->aliasType = $alias_type_manager->createInstance('canonical_entities:pathauto_string_id_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test aliasing entities with long string ID.
|
||||
*
|
||||
* @dataProvider entityWithStringIdProvider
|
||||
*
|
||||
* @param string|int $id
|
||||
* The entity ID
|
||||
* @param string $expected_key
|
||||
* The expected key for 'pathauto_state.*' collections.
|
||||
*/
|
||||
public function testEntityWithStringId($id, $expected_key) {
|
||||
$entity = PathautoStringIdTest::create([
|
||||
'id' => $id,
|
||||
'name' => $name = $this->randomMachineName(),
|
||||
]);
|
||||
$entity->save();
|
||||
|
||||
// Check that the path was generated.
|
||||
$this->assertEntityAlias($entity, mb_strtolower("/$name"));
|
||||
// Check that the path auto state was saved with the expected key.
|
||||
$value = \Drupal::keyValue('pathauto_state.pathauto_string_id_test')->get($expected_key);
|
||||
$this->assertEquals(PathautoState::CREATE, $value);
|
||||
|
||||
$context = [];
|
||||
// Batch delete uses the key-value store collection 'pathauto_state.*. We
|
||||
// test that after a bulk delete all aliases are removed. Running only once
|
||||
// the batch delete process is enough as the batch size is 100.
|
||||
$this->aliasType->batchDelete($context);
|
||||
|
||||
// Check that the paths were removed on batch delete.
|
||||
$this->assertNoEntityAliasExists($entity, "/$name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test cases for ::testEntityWithStringId().
|
||||
*
|
||||
* @see \Drupal\Tests\pathauto\Kernel\PathautoEntityWithStringIdTest::testEntityWithStringId()
|
||||
*/
|
||||
public function entityWithStringIdProvider() {
|
||||
return [
|
||||
'ascii with less or equal 128 chars' => [
|
||||
str_repeat('a', 128), str_repeat('a', 128)
|
||||
],
|
||||
'ascii with over 128 chars' => [
|
||||
str_repeat('a', 191), Crypt::hashBase64(str_repeat('a', 191))
|
||||
],
|
||||
'non-ascii with less or equal 128 chars' => [
|
||||
str_repeat('社', 128), Crypt::hashBase64(str_repeat('社', 128))
|
||||
],
|
||||
'non-ascii with over 128 chars' => [
|
||||
str_repeat('社', 191), Crypt::hashBase64(str_repeat('社', 191))
|
||||
],
|
||||
'simulating an integer id' => [
|
||||
123, '123'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\Tests\pathauto\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
@ -285,7 +284,7 @@ class PathautoKernelTest extends KernelTestBase {
|
|||
$this->assertEntityAlias($node, '/content/second-title');
|
||||
$this->assertNoAliasExists(array('alias' => '/content/first-title'));
|
||||
|
||||
// Test PATHAUTO_UPDATE_ACTION_LEAVE
|
||||
// Test PATHAUTO_UPDATE_ACTION_LEAVE.
|
||||
$config->set('update_action', PathautoGeneratorInterface::UPDATE_ACTION_LEAVE);
|
||||
$config->save();
|
||||
$node->setTitle('Third title');
|
||||
|
@ -323,8 +322,8 @@ class PathautoKernelTest extends KernelTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that \Drupal::service('pathauto.generator')->createEntityAlias() will not create an alias for a pattern
|
||||
* that does not get any tokens replaced.
|
||||
* Test that \Drupal::service('pathauto.generator')->createEntityAlias() will
|
||||
* not create an alias for a pattern that does not get any tokens replaced.
|
||||
*/
|
||||
public function testNoTokensNoAlias() {
|
||||
$this->installConfig(['filter']);
|
||||
|
@ -365,12 +364,11 @@ class PathautoKernelTest extends KernelTestBase {
|
|||
function testParentChildPathTokens() {
|
||||
// First create a field which will be used to create the path. It must
|
||||
// begin with a letter.
|
||||
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
|
||||
Vocabulary::create(['vid' => 'tags'])->save();
|
||||
|
||||
$fieldname = 'a' . Unicode::strtolower($this->randomMachineName());
|
||||
$fieldname = 'a' . mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create(['entity_type' => 'taxonomy_term', 'field_name' => $fieldname, 'type' => 'string']);
|
||||
$field_storage->save();
|
||||
$field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => 'tags']);
|
||||
|
@ -391,11 +389,11 @@ class PathautoKernelTest extends KernelTestBase {
|
|||
// Create the child term.
|
||||
$child = Term::create(['vid' => 'tags', $fieldname => $this->randomMachineName(), 'parent' => $parent, 'name' => $this->randomMachineName()]);
|
||||
$child->save();
|
||||
$this->assertEntityAlias($child, '/' . Unicode::strtolower($parent->getName() . '/' . $child->$fieldname->value));
|
||||
$this->assertEntityAlias($child, '/' . mb_strtolower($parent->getName() . '/' . $child->$fieldname->value));
|
||||
|
||||
// Re-saving the parent term should not modify the child term's alias.
|
||||
$parent->save();
|
||||
$this->assertEntityAlias($child, '/' . Unicode::strtolower($parent->getName() . '/' . $child->$fieldname->value));
|
||||
$this->assertEntityAlias($child, '/' . mb_strtolower($parent->getName() . '/' . $child->$fieldname->value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -506,7 +504,7 @@ class PathautoKernelTest extends KernelTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that enabled entity types genrates the necessary fields and plugins.
|
||||
* Tests that enabled entity types generates the necessary fields and plugins.
|
||||
*/
|
||||
public function testSettingChangeInvalidatesCache() {
|
||||
|
||||
|
@ -547,6 +545,22 @@ class PathautoKernelTest extends KernelTestBase {
|
|||
$this->assertEntityAlias($node1, '/content/default-revision');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the pathauto state property gets set to CREATED for new nodes.
|
||||
*
|
||||
* In some cases, this can trigger $node->path to be set up with no default
|
||||
* value for the pathauto property.
|
||||
*/
|
||||
public function testCreateNodeWhileAccessingPath() {
|
||||
$node = Node::create([
|
||||
'type' => 'article',
|
||||
'title' => 'TestAlias',
|
||||
]);
|
||||
$node->path->langcode;
|
||||
$node->save();
|
||||
$this->assertEntityAlias($node, '/content/testalias');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node programmatically.
|
||||
*
|
||||
|
|
|
@ -39,6 +39,42 @@ class PathautoTokenTest extends KernelTestBase {
|
|||
$alias_cleaner = \Drupal::service('pathauto.alias_cleaner');
|
||||
$alias_cleaner->cleanTokenValues($replacements, $data, array());
|
||||
$this->assertEqual($replacements['[array:join-path]'], 'test-first-arg/array-value');
|
||||
|
||||
// Test additional token cleaning and its configuration.
|
||||
$safe_tokens = $this->config('pathauto.settings')->get('safe_tokens');
|
||||
$safe_tokens[] = 'safe';
|
||||
$this->config('pathauto.settings')
|
||||
->set('safe_tokens', $safe_tokens)
|
||||
->save();
|
||||
|
||||
$safe_tokens = [
|
||||
'[example:path]',
|
||||
'[example:url]',
|
||||
'[example:url-brief]',
|
||||
'[example:login-url]',
|
||||
'[example:login-url:relative]',
|
||||
'[example:url:relative]',
|
||||
'[example:safe]',
|
||||
];
|
||||
$unsafe_tokens = [
|
||||
'[example:path_part]',
|
||||
'[example:something_url]',
|
||||
'[example:unsafe]',
|
||||
];
|
||||
foreach ($safe_tokens as $token) {
|
||||
$replacements = [
|
||||
$token => 'this/is/a/path',
|
||||
];
|
||||
$alias_cleaner->cleanTokenValues($replacements);
|
||||
$this->assertEquals('this/is/a/path', $replacements[$token], "Token $token cleaned.");
|
||||
}
|
||||
foreach ($unsafe_tokens as $token) {
|
||||
$replacements = [
|
||||
$token => 'This is not a / path',
|
||||
];
|
||||
$alias_cleaner->cleanTokenValues($replacements);
|
||||
$this->assertEquals('not-path', $replacements[$token], "Token $token not cleaned.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,59 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\pathauto\Unit {
|
||||
namespace Drupal\Tests\pathauto\Unit;
|
||||
|
||||
use Drupal\pathauto\VerboseMessenger;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\Messenger\MessengerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\pathauto\VerboseMessenger;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\pathauto\VerboseMessenger
|
||||
* @group pathauto
|
||||
*/
|
||||
class VerboseMessengerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\pathauto\VerboseMessenger
|
||||
* @group pathauto
|
||||
* The messenger under test.
|
||||
*
|
||||
* @var \Drupal\pathauto\VerboseMessenger
|
||||
*/
|
||||
class VerboseMessengerTest extends UnitTestCase {
|
||||
protected $messenger;
|
||||
|
||||
/**
|
||||
* The messenger under test.
|
||||
*
|
||||
* @var \Drupal\pathauto\VerboseMessenger
|
||||
*/
|
||||
protected $messenger;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$config_factory = $this->getConfigFactoryStub(['pathauto.settings' => ['verbose' => TRUE]]);
|
||||
$account = $this->createMock(AccountInterface::class);
|
||||
$account->expects($this->once())
|
||||
->method('hasPermission')
|
||||
->withAnyParameters()
|
||||
->willReturn(TRUE);
|
||||
$messenger = $this->createMock(MessengerInterface::class);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$config_factory = $this->getConfigFactoryStub(array('pathauto.settings' => array('verbose' => TRUE)));
|
||||
$account = $this->getMock('\Drupal\Core\Session\AccountInterface');
|
||||
$account->expects($this->once())
|
||||
->method('hasPermission')
|
||||
->withAnyParameters()
|
||||
->willReturn(TRUE);
|
||||
|
||||
$this->messenger = new VerboseMessenger($config_factory, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests add messages.
|
||||
* @covers ::addMessage
|
||||
*/
|
||||
public function testAddMessage() {
|
||||
$this->assertTrue($this->messenger->addMessage("Test message"), "The message was added");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::addMessage
|
||||
*/
|
||||
public function testDoNotAddMessageWhileBulkupdate() {
|
||||
$this->assertFalse($this->messenger->addMessage("Test message", "bulkupdate"), "The message was NOT added");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
namespace {
|
||||
// @todo Delete after https://drupal.org/node/1858196 is in.
|
||||
if (!function_exists('drupal_set_message')) {
|
||||
function drupal_set_message() {
|
||||
}
|
||||
$this->messenger = new VerboseMessenger($config_factory, $account, $messenger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests add messages.
|
||||
*
|
||||
* @covers ::addMessage
|
||||
*/
|
||||
public function testAddMessage() {
|
||||
$this->assertTrue($this->messenger->addMessage("Test message"), "The message was added");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::addMessage
|
||||
*/
|
||||
public function testDoNotAddMessageWhileBulkupdate() {
|
||||
$this->assertFalse($this->messenger->addMessage("Test message", "bulkupdate"), "The message was NOT added");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue