PathAdminTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Drupal\Tests\path\Functional;
  3. /**
  4. * Tests the Path admin UI.
  5. *
  6. * @group path
  7. */
  8. class PathAdminTest extends PathTestBase {
  9. /**
  10. * Modules to enable.
  11. *
  12. * @var array
  13. */
  14. public static $modules = ['path'];
  15. protected function setUp() {
  16. parent::setUp();
  17. // Create test user and log in.
  18. $web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer url aliases', 'create url aliases']);
  19. $this->drupalLogin($web_user);
  20. }
  21. /**
  22. * Tests the filtering aspect of the Path UI.
  23. */
  24. public function testPathFiltering() {
  25. // Create test nodes.
  26. $node1 = $this->drupalCreateNode();
  27. $node2 = $this->drupalCreateNode();
  28. $node3 = $this->drupalCreateNode();
  29. // Create aliases.
  30. $alias1 = '/' . $this->randomMachineName(8);
  31. $edit = [
  32. 'source' => '/node/' . $node1->id(),
  33. 'alias' => $alias1,
  34. ];
  35. $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
  36. $alias2 = '/' . $this->randomMachineName(8);
  37. $edit = [
  38. 'source' => '/node/' . $node2->id(),
  39. 'alias' => $alias2,
  40. ];
  41. $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
  42. $alias3 = '/' . $this->randomMachineName(4) . '/' . $this->randomMachineName(4);
  43. $edit = [
  44. 'source' => '/node/' . $node3->id(),
  45. 'alias' => $alias3,
  46. ];
  47. $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
  48. // Filter by the first alias.
  49. $edit = [
  50. 'filter' => $alias1,
  51. ];
  52. $this->drupalPostForm(NULL, $edit, t('Filter'));
  53. $this->assertLinkByHref($alias1);
  54. $this->assertNoLinkByHref($alias2);
  55. $this->assertNoLinkByHref($alias3);
  56. // Filter by the second alias.
  57. $edit = [
  58. 'filter' => $alias2,
  59. ];
  60. $this->drupalPostForm(NULL, $edit, t('Filter'));
  61. $this->assertNoLinkByHref($alias1);
  62. $this->assertLinkByHref($alias2);
  63. $this->assertNoLinkByHref($alias3);
  64. // Filter by the third alias which has a slash.
  65. $edit = [
  66. 'filter' => $alias3,
  67. ];
  68. $this->drupalPostForm(NULL, $edit, t('Filter'));
  69. $this->assertNoLinkByHref($alias1);
  70. $this->assertNoLinkByHref($alias2);
  71. $this->assertLinkByHref($alias3);
  72. // Filter by a random string with a different length.
  73. $edit = [
  74. 'filter' => $this->randomMachineName(10),
  75. ];
  76. $this->drupalPostForm(NULL, $edit, t('Filter'));
  77. $this->assertNoLinkByHref($alias1);
  78. $this->assertNoLinkByHref($alias2);
  79. // Reset the filter.
  80. $edit = [];
  81. $this->drupalPostForm(NULL, $edit, t('Reset'));
  82. $this->assertLinkByHref($alias1);
  83. $this->assertLinkByHref($alias2);
  84. }
  85. }