Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
5 use Drupal\Core\Config\ImmutableConfig; | 5 use Drupal\Core\Config\ImmutableConfig; |
6 use Drupal\Core\Session\AccountInterface; | 6 use Drupal\Core\Session\AccountInterface; |
7 use Drupal\Tests\UnitTestCase; | 7 use Drupal\Tests\UnitTestCase; |
8 use Drupal\user\Entity\User; | 8 use Drupal\user\Entity\User; |
9 use Drupal\user\Plugin\rest\resource\UserRegistrationResource; | 9 use Drupal\user\Plugin\rest\resource\UserRegistrationResource; |
10 use Drupal\user\UserInterface; | |
10 use Psr\Log\LoggerInterface; | 11 use Psr\Log\LoggerInterface; |
11 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | 12 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
12 use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | 13 use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
13 | |
14 /** | |
15 * Only administrators can create user accounts. | |
16 */ | |
17 if (!defined('USER_REGISTER_ADMINISTRATORS_ONLY')) { | |
18 define('USER_REGISTER_ADMINISTRATORS_ONLY', 'admin_only'); | |
19 } | |
20 | |
21 /** | |
22 * Visitors can create their own accounts. | |
23 */ | |
24 if (!defined('USER_REGISTER_VISITORS')) { | |
25 define('USER_REGISTER_VISITORS', 'visitors'); | |
26 } | |
27 | |
28 /** | |
29 * Visitors can create accounts, but they don't become active without | |
30 * administrative approval. | |
31 */ | |
32 if (!defined('USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL')) { | |
33 define('USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL', 'visitors_admin_approval'); | |
34 } | |
35 | 14 |
36 /** | 15 /** |
37 * Tests User Registration REST resource. | 16 * Tests User Registration REST resource. |
38 * | 17 * |
39 * @coversDefaultClass \Drupal\user\Plugin\rest\resource\UserRegistrationResource | 18 * @coversDefaultClass \Drupal\user\Plugin\rest\resource\UserRegistrationResource |
116 /** | 95 /** |
117 * Tests that admin permissions are required to register a user account. | 96 * Tests that admin permissions are required to register a user account. |
118 */ | 97 */ |
119 public function testRegistrationAdminOnlyPost() { | 98 public function testRegistrationAdminOnlyPost() { |
120 | 99 |
121 $this->userSettings->get('register')->willReturn(USER_REGISTER_ADMINISTRATORS_ONLY); | 100 $this->userSettings->get('register')->willReturn(UserInterface::REGISTER_ADMINISTRATORS_ONLY); |
122 | 101 |
123 $this->currentUser->isAnonymous()->willReturn(TRUE); | 102 $this->currentUser->isAnonymous()->willReturn(TRUE); |
124 | 103 |
125 $this->testClass = new UserRegistrationResource([], 'plugin_id', '', [], $this->logger, $this->userSettings->reveal(), $this->currentUser->reveal()); | 104 $this->testClass = new UserRegistrationResource([], 'plugin_id', '', [], $this->logger, $this->userSettings->reveal(), $this->currentUser->reveal()); |
126 | 105 |