2018-05-16 15:25:48 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2019-01-02 05:17:09 +08:00
|
|
|
namespace Flarum\Tests\integration\api\Controller;
|
2018-05-16 15:25:48 +08:00
|
|
|
|
2018-06-06 13:10:29 +08:00
|
|
|
use Flarum\Api\Controller\CreateTokenController;
|
2018-05-16 15:25:48 +08:00
|
|
|
use Flarum\Http\AccessToken;
|
|
|
|
|
2018-06-06 13:10:29 +08:00
|
|
|
class CreateTokenControllerTest extends ApiControllerTestCase
|
2018-05-16 15:25:48 +08:00
|
|
|
{
|
2018-06-06 13:10:29 +08:00
|
|
|
protected $controller = CreateTokenController::class;
|
2018-05-16 15:25:48 +08:00
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->prepareDatabase([
|
|
|
|
'users' => [
|
|
|
|
$this->normalUser(),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-05-16 15:25:48 +08:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function user_generates_token()
|
|
|
|
{
|
|
|
|
$response = $this->call($this->controller, null, [], [
|
2019-01-31 04:15:27 +08:00
|
|
|
'identification' => 'normal',
|
|
|
|
'password' => 'too-obscure'
|
2018-05-16 15:25:48 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$data = json_decode($response->getBody()->getContents(), true);
|
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
$this->assertEquals(2, $data['userId']);
|
2018-05-16 15:25:48 +08:00
|
|
|
|
|
|
|
$token = $data['token'];
|
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
$this->assertEquals(2, AccessToken::findOrFail($token)->user_id);
|
2018-05-16 15:25:48 +08:00
|
|
|
}
|
|
|
|
}
|