diff --git a/src/Core/Form.php b/src/Core/Form.php index 0143d75fbe..af90d2e451 100644 --- a/src/Core/Form.php +++ b/src/Core/Form.php @@ -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']); diff --git a/tests/Controller/SecurityTest.php b/tests/Controller/SecurityTest.php index e8a2d3f6f7..295c3ce9e0 100644 --- a/tests/Controller/SecurityTest.php +++ b/tests/Controller/SecurityTest.php @@ -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() diff --git a/tests/Core/FormTest.php b/tests/Core/FormTest.php index fdd93cc052..b920a0bfe7 100644 --- a/tests/Core/FormTest.php +++ b/tests/Core/FormTest.php @@ -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);