Commit 72fb4235 authored by zeuty's avatar zeuty Committed by Berdir

Issue #3061563 by zeuty: Convert simpletest to PHPUnit tests

parent 5a436346
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\pathauto\PathautoGeneratorInterface;
use Drupal\pathauto\PathautoState;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Bulk update functionality tests.
*
* @group pathauto
*/
class PathautoBulkUpdateTest extends WebTestBase {
class PathautoBulkUpdateTest extends BrowserTestBase {
use PathautoTestHelperTrait;
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\comment\Tests\CommentTestTrait;
/**
......@@ -10,7 +10,7 @@ use Drupal\comment\Tests\CommentTestTrait;
*
* @group pathauto
*/
class PathautoEnablingEntityTypesTest extends WebTestBase {
class PathautoEnablingEntityTypesTest extends BrowserTestBase {
use PathautoTestHelperTrait;
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\pathauto\PathautoState;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Mass delete functionality tests.
*
* @group pathauto
*/
class PathautoMassDeleteTest extends WebTestBase {
class PathautoMassDeleteTest extends BrowserTestBase {
use PathautoTestHelperTrait;
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\pathauto\Entity\PathautoPattern;
use Drupal\node\Entity\Node;
use Drupal\pathauto\PathautoState;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests pathauto node UI integration.
*
* @group pathauto
*/
class PathautoNodeWebTest extends WebTestBase {
class PathautoNodeWebTest extends BrowserTestBase {
use PathautoTestHelperTrait;
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\pathauto\PathautoGeneratorInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests pathauto settings form.
*
* @group pathauto
*/
class PathautoSettingsFormWebTest extends WebTestBase {
class PathautoSettingsFormWebTest extends BrowserTestBase {
use PathautoTestHelperTrait;
......
<?php
namespace Drupal\pathauto\Tests;
use Drupal\simpletest\WebTestBase;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests pathauto taxonomy UI integration.
*
* @group pathauto
*/
class PathautoTaxonomyWebTest extends WebTestBase {
class PathautoTaxonomyWebTest extends BrowserTestBase {
use PathautoTestHelperTrait;
......@@ -60,7 +61,7 @@ class PathautoTaxonomyWebTest extends WebTestBase {
$automatic_alias = '/tags/testing-term-name';
$this->drupalPostForm('admin/structure/taxonomy/manage/tags/add', ['name[0][value]' => $name], 'Save');
$name = trim($name);
$this->assertText("Created new term $name.");
$this->assertSession()->pageTextContains("Created new term $name.");
$term = $this->drupalGetTermByName($name);
// Look for alias generated in the form.
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
......@@ -73,7 +73,7 @@ trait PathautoTestHelperTrait {
$bubbleable_metadata = new BubbleableMetadata();
$tokens = \Drupal::token()->generate($type, [$token => $token], [$type => $object], [], $bubbleable_metadata);
$tokens += [$token => ''];
$this->assertIdentical($tokens[$token], $expected, t("Token value for [@type:@token] was '@actual', expected value '@expected'.", ['@type' => $type, '@token' => $token, '@actual' => $tokens[$token], '@expected' => $expected]));
$this->assertSame($tokens[$token], $expected, t("Token value for [@type:@token] was '@actual', expected value '@expected'.", ['@type' => $type, '@token' => $token, '@actual' => $tokens[$token], '@expected' => $expected]));
}
public function saveAlias($source, $alias, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
......@@ -119,7 +119,7 @@ trait PathautoTestHelperTrait {
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.",
$this->assertEquals($expected_alias, \Drupal::service('path.alias_manager')->getAliasByPath($source, $langcode), t("Alias for %source with language '@language' is correct.",
['%source' => $source, '@language' => $langcode]));
}
......@@ -176,7 +176,7 @@ trait PathautoTestHelperTrait {
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->create($values);
$pattern = \Drupal::service('pathauto.generator')->getPatternByEntity($entity);
$this->assertIdentical($expected, $pattern->getPattern());
$this->assertSame($expected, $pattern->getPattern());
}
public function drupalGetTermByName($name, $reset = FALSE) {
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\views\Views;
/**
......@@ -10,7 +10,7 @@ use Drupal\views\Views;
*
* @group pathauto
*/
class PathautoUserWebTest extends WebTestBase {
class PathautoUserWebTest extends BrowserTestBase {
use PathautoTestHelperTrait;
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\FunctionalJavascript;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\pathauto\PathautoState;
use Drupal\simpletest\WebTestBase;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\pathauto\Functional\PathautoTestHelperTrait;
/**
* Test pathauto functionality with localization and translation.
*
* @group pathauto
*/
class PathautoLocaleTest extends WebTestBase {
class PathautoLocaleTest extends WebDriverTestBase {
use PathautoTestHelperTrait;
......@@ -113,35 +114,33 @@ class PathautoLocaleTest extends WebTestBase {
// Create a pattern for English articles.
$this->drupalGet('admin/config/search/path/patterns/add');
$edit = [
'type' => 'canonical_entities:node',
];
$this->drupalPostAjaxForm(NULL, $edit, 'type');
$edit += [
'pattern' => '/the-articles/[node:title]',
'label' => 'English articles',
'id' => 'english_articles',
'bundles[article]' => TRUE,
'languages[en]' => TRUE,
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertText('Pattern English articles saved.');
$session = $this->getSession();
$page = $session->getPage();
$page->fillField('type', 'canonical_entities:node');
$this->assertSession()->assertWaitOnAjaxRequest();
$page->fillField('pattern', '/the-articles/[node:title]');
$page->fillField('bundles[article]', TRUE);
$page->fillField('languages[en]', TRUE);
$page->fillField('label', 'English articles');
$this->assertSession()->waitForElementVisible('css', '#edit-label-machine-name-suffix .machine-name-value');
$page->pressButton('Save');
$this->assertSession()->pageTextContains('Pattern English articles saved.');
// Create a pattern for French articles.
$this->drupalGet('admin/config/search/path/patterns/add');
$edit = [
'type' => 'canonical_entities:node',
];
$this->drupalPostAjaxForm(NULL, $edit, 'type');
$edit += [
'pattern' => '/les-articles/[node:title]',
'label' => 'French articles',
'id' => 'french_articles',
'bundles[article]' => TRUE,
'languages[fr]' => TRUE,
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertText('Pattern French articles saved.');
$page->fillField('type', 'canonical_entities:node');
$this->assertSession()->assertWaitOnAjaxRequest();
$page->fillField('pattern', '/les-articles/[node:title]');
$page->fillField('bundles[article]', TRUE);
$page->fillField('languages[fr]', TRUE);
$page->fillField('label', 'French articles');
$this->assertSession()->waitForElementVisible('css', '#edit-label-machine-name-suffix .machine-name-value');
$page->pressButton('Save');
$this->assertSession()->pageTextContains('Pattern French articles saved.');
// Create a node and its translation. Assert aliases.
$edit = [
......@@ -171,7 +170,7 @@ class PathautoLocaleTest extends WebTestBase {
'update[canonical_entities:node]' => TRUE,
];
$this->drupalPostForm('admin/config/search/path/update_bulk', $edit, t('Update'));
$this->assertText(t('Generated 2 URL aliases.'));
$this->assertSession()->pageTextContains(t('Generated 2 URL aliases.'));
$this->assertAlias('/node/' . $english_node->id(), '/the-articles/english-node', 'en');
$this->assertAlias('/node/' . $french_node->id(), '/les-articles/french-node', 'fr');
}
......@@ -196,7 +195,7 @@ class PathautoLocaleTest extends WebTestBase {
// Check that the alias works.
$this->drupalGet('content/test-node');
$this->assertResponse(200);
$this->assertSession()->pageTextContains(t('Test node'));
}
/**
......
<?php
namespace Drupal\pathauto\Tests;
namespace Drupal\Tests\pathauto\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\pathauto\Entity\PathautoPattern;
use Drupal\Tests\pathauto\Functional\PathautoTestHelperTrait;
/**
* Test basic pathauto functionality.
*
* @group pathauto
*/
class PathautoUiTest extends WebTestBase {
class PathautoUiTest extends WebDriverTestBase {
use PathautoTestHelperTrait;
......@@ -52,73 +53,56 @@ class PathautoUiTest extends WebTestBase {
}
function testSettingsValidation() {
$edit = [];
$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.');*/
$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.');*/
$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.');*/
$this->assertNoText('The configuration options have been saved.');
$edit['max_length'] = '50';
$edit['max_component_length'] = '50';
$this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration');
$this->assertText('The configuration options have been saved.');
$this->drupalGet('/admin/config/search/path/settings');
$this->assertSession()->fieldExists('max_length');
$this->assertSession()->elementAttributeContains('css', '#edit-max-length', 'min', '1');
$this->assertSession()->fieldExists('max_component_length');
$this->assertSession()->elementAttributeContains('css', '#edit-max-component-length', 'min', '1');
}
function testPatternsWorkflow() {
// Try to save an empty pattern, should not be allowed.
$this->drupalGet('admin/config/search/path/patterns/add');
$session = $this->getSession();
$session->getPage()->fillField('type', 'canonical_entities:node');
$this->assertSession()->assertWaitOnAjaxRequest();
$edit = [
'type' => 'canonical_entities:node',
];
$this->drupalPostAjaxForm(NULL, $edit, 'type');
$edit += [
'bundles[page]' => TRUE,
'label' => 'Page pattern',
'id' => 'page_pattern',
'pattern' => '[node:title]/[user:name]/[term:name]',
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertText('Path pattern field is required.');
$this->assertNoText('The configuration options have been saved.');
// Try to save an invalid pattern.
$this->assertSession()->waitForElementVisible('css', '[name="id"]');
$edit += [
'pattern' => '[node:title]/[user:name]/[term:name]',
'id' => 'page_pattern',
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertText('Path pattern is using the following invalid tokens: [user:name], [term:name].');
$this->assertNoText('The configuration options have been saved.');
$this->assertSession()->pageTextContains('Path pattern is using the following invalid tokens: [user:name], [term:name].');
$this->assertSession()->pageTextNotContains('The configuration options have been saved.');
// We do not need ID anymore, it is already set in previous step and made a label by browser
unset($edit['id']);
$edit['pattern'] = '#[node:title]';
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertText('The Path pattern is using the following invalid characters: #.');
$this->assertNoText('The configuration options have been saved.');
$this->assertSession()->pageTextContains('The Path pattern is using the following invalid characters: #.');
$this->assertSession()->pageTextNotContains('The configuration options have been saved.');
// Checking whitespace ending of the string.
$edit['pattern'] = '[node:title] ';
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertText('The Path pattern doesn\'t allow the patterns ending with whitespace.');
$this->assertNoText('The configuration options have been saved.');
$this->assertSession()->pageTextContains('The Path pattern doesn\'t allow the patterns ending with whitespace.');
$this->assertSession()->pageTextNotContains('The configuration options have been saved.');
// Fix the pattern, then check that it gets saved successfully.
$edit['pattern'] = '[node:title]';
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertText('Pattern Page pattern saved.');
$this->assertSession()->pageTextContains('Pattern Page pattern saved.');
\Drupal::service('pathauto.generator')->resetCaches();
......@@ -127,11 +111,15 @@ class PathautoUiTest extends WebTestBase {
$alias = '/page-pattern-enabled';
$node = $this->createNode(['title' => $title, 'type' => 'page']);
$this->drupalGet($alias);
$this->assertResponse(200);
$this->assertSession()->pageTextContains($title);
$this->assertEntityAlias($node, $alias);
// Edit workflow, set a new label and weight for the pattern.
$this->drupalPostForm('/admin/config/search/path/patterns', ['entities[page_pattern][weight]' => '4'], t('Save'));
$this->drupalGet('/admin/config/search/path/patterns');
$session->getPage()->pressButton('Show row weights');
$this->drupalPostForm(NULL, ['entities[page_pattern][weight]' => '4'], t('Save'));
$session->getPage()->find('css', '.dropbutton-toggle > button')->press();
$this->clickLink(t('Edit'));
$destination_query = ['query' => ['destination' => Url::fromRoute('entity.pathauto_pattern.collection')->toString()]];
$this->assertUrl('/admin/config/search/path/patterns/page_pattern', $destination_query);
......@@ -142,22 +130,26 @@ class PathautoUiTest extends WebTestBase {
$edit = ['label' => 'Test'];
$this->drupalPostForm('/admin/config/search/path/patterns/page_pattern', $edit, t('Save'));
$this->assertText('Pattern Test saved.');
$this->assertSession()->pageTextContains('Pattern Test saved.');
// Check that the pattern weight did not change.
$this->assertOptionSelected('edit-entities-page-pattern-weight', '4');
$this->drupalGet('/admin/config/search/path/patterns/page_pattern/duplicate');
$session->getPage()->pressButton('Edit');
$edit = array('label' => 'Test Duplicate', 'id' => 'page_pattern_test_duplicate');
$this->drupalPostForm('/admin/config/search/path/patterns/page_pattern/duplicate', $edit, t('Save'));
$this->assertText('Pattern Test Duplicate saved.');
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertSession()->pageTextContains('Pattern Test Duplicate saved.');
PathautoPattern::load('page_pattern_test_duplicate')->delete();
// Disable workflow.
$this->drupalGet('/admin/config/search/path/patterns');
$session->getPage()->find('css', '.dropbutton-toggle > button')->press();
$this->assertNoLink(t('Enable'));
$this->clickLink(t('Disable'));
$this->assertUrl('/admin/config/search/path/patterns/page_pattern/disable', $destination_query);
$this->drupalPostForm(NULL, [], t('Disable'));
$this->assertText('Disabled pattern Test.');
$this->assertSession()->pageTextContains('Disabled pattern Test.');
// Load the pattern from storage and check if its disabled.
$pattern = PathautoPattern::load('page_pattern');
......@@ -176,7 +168,7 @@ class PathautoUiTest extends WebTestBase {
$this->clickLink(t('Enable'));
$this->assertUrl('/admin/config/search/path/patterns/page_pattern/enable', $destination_query);
$this->drupalPostForm(NULL, [], t('Enable'));
$this->assertText('Enabled pattern Test.');
$this->assertSession()->pageTextContains('Enabled pattern Test.');
// Reload pattern from storage and check if its enabled.
$pattern = PathautoPattern::load('page_pattern');
......@@ -184,11 +176,12 @@ class PathautoUiTest extends WebTestBase {
// Delete workflow.
$this->drupalGet('/admin/config/search/path/patterns');
$session->getPage()->find('css', '.dropbutton-toggle > button')->press();
$this->clickLink(t('Delete'));
$this->assertUrl('/admin/config/search/path/patterns/page_pattern/delete', $destination_query);
$this->assertText(t('This action cannot be undone.'));
$this->assertSession()->pageTextContains(t('This action cannot be undone.'));
$this->drupalPostForm(NULL, [], t('Delete'));
$this->assertText('The pathauto pattern Test has been deleted.');
$this->assertSession()->pageTextContains('The pathauto pattern Test has been deleted.');
$this->assertFalse(PathautoPattern::load('page_pattern'));
}
......
......@@ -7,7 +7,7 @@ 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\Tests\pathauto\Functional\PathautoTestHelperTrait;
use Drupal\KernelTests\KernelTestBase;
use Drupal\pathauto_string_id_test\Entity\PathautoStringIdTest;
......
......@@ -11,7 +11,7 @@ use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\pathauto\PathautoGeneratorInterface;
use Drupal\pathauto\PathautoState;
use Drupal\pathauto\Tests\PathautoTestHelperTrait;
use Drupal\Tests\pathauto\Functional\PathautoTestHelperTrait;
use Drupal\KernelTests\KernelTestBase;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -72,7 +72,7 @@ class PathautoKernelTest extends KernelTestBase {
* Test _pathauto_get_schema_alias_maxlength().
*/
public function testGetSchemaAliasMaxLength() {
$this->assertIdentical(\Drupal::service('pathauto.alias_storage_helper')->getAliasSchemaMaxlength(), 255);
$this->assertSame(\Drupal::service('pathauto.alias_storage_helper')->getAliasSchemaMaxlength(), 255);
}
/**
......@@ -153,7 +153,7 @@ class PathautoKernelTest extends KernelTestBase {
$entity = \Drupal::entityTypeManager()->getStorage($test['entity'])->create($test['values']);
$entity->save();
$actual = \Drupal::service('pathauto.generator')->getPatternByEntity($entity);
$this->assertIdentical($actual->getPattern(), $test['expected'], t("Correct pattern returned for @entity_type with @values", [
$this->assertSame($actual->getPattern(), $test['expected'], t("Correct pattern returned for @entity_type with @values", [
'@entity' => $test['entity'],
'@values' => print_r($test['values'], TRUE),
]));
......@@ -215,7 +215,7 @@ class PathautoKernelTest extends KernelTestBase {
foreach ($tests as $input => $expected) {
$output = \Drupal::service('pathauto.alias_cleaner')->cleanString($input);
$this->assertEqual($output, $expected, t("Drupal::service('pathauto.alias_cleaner')->cleanString('@input') expected '@expected', actual '@output'", [
$this->assertEquals($output, $expected, t("Drupal::service('pathauto.alias_cleaner')->cleanString('@input') expected '@expected', actual '@output'", [
'@input' => $input,
'@expected' => $expected,
'@output' => $output,
......@@ -236,7 +236,7 @@ class PathautoKernelTest extends KernelTestBase {
foreach ($tests as $input => $expected) {
$output = \Drupal::service('pathauto.alias_cleaner')->cleanAlias($input);
$this->assertEqual($output, $expected, t("Drupal::service('pathauto.generator')->cleanAlias('@input') expected '@expected', actual '@output'", [
$this->assertEquals($output, $expected, t("Drupal::service('pathauto.generator')->cleanAlias('@input') expected '@expected', actual '@output'", [
'@input' => $input,
'@expected' => $expected,
'@output' => $output,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment