Version 1
[yaffs-website] / web / core / modules / user / tests / src / Unit / Menu / UserLocalTasksTest.php
diff --git a/web/core/modules/user/tests/src/Unit/Menu/UserLocalTasksTest.php b/web/core/modules/user/tests/src/Unit/Menu/UserLocalTasksTest.php
new file mode 100644 (file)
index 0000000..b9986c9
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+namespace Drupal\Tests\user\Unit\Menu;
+
+use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
+
+/**
+ * Tests user local tasks.
+ *
+ * @group user
+ */
+class UserLocalTasksTest extends LocalTaskIntegrationTestBase {
+
+  protected function setUp() {
+    $this->directoryList = ['user' => 'core/modules/user'];
+    parent::setUp();
+  }
+
+  /**
+   * Tests local task existence.
+   *
+   * @dataProvider getUserAdminRoutes
+   */
+  public function testUserAdminLocalTasks($route, $expected) {
+    $this->assertLocalTasks($route, $expected);
+  }
+
+  /**
+   * Provides a list of routes to test.
+   */
+  public function getUserAdminRoutes() {
+    return [
+      ['entity.user.collection', [['entity.user.collection', 'user.admin_permissions', 'entity.user_role.collection']]],
+      ['user.admin_permissions', [['entity.user.collection', 'user.admin_permissions', 'entity.user_role.collection']]],
+      ['entity.user_role.collection', [['entity.user.collection', 'user.admin_permissions', 'entity.user_role.collection']]],
+      ['entity.user.admin_form', [['user.account_settings_tab']]],
+    ];
+  }
+
+  /**
+   * Checks user listing local tasks.
+   *
+   * @dataProvider getUserLoginRoutes
+   */
+  public function testUserLoginLocalTasks($route) {
+    $tasks = [
+      0 => ['user.register', 'user.pass', 'user.login'],
+    ];
+    $this->assertLocalTasks($route, $tasks);
+  }
+
+  /**
+   * Provides a list of routes to test.
+   */
+  public function getUserLoginRoutes() {
+    return [
+      ['user.login'],
+      ['user.register'],
+      ['user.pass'],
+    ];
+  }
+
+  /**
+   * Checks user listing local tasks.
+   *
+   * @dataProvider getUserPageRoutes
+   */
+  public function testUserPageLocalTasks($route, $subtask = []) {
+    $tasks = [
+      0 => ['entity.user.canonical', 'entity.user.edit_form'],
+    ];
+    if ($subtask) $tasks[] = $subtask;
+    $this->assertLocalTasks($route, $tasks);
+  }
+
+  /**
+   * Provides a list of routes to test.
+   */
+  public function getUserPageRoutes() {
+    return [
+      ['entity.user.canonical'],
+      ['entity.user.edit_form'],
+    ];
+  }
+
+}