Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Auth/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function blueprint()
}

$blueprint = Blueprint::find('user') ?? Blueprint::makeFromFields([
'name' => ['type' => 'text', 'display' => __('Name'), 'listable' => true],
'email' => ['type' => 'text', 'input_type' => 'email', 'display' => __('Email Address'), 'listable' => true],
'name' => ['type' => 'text', 'autocomplete' => 'name', 'display' => __('Name'), 'listable' => true],
'email' => ['type' => 'text', 'input_type' => 'email', 'autocomplete' => 'email', 'display' => __('Email Address'), 'listable' => true],
])->setHandle('user');

$blueprint->ensureField('email', ['type' => 'text', 'input_type' => 'email', 'display' => __('Email Address'), 'listable' => true]);
$blueprint->ensureField('email', ['type' => 'text', 'input_type' => 'email', 'autocomplete' => 'email', 'display' => __('Email Address'), 'listable' => true]);

if (Statamic::pro()) {
$blueprint->ensureField('roles', ['type' => 'user_roles', 'mode' => 'select', 'width' => 50, 'listable' => true, 'filterable' => false]);
Expand Down
16 changes: 15 additions & 1 deletion tests/Auth/UserContractTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,31 @@ public function it_provides_email_field_fallback_in_blueprint()
$this->assertTrue($this->user()->blueprint()->hasField('email'));
$this->assertEquals('Email Address', $this->user()->blueprint()->fields()->get('email')->display());
$this->assertEquals('email', $this->user()->blueprint()->fields()->get('email')->get('input_type'));
$this->assertEquals('email', $this->user()->blueprint()->fields()->get('email')->get('autocomplete'));
}

#[Test]
public function it_allows_email_field_customizations_in_blueprint()
{
$blueprint = Blueprint::makeFromFields(['email' => ['display' => 'Custom Email Display']]);
$blueprint = Blueprint::makeFromFields(['email' => ['display' => 'Custom Email Display', 'autocomplete' => 'off']]);
Blueprint::shouldReceive('find')->with('user')->andReturn($blueprint);

$this->assertTrue($this->user()->blueprint()->hasField('email'));
$this->assertEquals('Custom Email Display', $this->user()->blueprint()->fields()->get('email')->display());
$this->assertEquals('email', $this->user()->blueprint()->fields()->get('email')->get('input_type'));
$this->assertEquals('off', $this->user()->blueprint()->fields()->get('email')->get('autocomplete'));
}

#[Test]
public function it_provides_name_and_email_fields_when_no_blueprint_is_defined()
{
Blueprint::partialMock()->shouldReceive('find')->with('user')->andReturnNull();

$fields = $this->user()->blueprint()->fields();

$this->assertEquals('name', $fields->get('name')->get('autocomplete'));
$this->assertEquals('email', $fields->get('email')->get('autocomplete'));
$this->assertEquals('email', $fields->get('email')->get('input_type'));
}

#[Test]
Expand Down
10 changes: 5 additions & 5 deletions tests/Tags/User/ProfileFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function it_renders_form_with_fields_array()
preg_match_all($this->regex(), $output, $actual);

$expected = [
'<label>Name</label><input id="userprofile-form-name-field" type="text" name="name" value="Test User">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com">',
'<label>Name</label><input id="userprofile-form-name-field" type="text" name="name" value="Test User" autocomplete="name">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com" autocomplete="email">',
];

$this->assertEquals($expected, $actual[0]);
Expand Down Expand Up @@ -112,7 +112,7 @@ public function it_renders_form_with_tabs_array_and_custom_blueprint()
'<h2 class="tab">Main</h2>',
'<h3 class="section">Account</h3>',
'<label>Full Name</label><input id="userprofile-form-name-field" type="text" name="name" value="Test User">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com" autocomplete="email">',
'<h3 class="section">About you</h3>',
'<label>Phone Number</label><input id="userprofile-form-phone-field" type="text" name="phone" value="12345">',
'<label>Over 18 years of age?</label><input id="userprofile-form-age-field" type="text" name="age" value="" required>',
Expand Down Expand Up @@ -150,7 +150,7 @@ public function it_renders_form_with_sections_array_and_custom_blueprint()
$expected = [
'<h3 class="section">Account</h3>',
'<label>Full Name</label><input id="userprofile-form-name-field" type="text" name="name" value="Test User">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com" autocomplete="email">',
'<h3 class="section">About you</h3>',
'<label>Phone Number</label><input id="userprofile-form-phone-field" type="text" name="phone" value="12345">',
'<label>Over 18 years of age?</label><input id="userprofile-form-age-field" type="text" name="age" value="" required>',
Expand Down Expand Up @@ -183,7 +183,7 @@ public function it_renders_form_with_fields_array_and_custom_blueprint()

$expected = [
'<label>Full Name</label><input id="userprofile-form-name-field" type="text" name="name" value="Test User">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com">',
'<label>Email Address</label><input id="userprofile-form-email-field" type="email" name="email" value="test@example.com" autocomplete="email">',
'<label>Phone Number</label><input id="userprofile-form-phone-field" type="text" name="phone" value="12345">',
'<label>Over 18 years of age?</label><input id="userprofile-form-age-field" type="text" name="age" value="" required>',
'<label>Newsletter</label><label><input type="hidden" name="newsletter" value="0"><input id="userprofile-form-newsletter-field" type="checkbox" name="newsletter" value="1" checked></label>',
Expand Down
6 changes: 3 additions & 3 deletions tests/Tags/User/RegisterFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public function it_renders_form_with_fields_array()
preg_match_all('/<label>.+<\/label><input.+>/U', $output, $actual);

$expected = [
'<label>Email Address</label><input id="userregister-form-email-field" type="email" name="email" value="">',
'<label>Email Address</label><input id="userregister-form-email-field" type="email" name="email" value="" autocomplete="email">',
'<label>Password</label><input id="userregister-form-password-field" type="password" name="password" value="">',
'<label>Password Confirmation</label><input id="userregister-form-password-confirmation-field" type="password" name="password_confirmation" value="">',
'<label>Name</label><input id="userregister-form-name-field" type="text" name="name" value="">',
'<label>Name</label><input id="userregister-form-name-field" type="text" name="name" value="" autocomplete="name">',
];

$this->assertEquals($expected, $actual[0]);
Expand All @@ -96,7 +96,7 @@ public function it_renders_form_with_fields_array_and_custom_blueprint()
preg_match_all('/<label>.+<\/label><input.+>/U', $output, $actual);

$expected = [
'<label>Email Address</label><input id="userregister-form-email-field" type="email" name="email" value="">',
'<label>Email Address</label><input id="userregister-form-email-field" type="email" name="email" value="" autocomplete="email">',
'<label>Password</label><input id="userregister-form-password-field" type="password" name="password" value="">',
'<label>Password Confirmation</label><input id="userregister-form-password-confirmation-field" type="password" name="password_confirmation" value="">',
'<label>Full Name</label><input id="userregister-form-name-field" type="text" name="name" value="">',
Expand Down
Loading