Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / pathauto / src / Tests / PathautoUserWebTest.php
1 <?php
2
3 namespace Drupal\pathauto\Tests;
4
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    * Basic functional testing of Pathauto with users.
52    */
53   function testUserEditing() {
54     // There should be no Pathauto checkbox on user forms.
55     $this->drupalGet('user/' . $this->adminUser->id() . '/edit');
56     $this->assertNoFieldById('path[0][pathauto]');
57   }
58
59   /**
60    * Test user operations.
61    */
62   function testUserOperations() {
63     $account = $this->drupalCreateUser();
64
65     // Delete all current URL aliases.
66     $this->deleteAllAliases();
67
68     // Find the position of just created account in the user_admin_people view.
69     $view = Views::getView('user_admin_people');
70     $view->initDisplay();
71     $view->preview('page_1');
72
73     foreach ($view->result as $key => $row) {
74       if ($view->field['name']->getValue($row) == $account->getUsername()) {
75         break;
76       }
77     }
78
79     $edit = array(
80       'action' => 'pathauto_update_alias_user',
81       "user_bulk_form[$key]" => TRUE,
82     );
83     $this->drupalPostForm('admin/people', $edit, t('Apply to selected items'));
84     $this->assertText('Update URL alias was applied to 1 item.');
85
86     $this->assertEntityAlias($account, '/users/' . mb_strtolower($account->getUsername()));
87     $this->assertEntityAlias($this->adminUser, '/user/' . $this->adminUser->id());
88   }
89
90 }