UserControllerTest.php

Same filename and directory in other branches
  1. 9 core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php
  2. 8.9.x core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php
  3. 10 core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php

Namespace

Drupal\Tests\user\Kernel\Controller

File

core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\user\Kernel\Controller;

use Drupal\Core\Url;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Controller\UserController;

/**
 * Tests for the User controller.
 *
 * @group user
 *
 * @coversDefaultClass \Drupal\user\Controller\UserController
 */
class UserControllerTest extends KernelTestBase {
    use UserCreationTrait;
    
    /**
     * The user controller.
     *
     * @var \Drupal\user\Controller\UserController
     */
    protected $userController;
    
    /**
     * The logged in user.
     *
     * @var \Drupal\user\UserInterface
     */
    protected $user;
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'user',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->userController = UserController::create(\Drupal::getContainer());
        // Create and log in a user.
        $this->user = $this->setUpCurrentUser();
    }
    
    /**
     * Tests the redirection to a user edit page.
     *
     * @covers ::userEditPage
     */
    public function testUserEditPage() : void {
        $response = $this->userController
            ->userEditPage();
        // Ensure the response is directed to the correct user edit page.
        $edit_url = Url::fromRoute('entity.user.edit_form', [
            'user' => $this->user
                ->id(),
        ])
            ->setAbsolute()
            ->toString();
        $this->assertEquals($edit_url, $response->getTargetUrl());
        $this->assertEquals(302, $response->getStatusCode());
    }

}

Classes

Title Deprecated Summary
UserControllerTest Tests for the User controller.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.