Version 1
[yaffs-website] / web / modules / contrib / pathauto / src / Tests / PathautoUserWebTest.php
1 <?php
2
3 namespace Drupal\pathauto\Tests;
4 use Drupal\Component\Utility\Unicode;
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\views\Views;
7
8 /**
9  * Tests pathauto user UI integration.
10  *
11  * @group pathauto
12  */
13 class PathautoUserWebTest extends WebTestBase {
14
15   use PathautoTestHelperTrait;
16
17   /**
18    * Modules to enable.
19    *
20    * @var array
21    */
22   public static $modules = array('pathauto', 'views');
23
24   /**
25    * Admin user.
26    *
27    * @var \Drupal\user\UserInterface
28    */
29   protected $adminUser;
30
31   /**
32    * {inheritdoc}
33    */
34   function setUp() {
35     parent::setUp();
36
37     // Allow other modules to add additional permissions for the admin user.
38     $permissions = array(
39       'administer pathauto',
40       'administer url aliases',
41       'create url aliases',
42       'administer users',
43     );
44     $this->adminUser = $this->drupalCreateUser($permissions);
45     $this->drupalLogin($this->adminUser);
46
47     $this->createPattern('user', '/users/[user:name]');
48   }
49
50
51   /**
52    * Basic functional testing of Pathauto with users.
53    */
54   function testUserEditing() {
55     // There should be no Pathauto checkbox on user forms.
56     $this->drupalGet('user/' . $this->adminUser->id() . '/edit');
57     $this->assertNoFieldById('path[0][pathauto]');
58   }
59
60   /**
61    * Test user operations.
62    */
63   function testUserOperations() {
64     $account = $this->drupalCreateUser();
65
66     // Delete all current URL aliases.
67     $this->deleteAllAliases();
68
69     // Find the position of just created account in the user_admin_people view.
70     $view = Views::getView('user_admin_people');
71     $view->initDisplay();
72     $view->preview('page_1');
73
74
75     foreach ($view->result as $key => $row) {
76       if ($view->field['name']->getValue($row) == $account->getUsername()) {
77         break;
78       }
79     }
80
81     $edit = array(
82       'action' => 'pathauto_update_alias_user',
83       "user_bulk_form[$key]" => TRUE,
84     );
85     $this->drupalPostForm('admin/people', $edit, t('Apply to selected items'));
86     $this->assertText('Update URL alias was applied to 1 item.');
87
88     $this->assertEntityAlias($account, '/users/' . Unicode::strtolower($account->getUsername()));
89     $this->assertEntityAlias($this->adminUser, '/user/' . $this->adminUser->id());
90   }
91
92 }