Skip to content

Commit 03191b3

Browse files
Merge branch 'hotfix' into feature-docker-refinements
2 parents 1d674fe + e82129f commit 03191b3

7 files changed

Lines changed: 94 additions & 80 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ before_install:
3333

3434
before_script:
3535
# install deps and UF
36-
- composer install
36+
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --no-interaction
3737
- php bakery debug
3838
- php bakery build-assets
3939
- php bakery migrate

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [v4.2.1]
9+
- Fix Italian translation ([#950])
10+
- User Registration fails when trying to register two accounts with the same email address ([#953])
11+
812
## [v4.2.0]
913
### Changed Requirements
1014
- Changed minimum Node.js version to **v10.12.0**
@@ -704,5 +708,8 @@ See [http://learn.userfrosting.com/upgrading/40-to-41](Upgrading 4.0.x to 4.1.x
704708
[#888]: https://github.com/userfrosting/UserFrosting/issues/888
705709
[#919]: https://github.com/userfrosting/UserFrosting/issues/919
706710
[#940]: https://github.com/userfrosting/UserFrosting/issues/940
711+
[#950]: https://github.com/userfrosting/UserFrosting/issues/950
712+
[#953]: https://github.com/userfrosting/UserFrosting/issues/953
707713

708714
[v4.2.0]: https://github.com/userfrosting/UserFrosting/compare/v4.1.22...v4.2.0
715+
[v4.2.1]: https://github.com/userfrosting/UserFrosting/compare/v4.2.0...v4.2.1

app/sprinkles/account/locale/it_IT/messages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,5 @@
182182
'USER_OR_EMAIL_INVALID' => "L'indirizzo mail o il nome utente non sono validi",
183183
'USER_OR_PASS_INVALID' => 'Il nome utente o la password non sono validi',
184184

185-
'WELCOME' => 'Bentornato, {{display_name}}'
185+
'WELCOME' => 'Bentornato, {{first_name}}'
186186
];

app/sprinkles/account/src/Account/Registration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ public function validate()
161161

162162
// Check if username is unique
163163
if (!$this->usernameIsUnique($this->userdata['user_name'])) {
164-
$e = new HttpException();
165-
$e->addUserMessage('USERNAME.IN_USE');
164+
$e = new HttpException('Username is already in use.');
165+
$e->addUserMessage('USERNAME.IN_USE', ['user_name' => $this->userdata['user_name']]);
166166
throw $e;
167167
}
168168

169169
// Check if email is unique
170170
if (!$this->emailIsUnique($this->userdata['email'])) {
171-
$e = new HttpException();
172-
$e->addUserMessage('EMAIL.IN_USE');
171+
$e = new HttpException('Email is already in use.');
172+
$e->addUserMessage('EMAIL.IN_USE', ['email' => $this->userdata['email']]);
173173
throw $e;
174174
}
175175

app/sprinkles/account/src/Controller/AccountController.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -913,12 +913,9 @@ public function register(Request $request, Response $response, $args)
913913
// Now that we check the form, we can register the actual user
914914
$registration = new Registration($this->ci, $data);
915915

916-
try {
917-
$user = $registration->register();
918-
} catch (\Exception $e) {
919-
$ms->addMessageTranslated('danger', $e->getMessage(), $data);
920-
$error = true;
921-
}
916+
// Try registration. An HttpException will be thrown if it fails
917+
// No need to catch, as this kind of exception will automatically returns the addMessageTranslated
918+
$user = $registration->register();
922919

923920
// Success message
924921
if ($config['site.registration.require_email_verification']) {

app/sprinkles/account/tests/Unit/RegistrationTest.php

Lines changed: 74 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use UserFrosting\Sprinkle\Core\Tests\RefreshDatabase;
1616
use UserFrosting\Sprinkle\Account\Account\Registration;
1717
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
18-
use UserFrosting\Support\Exception\HttpException;
18+
use UserFrosting\Sprinkle\Account\Database\Models\User;
1919

2020
/**
2121
* RegistrationTest Class
@@ -26,6 +26,17 @@ class RegistrationTest extends TestCase
2626
use TestDatabase;
2727
use RefreshDatabase;
2828

29+
/**
30+
* @var array Test user data
31+
*/
32+
protected $fakeUserData = [
33+
'user_name' => 'FooBar',
34+
'first_name' => 'Foo',
35+
'last_name' => 'Bar',
36+
'email' => 'Foo@Bar.com',
37+
'password' => 'FooBarFooBar123'
38+
];
39+
2940
public function tearDown()
3041
{
3142
parent::tearDown();
@@ -45,7 +56,43 @@ public function setUp()
4556
}
4657

4758
/**
48-
* testNormalRegistration
59+
* Test validation works
60+
*/
61+
public function testValidation()
62+
{
63+
$registration = new Registration($this->ci, [
64+
'user_name' => 'OwlFancy',
65+
'first_name' => 'Owl',
66+
'last_name' => 'Fancy',
67+
'email' => 'owl@fancy.com',
68+
'password' => 'owlFancy1234'
69+
]);
70+
71+
$validation = $registration->validate();
72+
$this->assertTrue($validation);
73+
}
74+
75+
/**
76+
* Test the $requiredProperties property
77+
* @depends testValidation
78+
* @expectedException UserFrosting\Support\Exception\HttpException
79+
* @expectedExceptionMessage Account can't be registrated as 'first_name' is required to create a new user.
80+
*/
81+
public function testMissingFields()
82+
{
83+
$registration = new Registration($this->ci, [
84+
'user_name' => 'OwlFancy',
85+
//'first_name' => 'Owl',
86+
'last_name' => 'Fancy',
87+
'email' => 'owl@fancy.com',
88+
'password' => 'owlFancy1234'
89+
]);
90+
91+
$validation = $registration->validate();
92+
}
93+
94+
/**
95+
* @depends testValidation
4996
*/
5097
public function testNormalRegistration()
5198
{
@@ -56,77 +103,53 @@ public function testNormalRegistration()
56103
// Tests can't mail properly
57104
$this->ci->config['site.registration.require_email_verification'] = false;
58105

59-
// Genereate user data
60-
$fakeUserData = [
61-
'user_name' => 'FooBar',
62-
'first_name' => 'Foo',
63-
'last_name' => 'Bar',
64-
'email' => 'Foo@Bar.com',
65-
'password' => 'FooBarFooBar123'
66-
];
67-
68106
// Get class
69-
$registration = new Registration($this->ci, $fakeUserData);
107+
$registration = new Registration($this->ci, $this->fakeUserData);
70108
$this->assertInstanceOf(Registration::class, $registration);
71109

72110
// Register user
73111
$user = $registration->register();
74112

75-
// Registration should return a valid user
113+
// Registration should return a valid user, with a new ID
76114
$this->assertInstanceOf(UserInterface::class, $user);
77115
$this->assertEquals('FooBar', $user->user_name);
116+
$this->assertInternalType('int', $user->id);
78117

79-
// We try to register the same user again. Should throw an error
80-
$registration = new Registration($this->ci, $fakeUserData);
81-
$this->expectException(HttpException::class);
82-
$validation = $registration->validate();
83-
84-
// Should throw email error if we change the username
85-
$fakeUserData['user_name'] = 'BarFoo';
86-
$registration = new Registration($this->ci, $fakeUserData);
87-
$this->expectException(HttpException::class);
88-
$validation = $registration->validate();
118+
// Make sure the user is added to the db by querying it
119+
$users = User::where('email', 'Foo@Bar.com')->get();
120+
$this->assertCount(1, $users);
121+
$this->assertSame('FooBar', $users->first()['user_name']);
89122
}
90123

91124
/**
92-
* Test validation works
125+
* @depends testNormalRegistration
126+
* @expectedException UserFrosting\Support\Exception\HttpException
127+
* @expectedExceptionMessage Username is already in use.
93128
*/
94-
public function testValidation()
129+
public function testValidationWithDuplicateUsername()
95130
{
96-
// Reset database
97-
$this->refreshDatabase();
98-
99-
$registration = new Registration($this->ci, [
100-
'user_name' => 'FooBar',
101-
'first_name' => 'Foo',
102-
'last_name' => 'Bar',
103-
'email' => 'Foo@Bar.com',
104-
'password' => 'FooBarFooBar123'
105-
]);
131+
// Create the first user to test against
132+
$this->testNormalRegistration();
106133

107-
// Validate user. Shouldn't tell us the username is already in use since we reset the database
134+
// We try to register the same user again. Should throw an error
135+
$registration = new Registration($this->ci, $this->fakeUserData);
108136
$validation = $registration->validate();
109-
$this->assertTrue($validation);
110137
}
111138

112139
/**
113-
* Test the $requiredProperties property
140+
* @depends testNormalRegistration
141+
* @expectedException UserFrosting\Support\Exception\HttpException
142+
* @expectedExceptionMessage Email is already in use.
114143
*/
115-
public function testMissingFields()
144+
public function testValidationWithDuplicateEmail()
116145
{
117-
// Reset database
118-
$this->refreshDatabase();
146+
// Create the first user to test against
147+
$this->testNormalRegistration();
119148

120-
$registration = new Registration($this->ci, [
121-
'user_name' => 'FooBar',
122-
//'first_name' => 'Foo',
123-
'last_name' => 'Bar',
124-
'email' => 'Foo@Bar.com',
125-
'password' => 'FooBarFooBar123'
126-
]);
127-
128-
// Validate user. Shouldn't tell us the username is already in use since we reset the database
129-
$this->expectException(HttpException::class);
149+
// Should throw email error if we change the username
150+
$fakeUserData = $this->fakeUserData;
151+
$fakeUserData['user_name'] = 'BarFoo';
152+
$registration = new Registration($this->ci, $fakeUserData);
130153
$validation = $registration->validate();
131154
}
132155
}

app/sprinkles/core/tests/Integration/DatabaseMigratorServiceTest.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,18 @@
99

1010
namespace UserFrosting\Sprinkle\Core\Tests\Integration;
1111

12-
use UserFrosting\Sprinkle\Core\Tests\TestDatabase;
12+
use UserFrosting\Sprinkle\Core\Database\Migrator\Migrator;
1313
use UserFrosting\Tests\TestCase;
1414

1515
/**
16-
* Tests for the Migrator Service
16+
* Tests for the Migrator Service
1717
*
18-
* @author Louis Charette
18+
* @author Louis Charette
1919
*/
2020
class DatabaseMigratorServiceTest extends TestCase
2121
{
22-
use TestDatabase;
23-
24-
/**
25-
* {@inheritdoc}
26-
*/
27-
public function setUp()
28-
{
29-
parent::setUp();
30-
31-
// Setup test database
32-
$this->setupTestDatabase();
33-
}
34-
3522
public function testMigratorService()
3623
{
37-
$this->assertInstanceOf('UserFrosting\Sprinkle\Core\Database\Migrator\Migrator', $this->ci->migrator);
24+
$this->assertInstanceOf(Migrator::class, $this->ci->migrator);
3825
}
3926
}

0 commit comments

Comments
 (0)