1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-01 17:38:38 +00:00

Move test files directly under tests/ directory

This commit is contained in:
Yassine Guedidi 2024-02-19 00:45:58 +01:00
parent a37b385c23
commit 24da70e338
117 changed files with 4 additions and 4 deletions

View file

@ -0,0 +1,45 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
class ConfigRestControllerTest extends WallabagApiTestCase
{
public function testGetConfig()
{
$this->client->request('GET', '/api/config.json');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$config = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('id', $config);
$this->assertArrayHasKey('items_per_page', $config);
$this->assertArrayHasKey('language', $config);
$this->assertArrayHasKey('reading_speed', $config);
$this->assertArrayHasKey('action_mark_as_read', $config);
$this->assertArrayHasKey('list_mode', $config);
$this->assertArrayHasKey('display_thumbnails', $config);
$this->assertSame(200.0, $config['reading_speed']);
$this->assertSame('en', $config['language']);
$this->assertCount(7, $config);
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
public function testGetConfigWithoutAuthentication()
{
$client = $this->createUnauthorizedClient();
$client->request('GET', '/api/config.json');
$this->assertSame(401, $client->getResponse()->getStatusCode());
$config = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('error', $config);
$this->assertArrayHasKey('error_description', $config);
$this->assertSame('access_denied', $config['error']);
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
}
}

View file

@ -0,0 +1,145 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
use Doctrine\ORM\EntityManagerInterface;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Entity\Api\Client;
class DeveloperControllerTest extends WallabagCoreTestCase
{
public function testCreateClient()
{
$this->logInAs('admin');
$client = $this->getTestClient();
$em = $client->getContainer()->get(EntityManagerInterface::class);
$nbClients = $em->getRepository(Client::class)->findAll();
$crawler = $client->request('GET', '/developer/client/create');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$form = $crawler->filter('button[id=client_save]')->form();
$data = [
'client[name]' => 'My app',
];
$crawler = $client->submit($form, $data);
$this->assertSame(200, $client->getResponse()->getStatusCode());
$newNbClients = $em->getRepository(Client::class)->findAll();
$this->assertGreaterThan(\count($nbClients), \count($newNbClients));
$this->assertGreaterThan(1, $alert = $crawler->filter('.settings table strong')->extract(['_text']));
$this->assertStringContainsString('My app', $alert[0]);
}
public function testCreateToken()
{
$client = $this->getTestClient();
$apiClient = $this->createApiClientForUser('admin');
$client->request('POST', '/oauth/v2/token', [
'grant_type' => 'password',
'client_id' => $apiClient->getPublicId(),
'client_secret' => $apiClient->getSecret(),
'username' => 'admin',
'password' => 'mypassword',
]);
$this->assertSame(200, $client->getResponse()->getStatusCode());
$data = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('access_token', $data);
$this->assertArrayHasKey('expires_in', $data);
$this->assertArrayHasKey('token_type', $data);
$this->assertArrayHasKey('refresh_token', $data);
}
public function testCreateTokenWithBadClientId()
{
$client = $this->getTestClient();
$client->request('POST', '/oauth/v2/token', [
'grant_type' => 'password',
'client_id' => '$WALLABAG_CLIENT_ID',
'client_secret' => 'secret',
'username' => 'admin',
'password' => 'mypassword',
]);
$this->assertSame(400, $client->getResponse()->getStatusCode());
}
public function testListingClient()
{
$this->logInAs('admin');
$client = $this->getTestClient();
$em = $client->getContainer()->get(EntityManagerInterface::class);
$nbClients = $em->getRepository(Client::class)->findAll();
$crawler = $client->request('GET', '/developer');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertSame(\count($nbClients), $crawler->filter('ul[class=collapsible] li')->count());
}
public function testDeveloperHowto()
{
$this->logInAs('admin');
$client = $this->getTestClient();
$crawler = $client->request('GET', '/developer/howto/first-app');
$this->assertSame(200, $client->getResponse()->getStatusCode());
}
public function testRemoveClient()
{
$client = $this->getTestClient();
$adminApiClient = $this->createApiClientForUser('admin');
$em = $client->getContainer()->get(EntityManagerInterface::class);
// Try to remove an admin's client with a wrong user
$this->logInAs('bob');
$client->request('GET', '/developer');
$this->assertStringContainsString('no_client', $client->getResponse()->getContent());
$this->logInAs('bob');
$client->request('POST', '/developer/client/delete/' . $adminApiClient->getId());
$this->assertSame(403, $client->getResponse()->getStatusCode());
// Try to remove the admin's client with the good user
$this->logInAs('admin');
$crawler = $client->request('GET', '/developer');
$form = $crawler->filter('form[name=delete-client]')->form();
$client->submit($form);
$this->assertSame(302, $client->getResponse()->getStatusCode());
$this->assertNull(
$em->getRepository(Client::class)->find($adminApiClient->getId()),
'The client should have been removed'
);
}
/**
* @param string $username
* @param array $grantTypes
*
* @return Client
*/
private function createApiClientForUser($username, $grantTypes = ['password'])
{
$client = $this->getTestClient();
$em = $client->getContainer()->get(EntityManagerInterface::class);
$userManager = $client->getContainer()->get('fos_user.user_manager.test');
$user = $userManager->findUserBy(['username' => $username]);
$apiClient = new Client($user);
$apiClient->setName('My app');
$apiClient->setAllowedGrantTypes($grantTypes);
$em->persist($apiClient);
$em->flush();
return $apiClient;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,67 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
class SearchRestControllerTest extends WallabagApiTestCase
{
public function testGetSearchWithFullOptions()
{
$this->client->request('GET', '/api/search', [
'page' => 1,
'perPage' => 2,
'term' => 'entry', // 6 results
]);
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertGreaterThanOrEqual(1, \count($content));
$this->assertArrayHasKey('items', $content['_embedded']);
$this->assertGreaterThanOrEqual(0, $content['total']);
$this->assertSame(1, $content['page']);
$this->assertSame(2, $content['limit']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertStringContainsString('term=entry', $content['_links'][$link]['href']);
}
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
public function testGetSearchWithNoLimit()
{
$this->client->request('GET', '/api/search', [
'term' => 'entry',
]);
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertGreaterThanOrEqual(1, \count($content));
$this->assertArrayHasKey('items', $content['_embedded']);
$this->assertGreaterThanOrEqual(0, $content['total']);
$this->assertSame(1, $content['page']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertStringContainsString('term=entry', $content['_links'][$link]['href']);
}
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
}

View file

@ -0,0 +1,225 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
use Doctrine\ORM\EntityManagerInterface;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
class TagRestControllerTest extends WallabagApiTestCase
{
private $otherUserTagLabel = 'bob';
public function testGetUserTags()
{
$this->client->request('GET', '/api/tags.json');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertGreaterThan(0, $content);
$this->assertArrayHasKey('id', $content[0]);
$this->assertArrayHasKey('label', $content[0]);
$this->assertArrayHasKey('nbEntries', $content[0]);
$tagLabels = array_map(function ($i) {
return $i['label'];
}, $content);
$this->assertNotContains($this->otherUserTagLabel, $tagLabels, 'There is a possible tag leak');
}
public function testDeleteUserTag()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = $this->client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
$tagLabel = 'tagtest';
$tag = new Tag();
$tag->setLabel($tagLabel);
$em->persist($tag);
$entry->addTag($tag);
$em->persist($entry);
$em->flush();
$em->clear();
$this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('label', $content);
$this->assertSame($tag->getLabel(), $content['label']);
$this->assertSame($tag->getSlug(), $content['slug']);
$entries = $em->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
$this->assertCount(0, $entries);
$tag = $em->getRepository(Tag::class)->findOneByLabel($tagLabel);
$this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag');
}
public function testDeleteOtherUserTag()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$tag = $em->getRepository(Tag::class)->findOneByLabel($this->otherUserTagLabel);
$this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json');
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
}
public function dataForDeletingTagByLabel()
{
return [
'by_query' => [true],
'by_body' => [false],
];
}
/**
* @dataProvider dataForDeletingTagByLabel
*/
public function testDeleteTagByLabel($useQueryString)
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = $this->client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
$tag = new Tag();
$tag->setLabel('Awesome tag for test');
$em->persist($tag);
$entry->addTag($tag);
$em->persist($entry);
$em->flush();
if ($useQueryString) {
$this->client->request('DELETE', '/api/tag/label.json?tag=' . $tag->getLabel());
} else {
$this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
}
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('label', $content);
$this->assertSame($tag->getLabel(), $content['label']);
$this->assertSame($tag->getSlug(), $content['slug']);
$entries = $this->client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
$this->assertCount(0, $entries);
}
public function testDeleteTagByLabelNotFound()
{
$this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']);
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
}
public function testDeleteTagByLabelOtherUser()
{
$this->client->request('DELETE', '/api/tag/label.json', ['tag' => $this->otherUserTagLabel]);
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
}
/**
* @dataProvider dataForDeletingTagByLabel
*/
public function testDeleteTagsByLabel($useQueryString)
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = $this->client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
$tag = new Tag();
$tag->setLabel('Awesome tag for tagsLabel');
$em->persist($tag);
$tag2 = new Tag();
$tag2->setLabel('Awesome tag for tagsLabel 2');
$em->persist($tag2);
$entry->addTag($tag);
$entry->addTag($tag2);
$em->persist($entry);
$em->flush();
if ($useQueryString) {
$this->client->request('DELETE', '/api/tags/label.json?tags=' . $tag->getLabel() . ',' . $tag2->getLabel());
} else {
$this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel() . ',' . $tag2->getLabel()]);
}
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertCount(2, $content);
$this->assertArrayHasKey('label', $content[0]);
$this->assertSame($tag->getLabel(), $content[0]['label']);
$this->assertSame($tag->getSlug(), $content[0]['slug']);
$this->assertArrayHasKey('label', $content[1]);
$this->assertSame($tag2->getLabel(), $content[1]['label']);
$this->assertSame($tag2->getSlug(), $content[1]['slug']);
$entries = $this->client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
$this->assertCount(0, $entries);
$entries = $this->client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag2->getId());
$this->assertCount(0, $entries);
}
public function testDeleteTagsByLabelNotFound()
{
$this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']);
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
}
public function testDeleteTagsByLabelOtherUser()
{
$this->client->request('DELETE', '/api/tags/label.json', ['tags' => $this->otherUserTagLabel]);
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
class TaggingRuleRestControllerTest extends WallabagApiTestCase
{
public function testExportEntry()
{
$this->client->request('GET', '/api/taggingrule/export');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
}

View file

@ -0,0 +1,185 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
use Craue\ConfigBundle\Util\Config;
class UserRestControllerTest extends WallabagApiTestCase
{
public function testGetUser()
{
$this->client->request('GET', '/api/user.json');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('id', $content);
$this->assertArrayHasKey('email', $content);
$this->assertArrayHasKey('name', $content);
$this->assertArrayHasKey('username', $content);
$this->assertArrayHasKey('created_at', $content);
$this->assertArrayHasKey('updated_at', $content);
$this->assertSame('bigboss@wallabag.org', $content['email']);
$this->assertSame('Big boss', $content['name']);
$this->assertSame('admin', $content['username']);
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
public function testGetUserWithoutAuthentication()
{
$client = $this->createUnauthorizedClient();
$client->request('GET', '/api/user.json');
$this->assertSame(401, $client->getResponse()->getStatusCode());
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('error', $content);
$this->assertArrayHasKey('error_description', $content);
$this->assertSame('access_denied', $content['error']);
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
}
public function testCreateNewUser()
{
$this->client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$this->client->request('PUT', '/api/user.json', [
'username' => 'google',
'password' => 'googlegoogle',
'email' => 'wallabag@google.com',
]);
$this->assertSame(201, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('id', $content);
$this->assertArrayHasKey('email', $content);
$this->assertArrayHasKey('username', $content);
$this->assertArrayHasKey('created_at', $content);
$this->assertArrayHasKey('updated_at', $content);
$this->assertArrayHasKey('default_client', $content);
$this->assertSame('wallabag@google.com', $content['email']);
$this->assertSame('google', $content['username']);
$this->assertArrayHasKey('client_secret', $content['default_client']);
$this->assertArrayHasKey('client_id', $content['default_client']);
$this->assertSame('Default client', $content['default_client']['name']);
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
$this->client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWithoutAuthentication()
{
// create a new client instead of using $this->client to be sure client isn't authenticated
$client = $this->createUnauthorizedClient();
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$client->request('PUT', '/api/user.json', [
'username' => 'google',
'password' => 'googlegoogle',
'email' => 'wallabag@google.com',
'client_name' => 'My client name !!',
]);
$this->assertSame(201, $client->getResponse()->getStatusCode());
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('id', $content);
$this->assertArrayHasKey('email', $content);
$this->assertArrayHasKey('username', $content);
$this->assertArrayHasKey('created_at', $content);
$this->assertArrayHasKey('updated_at', $content);
$this->assertArrayHasKey('default_client', $content);
$this->assertSame('wallabag@google.com', $content['email']);
$this->assertSame('google', $content['username']);
$this->assertArrayHasKey('client_secret', $content['default_client']);
$this->assertArrayHasKey('client_id', $content['default_client']);
$this->assertSame('My client name !!', $content['default_client']['name']);
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWithExistingEmail()
{
$client = $this->createUnauthorizedClient();
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$client->request('PUT', '/api/user.json', [
'username' => 'admin',
'password' => 'googlegoogle',
'email' => 'bigboss@wallabag.org',
]);
$this->assertSame(400, $client->getResponse()->getStatusCode());
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('error', $content);
$this->assertArrayHasKey('username', $content['error']);
$this->assertArrayHasKey('email', $content['error']);
// $this->assertEquals('fos_user.username.already_used', $content['error']['username'][0]);
// $this->assertEquals('fos_user.email.already_used', $content['error']['email'][0]);
// This shouldn't be translated ...
$this->assertSame('This value is already used.', $content['error']['username'][0]);
$this->assertSame('This value is already used.', $content['error']['email'][0]);
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWithTooShortPassword()
{
$client = $this->createUnauthorizedClient();
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$client->request('PUT', '/api/user.json', [
'username' => 'facebook',
'password' => 'face',
'email' => 'facebook@wallabag.org',
]);
$this->assertSame(400, $client->getResponse()->getStatusCode());
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('error', $content);
$this->assertArrayHasKey('password', $content['error']);
$this->assertSame('validator.password_too_short', $content['error']['password'][0]);
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWhenRegistrationIsDisabled()
{
$client = $this->createUnauthorizedClient();
$client->request('PUT', '/api/user.json', [
'username' => 'facebook',
'password' => 'face',
'email' => 'facebook@wallabag.org',
]);
$this->assertSame(403, $client->getResponse()->getStatusCode());
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('error', $content);
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
}
}

View file

@ -0,0 +1,77 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManager;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Wallabag\CoreBundle\Entity\User;
abstract class WallabagApiTestCase extends WebTestCase
{
/**
* @var KernelBrowser
*/
protected $client;
/**
* @var UserInterface
*/
protected $user;
protected function setUp(): void
{
parent::setUp();
$this->client = $this->createAuthorizedClient();
}
/**
* @return KernelBrowser
*/
protected function createUnauthorizedClient()
{
static::ensureKernelShutdown();
return static::createClient();
}
/**
* @return KernelBrowser
*/
protected function createAuthorizedClient()
{
$client = $this->createUnauthorizedClient();
$container = $client->getContainer();
/** @var UserManager $userManager */
$userManager = $container->get('fos_user.user_manager.test');
$firewallName = $container->getParameter('fos_user.firewall_name');
$this->user = $userManager->findUserBy(['username' => 'admin']);
$client->loginUser($this->user, $firewallName);
return $client;
}
/**
* Return the ID for the user admin.
* Used because on heavy testing we don't want to re-create the database on each run.
* Which means "admin" user won't have id 1 all the time.
*
* @param string $username
*
* @return int
*/
protected function getUserId($username = 'admin')
{
return $this->client
->getContainer()
->get(EntityManagerInterface::class)
->getRepository(User::class)
->findOneByUserName($username)
->getId();
}
}

View file

@ -0,0 +1,66 @@
<?php
namespace Tests\Wallabag\CoreBundle\Controller\Api;
use Craue\ConfigBundle\Util\Config;
class WallabagRestControllerTest extends WallabagApiTestCase
{
public function testGetVersion()
{
// create a new client instead of using $this->client to be sure client isn't authenticated
$client = $this->createUnauthorizedClient();
$client->request('GET', '/api/version');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content);
}
public function testGetInfo()
{
// create a new client instead of using $this->client to be sure client isn't authenticated
$client = $this->createUnauthorizedClient();
$client->request('GET', '/api/info');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('appname', $content);
$this->assertArrayHasKey('version', $content);
$this->assertArrayHasKey('allowed_registration', $content);
$this->assertSame('wallabag', $content['appname']);
}
public function testAllowedRegistration()
{
// create a new client instead of using $this->client to be sure client isn't authenticated
$client = $this->createUnauthorizedClient();
if (!$client->getContainer()->getParameter('fosuser_registration')) {
$this->markTestSkipped('fosuser_registration is not enabled.');
return;
}
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$client->request('GET', '/api/info');
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertTrue($content['allowed_registration']);
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
$client->request('GET', '/api/info');
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertFalse($content['allowed_registration']);
}
}