framework/tests/integration/forum/IndexTest.php
Alexander Skvortsov 104a31ba30
Run API Client requests through middleware (#2783)
- Add integration tests for login and registration
- Use URL instead of controller
- Add fluent API
- Allow setting parent request, user, session
2021-05-10 17:41:38 -04:00

73 lines
1.7 KiB
PHP

<?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\Tests\integration\forum;
use Flarum\Extend;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
class IndexTest extends TestCase
{
use RetrievesAuthorizedUsers;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->extend(
(new Extend\Csrf)->exemptRoute('login')
);
$this->prepareDatabase([
'users' => [
$this->normalUser()
]
]);
}
/**
* @test
*/
public function guest_not_serialized_by_current_user_serializer()
{
$response = $this->send(
$this->request('GET', '/')
);
$this->assertEquals(200, $response->getStatusCode());
$this->assertStringNotContainsString('preferences', $response->getBody()->getContents());
}
/**
* @test
*/
public function user_serialized_by_current_user_serializer()
{
$login = $this->send(
$this->request('POST', '/login', [
'json' => [
'identification' => 'normal',
'password' => 'too-obscure'
]
])
);
$response = $this->send(
$this->request('GET', '/', [
'cookiesFrom' => $login
])
);
$this->assertEquals(200, $response->getStatusCode());
$this->assertStringContainsString('preferences', $response->getBody()->getContents());
}
}