diff --git a/README.md b/README.md index d21f135..2799839 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Implementations are provided for core entity types: content, taxonomy terms, and users (including blogs and forum pages). Pathauto also provides a way to delete large numbers of aliases. This feature -is available at Administer > Configuration > Search and metadata > URL aliases > -Delete aliases. +is available at Administer > Configuration > Search and metadata > URL aliases +> Delete aliases. ##Benefits @@ -59,9 +59,12 @@ for that content type. ## Installing Pathauto 1. Install the module as normal, note that there are two dependencies. -2. Configure the module at admin/config/search/path/patterns - add a new pattern by creating by clicking "Add Pathauto pattern". -3. Fill out "Path pattern" with fx [node:title], choose which content types this applies to, give it a label (the name) and save it. -4. When you save new content from now on, it should automatically be assigned an alternative URL +2. Configure the module at admin/config/search/path/patterns - add a new pattern +by creating by clicking "Add Pathauto pattern". +3. Fill out "Path pattern" with fx [node:title], choose which content types this +applies to, give it a label (the name) and save it. +4. When you save new content from now on, it should automatically be assigned an +alternative URL ##Credits: diff --git a/pathauto.api.php b/pathauto.api.php index e4d7594..03ea54c 100644 --- a/pathauto.api.php +++ b/pathauto.api.php @@ -8,6 +8,8 @@ use Drupal\Core\Language\Language; /** + * Pathauto API. + * * @todo Update for 8.x-1.x * * It may be helpful to review some examples of integration from @@ -133,7 +135,7 @@ function hook_pathauto_pattern_alter(&$pattern, array $context) { * - 'pattern': A string of the pattern used for aliasing the object. */ function hook_pathauto_alias_alter(&$alias, array &$context) { - // Add a suffix so that all aliases get saved as 'content/my-title.html' + // Add a suffix so that all aliases get saved as 'content/my-title.html'. $alias .= '.html'; // Force all aliases to be saved as language neutral. @@ -143,7 +145,7 @@ function hook_pathauto_alias_alter(&$alias, array &$context) { /** * Alter the list of punctuation characters for Pathauto control. * - * @param $punctuation + * @param array $punctuation * An array of punctuation to be controlled by Pathauto during replacement * keyed by punctuation name. Each punctuation record should be an array * with the following key/value pairs: diff --git a/pathauto.install b/pathauto.install index f8de322..9db767a 100644 --- a/pathauto.install +++ b/pathauto.install @@ -8,15 +8,13 @@ */ use Drupal\Core\Entity\Entity\EntityFormDisplay; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\pathauto\Entity\PathautoPattern; /** * Implements hook_install(). */ function pathauto_install() { - // Set the weight to 1 + // Set the weight to 1. module_set_weight('pathauto', 1); // Ensure the url_alias table exists. @@ -143,7 +141,7 @@ function pathauto_update_8100() { 'id' => 'entity_bundle:' . $entity_type, 'bundles' => array($bundle => $bundle), 'negate' => FALSE, - 'context_mapping' => [ $entity_type => $entity_type ], + 'context_mapping' => [$entity_type => $entity_type], ]); $pattern->save(); @@ -170,7 +168,8 @@ function pathauto_update_8100() { continue; } - // This is a pattern for a bundle and a language, such as "node_article_es". + // This is a pattern for a bundle and a language, + // such as "node_article_es". $pattern = PathautoPattern::create([ 'id' => $entity_type . '_' . $extracted_bundle . '_' . str_replace('-', '_', $langcode), 'label' => $entity_label . ' ' . $bundle_info[$extracted_bundle]['label'] . ' ' . $language->getName(), @@ -184,18 +183,18 @@ function pathauto_update_8100() { 'id' => 'entity_bundle:' . $entity_type, 'bundles' => array($extracted_bundle => $extracted_bundle), 'negate' => FALSE, - 'context_mapping' => [ $entity_type => $entity_type ], + 'context_mapping' => [$entity_type => $entity_type], ]); // Add the language condition. $language_mapping = $entity_type . ':' . $entity_type_manager->getDefinition($entity_type)->getKey('langcode') . ':language'; $pattern->addSelectionCondition([ 'id' => 'language', - 'langcodes' => [ $langcode => $langcode ], + 'langcodes' => [$langcode => $langcode], 'negate' => FALSE, 'context_mapping' => [ 'language' => $language_mapping, - ] + ], ]); // Add the context relationship for this language. diff --git a/pathauto.js b/pathauto.js index d4e068f..c63b8ed 100644 --- a/pathauto.js +++ b/pathauto.js @@ -1,3 +1,8 @@ +/** + * @file + * Name: pathauto.js. + */ + (function ($) { 'use strict'; Drupal.behaviors.pathFieldsetSummaries = { diff --git a/pathauto.links.action.yml b/pathauto.links.action.yml index d68b94a..0afa384 100644 --- a/pathauto.links.action.yml +++ b/pathauto.links.action.yml @@ -3,4 +3,3 @@ entity.pathauto_pattern.add_form: title: 'Add Pathauto pattern' appears_on: - entity.pathauto_pattern.collection - diff --git a/pathauto.module b/pathauto.module index 6440bb8..e8f9083 100644 --- a/pathauto.module +++ b/pathauto.module @@ -1,4 +1,5 @@ updateEntityAlias($entity, 'update'); } - /** * Implements hook_entity_update(). */ @@ -176,8 +178,10 @@ function pathauto_entity_base_field_info_alter(&$fields, EntityTypeInterface $en } /** + * Pattern validate. + * * Validate the pattern field, to ensure it doesn't contain any characters that - * are invalid in URLs + * are invalid in URLs. */ function pathauto_pattern_validate($element, FormStateInterface $form_state) { @@ -193,7 +197,10 @@ function pathauto_pattern_validate($element, FormStateInterface $form_state) { } if (!empty($invalid_characters_used)) { - $form_state->setError($element, t('The %element-title is using the following invalid characters: @invalid-characters.', array('%element-title' => $title, '@invalid-characters' => implode(', ', $invalid_characters_used)))); + $form_state->setError($element, t('The %element-title is using the following invalid characters: @invalid-characters.', array( + '%element-title' => $title, + '@invalid-characters' => implode(', ', $invalid_characters_used), + ))); } } diff --git a/src/AliasCleaner.php b/src/AliasCleaner.php index 340a266..0512394 100644 --- a/src/AliasCleaner.php +++ b/src/AliasCleaner.php @@ -47,9 +47,8 @@ class AliasCleaner implements AliasCleanerInterface { /** * Calculated settings cache. * - * @todo Split this up into separate properties. - * * @var array + * @todo Split this up into separate properties. */ protected $cleanStringCache = array(); @@ -272,7 +271,6 @@ class AliasCleaner implements AliasCleanerInterface { return $output; } - /** * {@inheritdoc} */ diff --git a/src/AliasCleanerInterface.php b/src/AliasCleanerInterface.php index 87cc27e..0ad5e17 100644 --- a/src/AliasCleanerInterface.php +++ b/src/AliasCleanerInterface.php @@ -3,6 +3,8 @@ namespace Drupal\pathauto; /** + * Alias Cleaner Interface. + * * @todo add class comment. */ interface AliasCleanerInterface { @@ -13,7 +15,8 @@ interface AliasCleanerInterface { * Performs the following alterations: * - Trim duplicate, leading, and trailing back-slashes. * - Trim duplicate, leading, and trailing separators. - * - Shorten to a desired length and logical position based on word boundaries. + * - Shorten to a desired length and logical position based on word + * boundaries. * * @param string $alias * A string with the URL alias to clean up. @@ -52,7 +55,8 @@ interface AliasCleanerInterface { * - Replace whitespace with the separator character. * - Trim duplicate, leading, and trailing separators. * - Convert to lower-case. - * - Shorten to a desired length and logical position based on word boundaries. + * - Shorten to a desired length and logical position based on word + * boundaries. * * This function should *not* be called on URL alias or path strings * because it is assumed that they are already clean. @@ -72,8 +76,8 @@ interface AliasCleanerInterface { /** * Return an array of arrays for punctuation values. * - * Returns an array of arrays for punctuation values keyed by a name, including - * the value and a textual description. + * Returns an array of arrays for punctuation values keyed by a name, + * including the value and a textual description. * Can and should be expanded to include "all" non text punctuation values. * * @return array diff --git a/src/AliasStorageHelperInterface.php b/src/AliasStorageHelperInterface.php index 4f17880..bf1c22b 100644 --- a/src/AliasStorageHelperInterface.php +++ b/src/AliasStorageHelperInterface.php @@ -1,6 +1,7 @@ aliasManager->getPathByAlias($alias, $langcode)) { if ($existing_source != $alias) { - // If it is an alias for the provided source, it is allowed to keep using - // it. If not, then it is reserved. + // If it is an alias for the provided source, it is allowed to keep + // using it. If not, then it is reserved. return $existing_source != $source; } diff --git a/src/AliasUniquifierInterface.php b/src/AliasUniquifierInterface.php index 2da4ba2..45547eb 100644 --- a/src/AliasUniquifierInterface.php +++ b/src/AliasUniquifierInterface.php @@ -1,6 +1,7 @@ $error_operation[0], '@args' => print_r($error_operation[0], TRUE)))); + drupal_set_message(t('An error occurred while processing @operation with arguments : @args', array( + '@operation' => $error_operation[0], + '@args' => print_r($error_operation[0], TRUE), + ))); } } diff --git a/src/Form/PathautoSettingsForm.php b/src/Form/PathautoSettingsForm.php index c17ac99..1583c43 100644 --- a/src/Form/PathautoSettingsForm.php +++ b/src/Form/PathautoSettingsForm.php @@ -20,22 +20,30 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class PathautoSettingsForm extends ConfigFormBase { /** + * Entity Type Manager. + * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** + * Entity Field Manager. + * * @var \Drupal\Core\Entity\EntityFieldManagerInterface */ protected $entityFieldManager; /** + * Alias Type Manager. + * * @var \Drupal\pathauto\AliasTypeManager */ protected $aliasTypeManager; /** - * {@inheritDoc} + * Function to construct. + * + * {@inheritDoc}. */ public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, AliasTypeManager $alias_type_manager) { parent::__construct($config_factory); @@ -45,7 +53,9 @@ class PathautoSettingsForm extends ConfigFormBase { } /** - * {@inheritDoc} + * Function to create. + * + * {@inheritDoc}. */ public static function create(ContainerInterface $container) { return new static( diff --git a/src/Form/PatternEditForm.php b/src/Form/PatternEditForm.php index 8e555e2..31ebf3d 100644 --- a/src/Form/PatternEditForm.php +++ b/src/Form/PatternEditForm.php @@ -16,11 +16,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class PatternEditForm extends EntityForm { /** + * Manager. + * * @var \Drupal\pathauto\AliasTypeManager */ protected $manager; /** + * Entity. + * * @var \Drupal\pathauto\PathautoPatternInterface */ protected $entity; @@ -33,11 +37,15 @@ class PatternEditForm extends EntityForm { protected $entityTypeBundleInfo; /** + * Entity Type Manager. + * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** + * Language Manager. + * * @var \Drupal\Core\Language\LanguageManagerInterface */ protected $languageManager; @@ -58,11 +66,15 @@ class PatternEditForm extends EntityForm { * PatternEditForm constructor. * * @param \Drupal\pathauto\AliasTypeManager $manager + * Manager. * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info + * Entity type bundle info. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * Entity type manager. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * Language manager. */ - function __construct(AliasTypeManager $manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager) { + public function __construct(AliasTypeManager $manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager) { $this->manager = $manager; $this->entityTypeBundleInfo = $entity_type_bundle_info; $this->entityTypeManager = $entity_type_manager; @@ -70,7 +82,9 @@ class PatternEditForm extends EntityForm { } /** - * {@inheritDoc} + * Build Form. + * + * {@inheritDoc}. */ public function buildForm(array $form, FormStateInterface $form_state) { @@ -100,7 +114,7 @@ class PatternEditForm extends EntityForm { '#suffix' => '', ]; - // if there is no type yet, stop here. + // If there is no type yet, stop here. if ($this->entity->getType()) { $alias_type = $this->entity->getAliasType(); @@ -129,7 +143,7 @@ class PatternEditForm extends EntityForm { $default_bundles = []; $default_languages = []; - foreach ($this->entity->getSelectionConditions() as $condition_id => $condition) { + foreach ($this->entity->getSelectionConditions() as $condition) { if (in_array($condition->getPluginId(), ['entity_bundle:' . $entity_type->id(), 'node_type'])) { $default_bundles = $condition->getConfiguration()['bundles']; } @@ -198,7 +212,9 @@ class PatternEditForm extends EntityForm { } /** - * {@inheritDoc} + * Build Entity. + * + * {@inheritDoc}. */ public function buildEntity(array $form, FormStateInterface $form_state) { /** @var \Drupal\pathauto\PathautoPatternInterface $entity */ @@ -211,7 +227,9 @@ class PatternEditForm extends EntityForm { $entity_type = $alias_type->getDerivativeId(); // First, remove bundle and language conditions. foreach ($entity->getSelectionConditions() as $condition_id => $condition) { - if (in_array($condition->getPluginId(), ['entity_bundle:' . $entity_type, 'node_type', 'language'])) { + if (in_array($condition->getPluginId(), [ + 'entity_bundle:' . $entity_type, 'node_type', 'language', + ])) { $entity->removeSelectionCondition($condition_id); } } @@ -226,7 +244,7 @@ class PatternEditForm extends EntityForm { 'negate' => FALSE, 'context_mapping' => [ $entity_type => $entity_type, - ] + ], ] ); } @@ -241,7 +259,7 @@ class PatternEditForm extends EntityForm { 'negate' => FALSE, 'context_mapping' => [ 'language' => $language_mapping, - ] + ], ] ); $entity->addRelationship($language_mapping, t('Language')); @@ -255,7 +273,9 @@ class PatternEditForm extends EntityForm { } /** - * {@inheritDoc} + * Function to save. + * + * {@inheritDoc}. */ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); diff --git a/src/PathautoGenerator.php b/src/PathautoGenerator.php index 2c110e8..de307b6 100644 --- a/src/PathautoGenerator.php +++ b/src/PathautoGenerator.php @@ -86,11 +86,15 @@ class PathautoGenerator implements PathautoGeneratorInterface { protected $messenger; /** + * Token Entity Mapper. + * * @var \Drupal\token\TokenEntityMapperInterface */ protected $tokenEntityMapper; /** + * Entity Type Manager. + * * @var Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; @@ -115,7 +119,7 @@ class PathautoGenerator implements PathautoGeneratorInterface { * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. * @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager + * The entity type manager. */ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, Token $token, AliasCleanerInterface $alias_cleaner, AliasStorageHelperInterface $alias_storage_helper, AliasUniquifierInterface $alias_uniquifier, MessengerInterface $messenger, TranslationInterface $string_translation, TokenEntityMapperInterface $token_entity_mappper, EntityTypeManagerInterface $entity_type_manager) { $this->configFactory = $config_factory; @@ -239,7 +243,7 @@ class PathautoGenerator implements PathautoGeneratorInterface { } /** - * Loads pathauto patterns for a given entity type ID + * Loads pathauto patterns for a given entity type ID. * * @param string $entity_type_id * An entity type ID. diff --git a/src/PathautoGeneratorInterface.php b/src/PathautoGeneratorInterface.php index 5880adb..faed077 100644 --- a/src/PathautoGeneratorInterface.php +++ b/src/PathautoGeneratorInterface.php @@ -10,17 +10,17 @@ use Drupal\Core\Entity\EntityInterface; interface PathautoGeneratorInterface { /** - * "Do nothing. Leave the old alias intact." + * Do nothing. Leave the old alias intact. */ const UPDATE_ACTION_NO_NEW = 0; /** - * "Create a new alias. Leave the existing alias functioning." + * Create a new alias. Leave the existing alias functioning. */ const UPDATE_ACTION_LEAVE = 1; /** - * "Create a new alias. Delete the old alias." + * Create a new alias. Delete the old alias. */ const UPDATE_ACTION_DELETE = 2; @@ -49,7 +49,9 @@ interface PathautoGeneratorInterface { * * @param \Drupal\Core\Entity\EntityInterface $entity * An entity. + * * @return \Drupal\pathauto\PathautoPatternInterface|null + * Return Pattern. */ public function getPatternByEntity(EntityInterface $entity); @@ -77,8 +79,8 @@ interface PathautoGeneratorInterface { * @param string $op * The operation performed (insert, update) * @param array $options - * - force: will force updating the path - * - language: the language for which to create the alias + * - Force: will force updating the path + * - language: the language for which to create the alias. * * @return array|null * - An array with alias data in case the alias has been created or updated. diff --git a/src/PathautoPatternInterface.php b/src/PathautoPatternInterface.php index 9782f2e..e884ed4 100644 --- a/src/PathautoPatternInterface.php +++ b/src/PathautoPatternInterface.php @@ -13,6 +13,7 @@ interface PathautoPatternInterface extends ConfigEntityInterface { * Get the tokenized pattern used during alias generation. * * @return string + * Return string with pattern. */ public function getPattern(); @@ -20,8 +21,10 @@ interface PathautoPatternInterface extends ConfigEntityInterface { * Set the tokenized pattern to use during alias generation. * * @param string $pattern + * String with pattern. * * @return $this + * Return pattern. */ public function setPattern($pattern); @@ -29,11 +32,15 @@ interface PathautoPatternInterface extends ConfigEntityInterface { * Gets the type of this pattern. * * @return string + * Return string with Type. */ public function getType(); /** + * Get Alias Type. + * * @return \Drupal\pathauto\AliasTypeInterface + * Return Alias Type. */ public function getAliasType(); @@ -41,6 +48,7 @@ interface PathautoPatternInterface extends ConfigEntityInterface { * Gets the weight of this pattern (compared to other patterns of this type). * * @return int + * Return weight. */ public function getWeight(); @@ -58,6 +66,7 @@ interface PathautoPatternInterface extends ConfigEntityInterface { * Returns the contexts of this pattern. * * @return \Drupal\Core\Plugin\Context\ContextInterface[] + * Return contexts. */ public function getContexts(); @@ -126,6 +135,7 @@ interface PathautoPatternInterface extends ConfigEntityInterface { * Gets the selection condition collection. * * @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionPluginCollection + * Return Selection Conditions. */ public function getSelectionConditions(); @@ -147,6 +157,7 @@ interface PathautoPatternInterface extends ConfigEntityInterface { * The id of the condition. * * @return \Drupal\Core\Condition\ConditionInterface + * Return Selection Condition. */ public function getSelectionCondition($condition_id); @@ -171,10 +182,11 @@ interface PathautoPatternInterface extends ConfigEntityInterface { /** * Determines if this pattern can apply a given object. * - * @param $object + * @param object $object * The object used to determine if this plugin can apply. * * @return bool + * Return flag with type boolean. */ public function applies($object); diff --git a/src/PathautoState.php b/src/PathautoState.php index 6415252..805567b 100644 --- a/src/PathautoState.php +++ b/src/PathautoState.php @@ -1,4 +1,5 @@ parent->getEntity()->getEntityTypeId(); diff --git a/src/PathautoWidget.php b/src/PathautoWidget.php index 8518d1f..21dd63c 100644 --- a/src/PathautoWidget.php +++ b/src/PathautoWidget.php @@ -24,18 +24,19 @@ class PathautoWidget extends PathWidget { // @todo Impossible to do this in widget, use another solution /* $form['path'] += array( - '#type' => 'fieldset', - '#title' => $this->t('URL path settings'), - '#collapsible' => TRUE, - '#collapsed' => empty($form['path']['alias']), - '#group' => 'additional_settings', - '#attributes' => array( - 'class' => array('path-form'), - ), - '#access' => \Drupal::currentUser()->hasPermission('create url aliases') || \Drupal::currentUser()->hasPermission('administer url aliases'), - '#weight' => 30, - '#tree' => TRUE, - '#element_validate' => array('path_form_element_validate'), + '#type' => 'fieldset', + '#title' => $this->t('URL path settings'), + '#collapsible' => TRUE, + '#collapsed' => empty($form['path']['alias']), + '#group' => 'additional_settings', + '#attributes' => array( + 'class' => array('path-form'), + ), + // @codingStandardsIgnoreLine + '#access' => \Drupal::currentUser()->hasPermission('create url aliases') || \Drupal::currentUser()->hasPermission('administer url aliases'), + '#weight' => 30, + '#tree' => TRUE, + '#element_validate' => array('path_form_element_validate'), );*/ $pattern = \Drupal::service('pathauto.generator')->getPatternByEntity($entity); @@ -55,7 +56,6 @@ class PathautoWidget extends PathWidget { // alias checkbox is checked. $element['alias']['#states']['disabled']['input[name="path[' . $delta . '][pathauto]"]'] = array('checked' => TRUE); - // Override path.module's vertical tabs summary. $element['alias']['#attached']['library'] = ['pathauto/widget']; diff --git a/src/Plugin/Deriver/EntityAliasTypeDeriver.php b/src/Plugin/Deriver/EntityAliasTypeDeriver.php index cf7b4a2..8d9bf5a 100644 --- a/src/Plugin/Deriver/EntityAliasTypeDeriver.php +++ b/src/Plugin/Deriver/EntityAliasTypeDeriver.php @@ -21,16 +21,22 @@ class EntityAliasTypeDeriver extends DeriverBase implements ContainerDeriverInte use StringTranslationTrait; /** + * Entity Type Manager. + * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** + * Entity Field Manager. + * * @var \Drupal\Core\Entity\EntityFieldManagerInterface */ protected $entityFieldManager; /** + * Token Entity Mapper. + * * @var \Drupal\token\TokenEntityMapperInterface */ protected $tokenEntityMapper; @@ -44,6 +50,7 @@ class EntityAliasTypeDeriver extends DeriverBase implements ContainerDeriverInte * The entity field manager. * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. + * * @apram \Drupal\Token\TokenEntityMapperInterface $token_entity_mapper * The token entity mapper. */ @@ -84,7 +91,7 @@ class EntityAliasTypeDeriver extends DeriverBase implements ContainerDeriverInte $this->derivatives[$entity_type_id]['types'] = [$this->tokenEntityMapper->getTokenTypeForEntityType($entity_type_id)]; $this->derivatives[$entity_type_id]['provider'] = $entity_type->getProvider(); $this->derivatives[$entity_type_id]['context'] = [ - $entity_type_id => new ContextDefinition("entity:$entity_type_id", $this->t('@label being aliased', ['@label' => $entity_type->getLabel()])) + $entity_type_id => new ContextDefinition("entity:$entity_type_id", $this->t('@label being aliased', ['@label' => $entity_type->getLabel()])), ]; } } diff --git a/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php b/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php index e17e3eb..940dc7b 100644 --- a/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php +++ b/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php @@ -224,5 +224,4 @@ class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInt return $this; } - } diff --git a/src/Tests/PathautoBulkUpdateTest.php b/src/Tests/PathautoBulkUpdateTest.php index b1f7ea1..b1c5fc0 100644 --- a/src/Tests/PathautoBulkUpdateTest.php +++ b/src/Tests/PathautoBulkUpdateTest.php @@ -36,9 +36,11 @@ class PathautoBulkUpdateTest extends WebTestBase { protected $nodes; /** - * {inheritdoc} + * Function to set up. + * + * {inheritdoc}. */ - function setUp() { + public function setUp() { parent::setUp(); // Allow other modules to add additional permissions for the admin user. @@ -54,7 +56,10 @@ class PathautoBulkUpdateTest extends WebTestBase { $this->createPattern('user', '/users/[user:name]'); } - function testBulkUpdate() { + /** + * Function testBulkUpdate(). + */ + public function testBulkUpdate() { // Create some nodes. $this->nodes = array(); for ($i = 1; $i <= 5; $i++) { @@ -94,7 +99,7 @@ class PathautoBulkUpdateTest extends WebTestBase { /** * Tests alias generation for nodes that existed before installing Pathauto. */ - function testBulkUpdateExistingContent() { + public function testBulkUpdateExistingContent() { // Create a node. $node = $this->drupalCreateNode(); diff --git a/src/Tests/PathautoEnablingEntityTypesTest.php b/src/Tests/PathautoEnablingEntityTypesTest.php index c8cc1ff..1da9337 100644 --- a/src/Tests/PathautoEnablingEntityTypesTest.php +++ b/src/Tests/PathautoEnablingEntityTypesTest.php @@ -30,9 +30,11 @@ class PathautoEnablingEntityTypesTest extends WebTestBase { protected $adminUser; /** - * {inheritdoc} + * Function to set up. + * + * {inheritdoc}. */ - function setUp() { + public function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'article')); @@ -50,11 +52,13 @@ class PathautoEnablingEntityTypesTest extends WebTestBase { } /** + * Function testEnablingEntityTypes(). + * * A suite of tests to verify if the feature to enable and disable the * ability to define alias patterns for a given entity type works. Test with * the comment module, as it is not enabled by default. */ - function testEnablingEntityTypes() { + public function testEnablingEntityTypes() { // Verify that the comment entity type is not available when trying to add // a new pattern, nor "broken". $this->drupalGet('/admin/config/search/path/patterns/add'); diff --git a/src/Tests/PathautoLocaleTest.php b/src/Tests/PathautoLocaleTest.php index dd271ef..9bec12d 100644 --- a/src/Tests/PathautoLocaleTest.php +++ b/src/Tests/PathautoLocaleTest.php @@ -22,7 +22,12 @@ class PathautoLocaleTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'pathauto', 'locale', 'content_translation'); + public static $modules = array( + 'node', + 'pathauto', + 'locale', + 'content_translation', + ); /** * {@inheritdoc} @@ -35,10 +40,12 @@ class PathautoLocaleTest extends WebTestBase { } /** + * Function testLanguageAliases(). + * * Test that when an English node is updated, its old English alias is * updated and its newer French alias is left intact. */ - function testLanguageAliases() { + public function testLanguageAliases() { $this->createPattern('node', '/content/[node:title]'); @@ -51,7 +58,8 @@ class PathautoLocaleTest extends WebTestBase { 'path' => array(array( 'alias' => '/english-node', 'pathauto' => FALSE, - )), + ), + ), ); $node = $this->drupalCreateNode($node); $english_alias = \Drupal::service('path.alias_storage')->load(array('alias' => '/english-node', 'langcode' => 'en')); @@ -86,7 +94,7 @@ class PathautoLocaleTest extends WebTestBase { /** * Test that patterns work on multilingual content. */ - function testLanguagePatterns() { + public function testLanguagePatterns() { $this->drupalLogin($this->rootUser); // Add French language. @@ -173,7 +181,11 @@ class PathautoLocaleTest extends WebTestBase { $pattern->save(); // Create a node with language Not Applicable. - $node = $this->createNode(['type' => 'article', 'title' => 'Test node', 'langcode' => LanguageInterface::LANGCODE_NOT_APPLICABLE]); + $node = $this->createNode([ + 'type' => 'article', + 'title' => 'Test node', + 'langcode' => LanguageInterface::LANGCODE_NOT_APPLICABLE, + ]); // Check that the generated alias has language Not Specified. $alias = \Drupal::service('pathauto.alias_storage_helper')->loadBySource('/node/' . $node->id()); diff --git a/src/Tests/PathautoMassDeleteTest.php b/src/Tests/PathautoMassDeleteTest.php index e528ba6..88d8f0f 100644 --- a/src/Tests/PathautoMassDeleteTest.php +++ b/src/Tests/PathautoMassDeleteTest.php @@ -48,11 +48,12 @@ class PathautoMassDeleteTest extends WebTestBase { */ protected $terms; - /** - * {inheritdoc} + * Function to set up. + * + * {inheritdoc}. */ - function setUp() { + public function setUp() { parent::setUp(); $permissions = array( @@ -71,7 +72,7 @@ class PathautoMassDeleteTest extends WebTestBase { /** * Tests the deletion of all the aliases. */ - function testDeleteAll() { + public function testDeleteAll() { // 1. Test that deleting all the aliases, of any type, works. $this->generateAliases(); $edit = array( @@ -87,7 +88,11 @@ class PathautoMassDeleteTest extends WebTestBase { // 2. Test deleting only specific (entity type) aliases. $manager = $this->container->get('plugin.manager.alias_type'); - $pathauto_plugins = array('canonical_entities:node' => 'nodes', 'canonical_entities:taxonomy_term' => 'terms', 'canonical_entities:user' => 'accounts'); + $pathauto_plugins = array( + 'canonical_entities:node' => 'nodes', + 'canonical_entities:taxonomy_term' => 'terms', + 'canonical_entities:user' => 'accounts', + ); foreach ($pathauto_plugins as $pathauto_plugin => $attribute) { $this->generateAliases(); $edit = array( @@ -117,7 +122,7 @@ class PathautoMassDeleteTest extends WebTestBase { /** * Helper function to generate aliases. */ - function generateAliases() { + public function generateAliases() { // We generate a bunch of aliases for nodes, users and taxonomy terms. If // the entities are already created we just update them, otherwise we create // them. @@ -140,7 +145,7 @@ class PathautoMassDeleteTest extends WebTestBase { } } else { - foreach ($this->accounts as $id => $account) { + foreach ($this->accounts as $account) { $account->save(); } } diff --git a/src/Tests/PathautoNodeWebTest.php b/src/Tests/PathautoNodeWebTest.php index 482bfce..87c2a5b 100644 --- a/src/Tests/PathautoNodeWebTest.php +++ b/src/Tests/PathautoNodeWebTest.php @@ -1,6 +1,7 @@ drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); @@ -56,8 +65,9 @@ class PathautoNodeWebTest extends WebTestBase { /** * Tests editing nodes with different settings. */ - function testNodeEditing() { - // Ensure that the Pathauto checkbox is checked by default on the node add form. + public function testNodeEditing() { + // Ensure that the Pathauto checkbox is checked by default on the node add + // form. $this->drupalGet('node/add/page'); $this->assertFieldChecked('edit-path-0-pathauto'); @@ -130,7 +140,7 @@ class PathautoNodeWebTest extends WebTestBase { $edit = array(); $edit['title'] = 'My test article'; $this->drupalCreateNode($edit); - //$this->drupalPostForm(NULL, $edit, t('Save and keep published')); + // $this->drupalPostForm(NULL, $edit, t('Save and keep published'));. $node = $this->drupalGetNodeByTitle($edit['title']); // Pathauto checkbox should still not exist. @@ -143,7 +153,7 @@ class PathautoNodeWebTest extends WebTestBase { /** * Test node operations. */ - function testNodeOperations() { + public function testNodeOperations() { $node1 = $this->drupalCreateNode(array('title' => 'node1')); $node2 = $this->drupalCreateNode(array('title' => 'node2')); @@ -163,6 +173,8 @@ class PathautoNodeWebTest extends WebTestBase { } /** + * Function testNodeState(). + * * @todo Merge this with existing node test methods? */ public function testNodeState() { @@ -188,7 +200,8 @@ class PathautoNodeWebTest extends WebTestBase { $node = Node::load($node->id()); $this->assertIdentical($node->path->pathauto, PathautoState::SKIP); - // Ensure that the manual path alias was saved and an automatic alias was not generated. + // Ensure that the manual path alias was saved and an automatic alias was + // not generated. $this->assertEntityAlias($node, '/test-alias'); $this->assertNoEntityAliasExists($node, '/content/node-version-one'); @@ -205,7 +218,8 @@ class PathautoNodeWebTest extends WebTestBase { $this->assertNoEntityAliasExists($node, '/content/node-version-one'); $this->assertNoEntityAliasExists($node, '/content/node-version-two'); - // Load the edit node page and check that the Pathauto checkbox is unchecked. + // Load the edit node page and check that the Pathauto checkbox is + // unchecked. $this->drupalLogin($nodeAliasUser); $this->drupalGet('node/' . $node->id() . '/edit'); $this->assertNoFieldChecked('edit-path-0-pathauto'); @@ -245,7 +259,6 @@ class PathautoNodeWebTest extends WebTestBase { $this->assertNull(\Drupal::keyValue('pathauto_state.node')->get($node->id()), 'Pathauto state was deleted'); } - /** * Tests that nodes without a Pathauto pattern can set custom aliases. */ @@ -271,7 +284,11 @@ class PathautoNodeWebTest extends WebTestBase { $this->assertResponse(200, 'A node without a pattern can have a custom alias.'); // Now create a node through the API. - $node = Node::create(['type' => 'article', 'title' => 'Sample article API', 'path' => ['alias' => '/sample-article-api']]); + $node = Node::create([ + 'type' => 'article', + 'title' => 'Sample article API', + 'path' => ['alias' => '/sample-article-api'], + ]); $node->save(); // Test the alias. diff --git a/src/Tests/PathautoSettingsFormWebTest.php b/src/Tests/PathautoSettingsFormWebTest.php index 9a4a690..acaa62c 100644 --- a/src/Tests/PathautoSettingsFormWebTest.php +++ b/src/Tests/PathautoSettingsFormWebTest.php @@ -85,9 +85,11 @@ class PathautoSettingsFormWebTest extends WebTestBase { ); /** - * {inheritdoc} + * Function to set up. + * + * {inheritdoc}. */ - function setUp() { + public function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'article')); @@ -108,7 +110,7 @@ class PathautoSettingsFormWebTest extends WebTestBase { /** * Test if the default values are shown correctly in the form. */ - function testDefaultFormValues() { + public function testDefaultFormValues() { $this->drupalGet('/admin/config/search/path/settings'); $this->assertNoFieldChecked('edit-verbose'); $this->assertField('edit-separator', $this->defaultFormValues['separator']); @@ -124,7 +126,7 @@ class PathautoSettingsFormWebTest extends WebTestBase { /** * Test the verbose option. */ - function testVerboseOption() { + public function testVerboseOption() { $edit = array('verbose' => '1'); $this->drupalPostForm('/admin/config/search/path/settings', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.')); @@ -145,7 +147,7 @@ class PathautoSettingsFormWebTest extends WebTestBase { /** * Tests generating aliases with different settings. */ - function testSettingsForm() { + public function testSettingsForm() { // Ensure the separator settings apply correctly. $this->checkAlias('My awesome content', '/content/my.awesome.content', array('separator' => '.')); @@ -171,7 +173,7 @@ class PathautoSettingsFormWebTest extends WebTestBase { /** * Test the punctuation setting form items. */ - function testPunctuationSettings() { + public function testPunctuationSettings() { // Test the replacement of punctuations. $settings = []; foreach ($this->defaultPunctuations as $key => $punctuation) { diff --git a/src/Tests/PathautoTaxonomyWebTest.php b/src/Tests/PathautoTaxonomyWebTest.php index e1a7e88..f61d43e 100644 --- a/src/Tests/PathautoTaxonomyWebTest.php +++ b/src/Tests/PathautoTaxonomyWebTest.php @@ -1,6 +1,7 @@ createPattern('taxonomy_term', '/[term:vocabulary]/[term:name]'); } - /** * Basic functional testing of Pathauto with taxonomy terms. */ - function testTermEditing() { + public function testTermEditing() { $this->drupalGet('admin/structure'); $this->drupalGet('admin/structure/taxonomy'); diff --git a/src/Tests/PathautoTestHelperTrait.php b/src/Tests/PathautoTestHelperTrait.php index b8b8075..5fcdfc8 100644 --- a/src/Tests/PathautoTestHelperTrait.php +++ b/src/Tests/PathautoTestHelperTrait.php @@ -49,7 +49,7 @@ trait PathautoTestHelperTrait { * @param string $entity_type * The entity type ID. * @param string $bundle - * The bundle + * The bundle. */ protected function addBundleCondition(PathautoPatternInterface $pattern, $entity_type, $bundle) { $plugin_id = $entity_type == 'node' ? 'node_type' : 'entity_bundle:' . $entity_type; @@ -63,23 +63,42 @@ trait PathautoTestHelperTrait { 'negate' => FALSE, 'context_mapping' => [ $entity_type => $entity_type, - ] + ], ] ); } + /** + * Function to assert token. + */ public function assertToken($type, $object, $token, $expected) { $bubbleable_metadata = new BubbleableMetadata(); $tokens = \Drupal::token()->generate($type, array($token => $token), array($type => $object), [], $bubbleable_metadata); $tokens += array($token => ''); - $this->assertIdentical($tokens[$token], $expected, t("Token value for [@type:@token] was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $tokens[$token], '@expected' => $expected))); + $this->assertIdentical($tokens[$token], $expected, t("Token value for [@type:@token] was '@actual', expected value '@expected'.", array( + '@type' => $type, + '@token' => $token, + '@actual' => $tokens[$token], + '@expected' => $expected, + ))); } + /** + * Function to save alias. + */ public function saveAlias($source, $alias, $langcode = Language::LANGCODE_NOT_SPECIFIED) { - \Drupal::service('path.alias_storage')->delete(array('source' => $source, 'language', 'langcode' => $langcode)); + \Drupal::service('path.alias_storage')->delete(array( + 'source' => $source, + // @codingStandardsIgnoreLine + 'language', + 'langcode' => $langcode, + )); return \Drupal::service('path.alias_storage')->save($source, $alias, $langcode); } + /** + * Function to save entity alias. + */ public function saveEntityAlias(EntityInterface $entity, $alias, $langcode = NULL) { // By default, use the entity language. if (!$langcode) { @@ -88,6 +107,9 @@ trait PathautoTestHelperTrait { return $this->saveAlias('/' . $entity->toUrl()->getInternalPath(), $alias, $langcode); } + /** + * Function assertEntityAlias(). + */ public function assertEntityAlias(EntityInterface $entity, $expected_alias, $langcode = NULL) { // By default, use the entity language. if (!$langcode) { @@ -96,10 +118,16 @@ trait PathautoTestHelperTrait { $this->assertAlias('/' . $entity->toUrl()->getInternalPath(), $expected_alias, $langcode); } + /** + * Function assertEntityAliasExists(). + */ public function assertEntityAliasExists(EntityInterface $entity) { return $this->assertAliasExists(array('source' => '/' . $entity->toUrl()->getInternalPath())); } + /** + * Function assertNoEntityAlias(). + */ public function assertNoEntityAlias(EntityInterface $entity, $langcode = NULL) { // By default, use the entity language. if (!$langcode) { @@ -108,6 +136,9 @@ trait PathautoTestHelperTrait { $this->assertEntityAlias($entity, '/' . $entity->toUrl()->getInternalPath(), $langcode); } + /** + * Function assertNoEntityAliasExists(). + */ public function assertNoEntityAliasExists(EntityInterface $entity, $alias = NULL) { $path = array('source' => '/' . $entity->toUrl()->getInternalPath()); if (!empty($alias)) { @@ -116,31 +147,48 @@ trait PathautoTestHelperTrait { $this->assertNoAliasExists($path); } + /** + * Function assertAlias(). + */ public function assertAlias($source, $expected_alias, $langcode = Language::LANGCODE_NOT_SPECIFIED) { \Drupal::service('path.alias_manager')->cacheClear($source); $this->assertEqual($expected_alias, \Drupal::service('path.alias_manager')->getAliasByPath($source, $langcode), t("Alias for %source with language '@language' is correct.", array('%source' => $source, '@language' => $langcode))); } + /** + * Function assertAliasExists(). + */ public function assertAliasExists($conditions) { $path = \Drupal::service('path.alias_storage')->load($conditions); $this->assertTrue($path, t('Alias with conditions @conditions found.', array('@conditions' => var_export($conditions, TRUE)))); return $path; } + /** + * Function assertNoAliasExists(). + */ public function assertNoAliasExists($conditions) { $alias = \Drupal::service('path.alias_storage')->load($conditions); $this->assertFalse($alias, t('Alias with conditions @conditions not found.', array('@conditions' => var_export($conditions, TRUE)))); } + /** + * Function to Delete all aliases. + */ public function deleteAllAliases() { db_delete('url_alias')->execute(); \Drupal::service('path.alias_manager')->cacheClear(); } /** + * Add Vocabulary. + * * @param array $values + * Array with values. + * * @return \Drupal\taxonomy\VocabularyInterface + * Return vocabulary object. */ public function addVocabulary(array $values = array()) { $name = Unicode::strtolower($this->randomMachineName(5)); @@ -154,6 +202,9 @@ trait PathautoTestHelperTrait { return $vocabulary; } + /** + * Add Term. + */ public function addTerm(VocabularyInterface $vocabulary, array $values = array()) { $values += array( 'name' => Unicode::strtolower($this->randomMachineName(5)), @@ -165,8 +216,14 @@ trait PathautoTestHelperTrait { return $term; } + /** + * Function assertEntityPattern(). + * + * @codingStandardsIgnoreStart + */ public function assertEntityPattern($entity_type, $bundle, $langcode = Language::LANGCODE_NOT_SPECIFIED, $expected) { - + + // @codingStandardsIgnoreEnd $values = [ 'langcode' => $langcode, \Drupal::entityTypeManager()->getDefinition($entity_type)->getKey('bundle') => $bundle, @@ -177,6 +234,9 @@ trait PathautoTestHelperTrait { $this->assertIdentical($expected, $pattern->getPattern()); } + /** + * Function to Get Term. + */ public function drupalGetTermByName($name, $reset = FALSE) { if ($reset) { // @todo - implement cache reset. diff --git a/src/Tests/PathautoUiTest.php b/src/Tests/PathautoUiTest.php index 73c8b04..fc73177 100644 --- a/src/Tests/PathautoUiTest.php +++ b/src/Tests/PathautoUiTest.php @@ -29,9 +29,11 @@ class PathautoUiTest extends WebTestBase { protected $adminUser; /** - * {inheritdoc} + * Function to set up. + * + * {inheritdoc}. */ - function setUp() { + public function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); @@ -50,27 +52,49 @@ class PathautoUiTest extends WebTestBase { $this->drupalLogin($this->adminUser); } - function testSettingsValidation() { + /** + * TestSettingsValidation. + */ + public function testSettingsValidation() { $edit = array(); $edit['max_length'] = 'abc'; $edit['max_component_length'] = 'abc'; $this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration'); - /*$this->assertText('The field Maximum alias length is not a valid number.'); - $this->assertText('The field Maximum component length is not a valid number.');*/ + /* + * @codingStandardsIgnoreStart + * @code + * $this->assertText('The field Maximum alias length is not a valid number.'); + * $this->assertText('The field Maximum component length is not a valid number.'); + * @endcode + * @codingStandardsIgnoreEnd + */ $this->assertNoText('The configuration options have been saved.'); $edit['max_length'] = '0'; $edit['max_component_length'] = '0'; $this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration'); - /*$this->assertText('The field Maximum alias length cannot be less than 1.'); - $this->assertText('The field Maximum component length cannot be less than 1.');*/ + /* + * @codingStandardsIgnoreStart + * @code + * $this->assertText('The field Maximum alias length cannot be less than 1.'); + * $this->assertText('The field Maximum component length cannot be less than 1.'); + * @endcode + * @codingStandardsIgnoreEnd + */ $this->assertNoText('The configuration options have been saved.'); $edit['max_length'] = '999'; $edit['max_component_length'] = '999'; $this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration'); - /*$this->assertText('The field Maximum alias length cannot be greater than 255.'); - $this->assertText('The field Maximum component length cannot be greater than 255.');*/ + /* + * @codingStandardsIgnoreStart + * @code + * $this->assertText('The field Maximum alias length cannot be greater than 255.'); + * $this->assertText('The field Maximum component length cannot be greater than 255.'); + * @endcode + * @codingStandardsIgnoreEnd + */ + $this->assertNoText('The configuration options have been saved.'); $edit['max_length'] = '50'; @@ -79,7 +103,10 @@ class PathautoUiTest extends WebTestBase { $this->assertText('The configuration options have been saved.'); } - function testPatternsWorkflow() { + /** + * Function testPatternsWorkflow(). + */ + public function testPatternsWorkflow() { // Try to save an empty pattern, should not be allowed. $this->drupalGet('admin/config/search/path/patterns/add'); $edit = array( diff --git a/src/Tests/PathautoUserWebTest.php b/src/Tests/PathautoUserWebTest.php index 54832df..94a9a3b 100644 --- a/src/Tests/PathautoUserWebTest.php +++ b/src/Tests/PathautoUserWebTest.php @@ -1,6 +1,7 @@ createPattern('user', '/users/[user:name]'); } - /** * Basic functional testing of Pathauto with users. */ - function testUserEditing() { + public function testUserEditing() { // There should be no Pathauto checkbox on user forms. $this->drupalGet('user/' . $this->adminUser->id() . '/edit'); $this->assertNoFieldById('path[0][pathauto]'); @@ -60,7 +62,7 @@ class PathautoUserWebTest extends WebTestBase { /** * Test user operations. */ - function testUserOperations() { + public function testUserOperations() { $account = $this->drupalCreateUser(); // Delete all current URL aliases. @@ -71,7 +73,6 @@ class PathautoUserWebTest extends WebTestBase { $view->initDisplay(); $view->preview('page_1'); - foreach ($view->result as $key => $row) { if ($view->field['name']->getValue($row) == $account->getUsername()) { break; diff --git a/tests/modules/pathauto_views_test/pathauto_views_test.info.yml b/tests/modules/pathauto_views_test/pathauto_views_test.info.yml index 3392573..728f7e2 100644 --- a/tests/modules/pathauto_views_test/pathauto_views_test.info.yml +++ b/tests/modules/pathauto_views_test/pathauto_views_test.info.yml @@ -2,7 +2,6 @@ name: 'Views Test Config' type: module description: 'Provides default views for tests.' package: Testing -version: VERSION core: 8.x dependencies: - views diff --git a/tests/src/Kernel/PathautoKernelTest.php b/tests/src/Kernel/PathautoKernelTest.php index c3438b5..50a36cd 100644 --- a/tests/src/Kernel/PathautoKernelTest.php +++ b/tests/src/Kernel/PathautoKernelTest.php @@ -28,20 +28,40 @@ class PathautoKernelTest extends KernelTestBase { use PathautoTestHelperTrait; - public static $modules = array('system', 'field', 'text', 'user', 'node', 'path', 'pathauto', 'taxonomy', 'token', 'filter', 'ctools', 'language'); + public static $modules = array( + 'system', + 'field', + 'text', + 'user', + 'node', + 'path', + 'pathauto', + 'taxonomy', + 'token', + 'filter', + 'ctools', + 'language', + ); protected $currentUser; /** + * Node Pattern. + * * @var \Drupal\pathauto\PathautoPatternInterface */ protected $nodePattern; /** + * User Pattern. + * * @var \Drupal\pathauto\PathautoPatternInterface */ protected $userPattern; + /** + * Function to set up. + */ public function setUp() { parent::setup(); @@ -95,7 +115,7 @@ class PathautoKernelTest extends KernelTestBase { 'negate' => FALSE, 'context_mapping' => [ 'language' => 'node:langcode:language', - ] + ], ] ); @@ -264,7 +284,10 @@ class PathautoKernelTest extends KernelTestBase { } /** - * Test the different update actions in \Drupal::service('pathauto.generator')->createEntityAlias(). + * Test Update Actions. + * + * Test the different update actions in + * \Drupal::service('pathauto.generator')->createEntityAlias(). */ public function testUpdateActions() { $config = $this->config('pathauto.settings'); @@ -285,7 +308,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 +346,10 @@ 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 no Tokens no Alias. + * + * 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']); @@ -341,7 +366,10 @@ class PathautoKernelTest extends KernelTestBase { } /** - * Test the handling of path vs non-path tokens in pathauto_clean_token_values(). + * Test Path Tokens. + * + * Test the handling of path vs non-path tokens in + * pathauto_clean_token_values(). */ public function testPathTokens() { $this->createPattern('taxonomy_term', '/[term:parent:url:path]/[term:name]'); @@ -362,16 +390,19 @@ class PathautoKernelTest extends KernelTestBase { /** * Test using fields for path structures. */ - function testParentChildPathTokens() { + public 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()); - $field_storage = FieldStorageConfig::create(['entity_type' => 'taxonomy_term', 'field_name' => $fieldname, 'type' => 'string']); + $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']); $field->save(); @@ -385,11 +416,20 @@ class PathautoKernelTest extends KernelTestBase { $this->createPattern('taxonomy_term', '/[term:parents:join-path]/[term:' . $fieldname . ']'); // Start by creating a parent term. - $parent = Term::create(['vid' => 'tags', $fieldname => $this->randomMachineName(), 'name' => $this->randomMachineName()]); + $parent = Term::create([ + 'vid' => 'tags', + $fieldname => $this->randomMachineName(), + 'name' => $this->randomMachineName(), + ]); $parent->save(); // Create the child term. - $child = Term::create(['vid' => 'tags', $fieldname => $this->randomMachineName(), 'parent' => $parent, 'name' => $this->randomMachineName()]); + $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)); @@ -402,8 +442,6 @@ class PathautoKernelTest extends KernelTestBase { * Tests aliases on taxonomy terms. */ public function testTaxonomyPattern() { - // Create a vocabulary and test that it's pattern variable works. - $vocab = $this->addVocabulary(array('vid' => 'name')); $this->createPattern('taxonomy_term', 'base'); $pattern = $this->createPattern('taxonomy_term', 'bundle', -1); $this->addBundleCondition($pattern, 'taxonomy_term', 'name'); @@ -411,7 +449,10 @@ class PathautoKernelTest extends KernelTestBase { $this->assertEntityPattern('taxonomy_term', 'name', Language::LANGCODE_NOT_SPECIFIED, 'bundle'); } - function testNoExistingPathAliases() { + /** + * Function test existing Path Aliases. + */ + public function testNoExistingPathAliases() { $this->config('pathauto.settings') ->set('punctuation.period', PathautoGeneratorInterface::PUNCTUATION_DO_NOTHING) ->save(); @@ -444,7 +485,7 @@ class PathautoKernelTest extends KernelTestBase { /** * Test programmatic entity creation for aliases. */ - function testProgrammaticEntityCreation() { + public function testProgrammaticEntityCreation() { $this->createPattern('taxonomy_term', '/[term:vocabulary]/[term:name]'); $node = $this->drupalCreateNode(array('title' => 'Test node', 'path' => array('pathauto' => TRUE))); $this->assertEntityAlias($node, '/content/test-node'); @@ -466,7 +507,7 @@ class PathautoKernelTest extends KernelTestBase { /** * Tests word safe alias truncating. */ - function testPathAliasUniquifyWordsafe() { + public function testPathAliasUniquifyWordsafe() { $this->config('pathauto.settings') ->set('max_length', 26) ->save(); @@ -476,7 +517,7 @@ class PathautoKernelTest extends KernelTestBase { // Check that alias uniquifying is truncating with $wordsafe param set to // TRUE. - // If it doesn't path alias result would be content/thequick-brownf-0 + // If it doesn't path alias result would be content/thequick-brownf-0. $this->assertEntityAlias($node_1, '/content/thequick-brownfox'); $this->assertEntityAlias($node_2, '/content/thequick-0'); } @@ -484,7 +525,7 @@ class PathautoKernelTest extends KernelTestBase { /** * Test if aliases are (not) generated with enabled/disabled patterns. */ - function testPatternStatus() { + public function testPatternStatus() { // Create a node to get an alias for. $title = 'Pattern enabled'; $alias = '/content/pattern-enabled'; diff --git a/tests/src/Kernel/PathautoTokenTest.php b/tests/src/Kernel/PathautoTokenTest.php index 30c5ad1..4bd35b5 100644 --- a/tests/src/Kernel/PathautoTokenTest.php +++ b/tests/src/Kernel/PathautoTokenTest.php @@ -19,6 +19,9 @@ class PathautoTokenTest extends KernelTestBase { */ public static $modules = array('system', 'token', 'pathauto'); + /** + * Function to test Pathauto Tokens. + */ public function testPathautoTokens() { $this->installConfig(array('pathauto')); @@ -34,7 +37,8 @@ class PathautoTokenTest extends KernelTestBase { $data['array'] = $array; $replacements = $this->assertTokens('array', $data, $tokens); - // Ensure that the cleanTokenValues() method does not alter this token value. + // Ensure that the cleanTokenValues() method does not alter this token + // value. /* @var \Drupal\pathauto\AliasCleanerInterface $alias_cleaner */ $alias_cleaner = \Drupal::service('pathauto.alias_cleaner'); $alias_cleaner->cleanTokenValues($replacements, $data, array()); @@ -51,22 +55,35 @@ class PathautoTokenTest extends KernelTestBase { foreach ($tokens as $name => $expected) { $token = $input[$name]; if (!isset($expected)) { - $this->assertTrue(!isset($values[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token))); + $this->assertTrue(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token))); } elseif (!isset($replacements[$token])) { $this->fail(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token))); } elseif (!empty($options['regex'])) { - $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected))); + $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array( + '@type' => $type, + '@token' => $token, + '@actual' => $replacements[$token], + '@expected' => $expected, + ))); } else { - $this->assertIdentical($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected))); + $this->assertIdentical($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array( + '@type' => $type, + '@token' => $token, + '@actual' => $replacements[$token], + '@expected' => $expected, + ))); } } return $replacements; } + /** + * Function to Map token names. + */ public function mapTokenNames($type, array $tokens = array()) { $return = array(); foreach ($tokens as $token) { diff --git a/tests/src/Unit/VerboseMessengerTest.php b/tests/src/Unit/VerboseMessengerTest.php index 9567dd5..7ecff4d 100644 --- a/tests/src/Unit/VerboseMessengerTest.php +++ b/tests/src/Unit/VerboseMessengerTest.php @@ -34,6 +34,7 @@ namespace Drupal\Tests\pathauto\Unit { /** * Tests add messages. + * * @covers ::addMessage */ public function testAddMessage() { @@ -41,19 +42,27 @@ namespace Drupal\Tests\pathauto\Unit { } /** + * Function for test do not add Message while bulkupdate. + * * @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 for set message in Drupal. + */ function drupal_set_message() { } + } }