silverstripe-framework/tests/php/Forms/PasswordFieldTest.php

48 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Forms\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\PasswordField;
2024-09-18 03:53:44 +02:00
use PHPUnit\Framework\Attributes\DataProvider;
class PasswordFieldTest extends SapphireTest
{
2024-09-18 03:53:44 +02:00
public static function boolDataProvider()
{
return [
[false],
[true]
];
}
/**
* @param bool $bool
*/
2024-09-18 03:53:44 +02:00
#[DataProvider('boolDataProvider')]
public function testAutocomplete($bool)
{
Config::modify()->set(PasswordField::class, 'autocomplete', $bool);
$field = new PasswordField('test');
$attrs = $field->getAttributes();
$this->assertArrayHasKey('autocomplete', $attrs);
$this->assertEquals($bool ? 'on' : 'off', $attrs['autocomplete']);
}
/**
* @param bool $bool
*/
2024-09-18 03:53:44 +02:00
#[DataProvider('boolDataProvider')]
public function testValuePostback($bool)
{
$field = (new PasswordField('test', 'test', 'password'))
->setAllowValuePostback($bool);
$attrs = $field->getAttributes();
$this->assertArrayHasKey('value', $attrs);
$this->assertEquals($bool ? 'password' : '', $attrs['value']);
}
}