framework/tests/integration/api/access_tokens/RemembererTest.php
Alexander Skvortsov d64750b3eb
Rename viewDiscussions => viewForum, viewUserList => searchUsers (#2854)
This naming is clearer as to the intended effect. Changes include:

- A migration to rename all permissions
- Updating the seed migration to use the original naming from the start
- Replacing usage of the old names with new names in code
- Throwing warnings when the old names are used.
2021-05-11 15:15:27 -04:00

98 lines
2.4 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\api\access_tokens;
use Carbon\Carbon;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
class RemembererTest extends TestCase
{
use RetrievesAuthorizedUsers;
/**
* @inheritDoc
*/
protected function setUp(): void
{
parent::setUp();
$this->prepareDatabase([
'access_tokens' => [
['token' => 'a', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session'],
['token' => 'b', 'user_id' => 1, 'last_activity_at' => Carbon::parse('2021-01-01 02:00:00'), 'type' => 'session_remember'],
],
]);
}
/**
* @test
*/
public function non_remember_tokens_cannot_be_used()
{
$this->populateDatabase();
Carbon::setTestNow('2021-01-01 02:30:00');
$response = $this->send(
$this->request('GET', '/api')->withCookieParams([
'flarum_remember' => 'a',
])
);
Carbon::setTestNow();
$data = json_decode($response->getBody(), true);
$this->assertFalse($data['data']['attributes']['canSearchUsers']);
}
/**
* @test
*/
public function expired_tokens_cannot_be_used()
{
$this->populateDatabase();
Carbon::setTestNow('2027-01-01 02:30:00');
$response = $this->send(
$this->request('GET', '/api')->withCookieParams([
'flarum_remember' => 'b',
])
);
Carbon::setTestNow();
$data = json_decode($response->getBody(), true);
$this->assertFalse($data['data']['attributes']['canSearchUsers']);
}
/**
* @test
*/
public function valid_tokens_can_be_used()
{
$this->populateDatabase();
Carbon::setTestNow('2021-01-01 02:30:00');
$response = $this->send(
$this->request('GET', '/api')->withCookieParams([
'flarum_remember' => 'b',
])
);
Carbon::setTestNow();
$data = json_decode($response->getBody(), true);
$this->assertTrue($data['data']['attributes']['canSearchUsers']);
}
}