Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php /* * This file is part of Flarum. * * For detailed copyright and license informa..
Decoded Output download
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Nicknames\Tests\integration;
use Flarum\Extend;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
use PHPUnit\Framework\Attributes\Test;
class RegisterTest extends TestCase
{
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->extension('flarum-nicknames');
$this->extend(
(new Extend\Csrf)->exemptRoute('register')
);
}
#[Test]
public function can_register_with_nickname()
{
$this->setting('flarum-nicknames.set_on_registration', true);
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => '',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(201, $response->getStatusCode(), $response->getBody()->getContents());
/** @var User $user */
$user = User::where('username', 'test')->firstOrFail();
$this->assertEquals(0, $user->is_email_confirmed);
$this->assertEquals('test', $user->username);
$this->assertEquals('[email protected]', $user->email);
}
#[Test]
public function cant_register_with_nickname_if_not_allowed()
{
$this->setting('flarum-nicknames.set_on_registration', false);
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => '',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(403, $response->getStatusCode(), $response->getBody()->getContents());
}
#[Test]
public function cant_register_with_nickname_if_invalid_regex()
{
$this->setting('flarum-nicknames.set_on_registration', true);
$this->setting('flarum-nicknames.regex', '^[A-z]+$');
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => '007',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(422, $response->getStatusCode(), $response->getBody()->getContents());
}
#[Test]
public function can_register_with_nickname_if_valid_regex()
{
$this->setting('flarum-nicknames.set_on_registration', true);
$this->setting('flarum-nicknames.regex', '^[A-z]+$');
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => 'Acme',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(201, $response->getStatusCode(), $response->getBody()->getContents());
}
}
?>
Did this file decode correctly?
Original Code
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Nicknames\Tests\integration;
use Flarum\Extend;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
use PHPUnit\Framework\Attributes\Test;
class RegisterTest extends TestCase
{
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->extension('flarum-nicknames');
$this->extend(
(new Extend\Csrf)->exemptRoute('register')
);
}
#[Test]
public function can_register_with_nickname()
{
$this->setting('flarum-nicknames.set_on_registration', true);
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => '',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(201, $response->getStatusCode(), $response->getBody()->getContents());
/** @var User $user */
$user = User::where('username', 'test')->firstOrFail();
$this->assertEquals(0, $user->is_email_confirmed);
$this->assertEquals('test', $user->username);
$this->assertEquals('[email protected]', $user->email);
}
#[Test]
public function cant_register_with_nickname_if_not_allowed()
{
$this->setting('flarum-nicknames.set_on_registration', false);
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => '',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(403, $response->getStatusCode(), $response->getBody()->getContents());
}
#[Test]
public function cant_register_with_nickname_if_invalid_regex()
{
$this->setting('flarum-nicknames.set_on_registration', true);
$this->setting('flarum-nicknames.regex', '^[A-z]+$');
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => '007',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(422, $response->getStatusCode(), $response->getBody()->getContents());
}
#[Test]
public function can_register_with_nickname_if_valid_regex()
{
$this->setting('flarum-nicknames.set_on_registration', true);
$this->setting('flarum-nicknames.regex', '^[A-z]+$');
$response = $this->send(
$this->request('POST', '/register', [
'json' => [
'nickname' => 'Acme',
'username' => 'test',
'password' => 'too-obscure',
'email' => '[email protected]',
]
])
);
$this->assertEquals(201, $response->getStatusCode(), $response->getBody()->getContents());
}
}
Function Calls
None |
Stats
MD5 | 48144d9804ffcbfea4d6602fd2ce3516 |
Eval Count | 0 |
Decode Time | 99 ms |