[CORE][Form][TESTS] Fix FormTest::handle

This commit is contained in:
Hugo Sales 2022-03-13 18:53:53 +00:00
parent 63ef9292f3
commit e1cceac150
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 14 additions and 17 deletions

View File

@ -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"); 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); throw new ServerException($m);
} }
if ($target != null && empty($options['data']) && (mb_strstr($key, 'password') == false) && $class != SubmitType::class) { if (isset($extra_data[$key])) {
if (isset($extra_data[$key])) { // @codeCoverageIgnoreStart
// @codeCoverageIgnoreStart $options['data'] = $extra_data[$key];
$options['data'] = $extra_data[$key]; // @codeCoverageIgnoreEnd
// @codeCoverageIgnoreEnd } elseif (!\is_null($target)) {
} else { $method = 'get' . ucfirst(Formatting::snakeCaseToCamelCase($key));
$method = 'get' . ucfirst(Formatting::snakeCaseToCamelCase($key)); if (method_exists($target, $method)) {
if (method_exists($target, $method)) { $options['data'] = $target->{$method}();
$options['data'] = $target->{$method}();
}
} }
} }
unset($options['hide']); unset($options['hide']);

View File

@ -66,7 +66,7 @@ class SecurityTest extends GNUsocialTestCase
{ {
self::testLogin('taken_user', 'wrong password'); self::testLogin('taken_user', 'wrong password');
$this->assertResponseIsSuccessful(); $this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('.alert', 'Invalid login credentials'); $this->assertSelectorTextContains('.alert', 'The presented password is invalid.');
$this->assertRouteSame('security_login'); $this->assertRouteSame('security_login');
} }
@ -100,11 +100,8 @@ class SecurityTest extends GNUsocialTestCase
[$client,] = self::testRegister('new_nickname', 'new_email@provider.any', 'foobar'); [$client,] = self::testRegister('new_nickname', 'new_email@provider.any', 'foobar');
$this->assertResponseStatusCodeSame(302); $this->assertResponseStatusCodeSame(302);
$crawler = $client->followRedirect(); $crawler = $client->followRedirect();
$this->assertRouteSame('root'); $this->assertRouteSame('security_login');
$client->followRedirect();
$this->assertResponseIsSuccessful();
$this->assertSelectorNotExists('.alert'); $this->assertSelectorNotExists('.alert');
$this->assertSelectorTextContains('.profile-info-url-nickname', 'new_nickname');
} }
public function testRegisterDifferentPassword() public function testRegisterDifferentPassword()

View File

@ -23,6 +23,7 @@ declare(strict_types = 1);
namespace App\Tests\Core; namespace App\Tests\Core;
use App\Core\ActorLocalRoles;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use App\Entity\Actor; use App\Entity\Actor;
@ -110,7 +111,8 @@ class FormTest extends GNUsocialTestCase
parent::bootKernel(); parent::bootKernel();
$data = ['fullname' => 'Full Name', 'homepage' => 'gnu.org']; $data = ['fullname' => 'Full Name', 'homepage' => 'gnu.org'];
$mock_request = static::createMock(Request::class); $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('handleRequest');
$mock_form->method('isSubmitted')->willReturn(true); $mock_form->method('isSubmitted')->willReturn(true);
$mock_form->method('isValid')->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); $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); 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); 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); $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); static::assertSame($mock_form, $ret);