[CORE][Form][TESTS] Fix FormTest::handle
This commit is contained in:
parent
63ef9292f3
commit
e1cceac150
@ -111,16 +111,14 @@ abstract class Form
|
||||
Log::critical($m = "It's generally a bad idea to use {$key} as a form name, because it can conflict with other forms in the same page");
|
||||
throw new ServerException($m);
|
||||
}
|
||||
if ($target != null && empty($options['data']) && (mb_strstr($key, 'password') == false) && $class != SubmitType::class) {
|
||||
if (isset($extra_data[$key])) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$options['data'] = $extra_data[$key];
|
||||
// @codeCoverageIgnoreEnd
|
||||
} else {
|
||||
$method = 'get' . ucfirst(Formatting::snakeCaseToCamelCase($key));
|
||||
if (method_exists($target, $method)) {
|
||||
$options['data'] = $target->{$method}();
|
||||
}
|
||||
if (isset($extra_data[$key])) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$options['data'] = $extra_data[$key];
|
||||
// @codeCoverageIgnoreEnd
|
||||
} elseif (!\is_null($target)) {
|
||||
$method = 'get' . ucfirst(Formatting::snakeCaseToCamelCase($key));
|
||||
if (method_exists($target, $method)) {
|
||||
$options['data'] = $target->{$method}();
|
||||
}
|
||||
}
|
||||
unset($options['hide']);
|
||||
|
@ -66,7 +66,7 @@ class SecurityTest extends GNUsocialTestCase
|
||||
{
|
||||
self::testLogin('taken_user', 'wrong password');
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertSelectorTextContains('.alert', 'Invalid login credentials');
|
||||
$this->assertSelectorTextContains('.alert', 'The presented password is invalid.');
|
||||
$this->assertRouteSame('security_login');
|
||||
}
|
||||
|
||||
@ -100,11 +100,8 @@ class SecurityTest extends GNUsocialTestCase
|
||||
[$client,] = self::testRegister('new_nickname', 'new_email@provider.any', 'foobar');
|
||||
$this->assertResponseStatusCodeSame(302);
|
||||
$crawler = $client->followRedirect();
|
||||
$this->assertRouteSame('root');
|
||||
$client->followRedirect();
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertRouteSame('security_login');
|
||||
$this->assertSelectorNotExists('.alert');
|
||||
$this->assertSelectorTextContains('.profile-info-url-nickname', 'new_nickname');
|
||||
}
|
||||
|
||||
public function testRegisterDifferentPassword()
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace App\Tests\Core;
|
||||
|
||||
use App\Core\ActorLocalRoles;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Form;
|
||||
use App\Entity\Actor;
|
||||
@ -110,7 +111,8 @@ class FormTest extends GNUsocialTestCase
|
||||
parent::bootKernel();
|
||||
$data = ['fullname' => 'Full Name', 'homepage' => 'gnu.org'];
|
||||
$mock_request = static::createMock(Request::class);
|
||||
$mock_form = static::createMock(SymfForm::class);
|
||||
$mock_request->method('getMethod')->willReturn('POST');
|
||||
$mock_form = static::createMock(SymfForm::class);
|
||||
$mock_form->method('handleRequest');
|
||||
$mock_form->method('isSubmitted')->willReturn(true);
|
||||
$mock_form->method('isValid')->willReturn(true);
|
||||
@ -118,7 +120,7 @@ class FormTest extends GNUsocialTestCase
|
||||
$ret = Form::handle(form_definition: [/* not normal usage */], request: $mock_request, target: null, extra_args: [], before_step: null, after_step: null, create_args: [], testing_only_form: $mock_form);
|
||||
static::assertSame($data, $ret);
|
||||
|
||||
$actor = Actor::create(['nickname' => 'form_testing_new_user', 'is_local' => false]);
|
||||
$actor = Actor::create(['nickname' => 'form_testing_new_user', 'is_local' => false, 'roles' => ActorLocalRoles::PARTICIPANT | ActorLocalRoles::VISITOR, 'type' => Actor::PERSON]);
|
||||
DB::persist($actor);
|
||||
$ret = Form::handle(form_definition: [/* not normal usage */], request: $mock_request, target: $actor, extra_args: [], before_step: null, after_step: null, create_args: [], testing_only_form: $mock_form);
|
||||
static::assertSame($mock_form, $ret);
|
||||
|
Loading…
Reference in New Issue
Block a user