mirror of
https://github.com/wallabag/wallabag.git
synced 2025-02-23 14:06:18 +00:00
Merge pull request #2172 from wallabag/more-tests
Change the way to login user in tests
This commit is contained in:
commit
9f8c43e222
11 changed files with 138 additions and 51 deletions
|
@ -5,25 +5,27 @@ imports:
|
||||||
|
|
||||||
framework:
|
framework:
|
||||||
#esi: ~
|
#esi: ~
|
||||||
translator: { fallback: "%locale%" }
|
translator:
|
||||||
secret: "%secret%"
|
enabled: true
|
||||||
|
fallback: "%locale%"
|
||||||
|
secret: "%secret%"
|
||||||
router:
|
router:
|
||||||
resource: "%kernel.root_dir%/config/routing.yml"
|
resource: "%kernel.root_dir%/config/routing.yml"
|
||||||
strict_requirements: ~
|
strict_requirements: ~
|
||||||
form: ~
|
form: ~
|
||||||
csrf_protection: ~
|
csrf_protection: ~
|
||||||
validation: { enable_annotations: true }
|
validation:
|
||||||
|
enable_annotations: true
|
||||||
templating:
|
templating:
|
||||||
engines: ['twig']
|
engines: ['twig']
|
||||||
#assets_version: SomeVersionScheme
|
default_locale: "%locale%"
|
||||||
default_locale: "%locale%"
|
trusted_hosts: ~
|
||||||
trusted_hosts: ~
|
|
||||||
trusted_proxies: ~
|
trusted_proxies: ~
|
||||||
session:
|
session:
|
||||||
# handler_id set to null will use default session handler from php.ini
|
# handler_id set to null will use default session handler from php.ini
|
||||||
handler_id: session.handler.native_file
|
handler_id: session.handler.native_file
|
||||||
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
|
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
|
||||||
fragments: ~
|
fragments: ~
|
||||||
http_method_override: true
|
http_method_override: true
|
||||||
assets: ~
|
assets: ~
|
||||||
|
|
||||||
|
@ -54,14 +56,14 @@ wallabag_import:
|
||||||
|
|
||||||
# Twig Configuration
|
# Twig Configuration
|
||||||
twig:
|
twig:
|
||||||
debug: "%kernel.debug%"
|
debug: "%kernel.debug%"
|
||||||
strict_variables: "%kernel.debug%"
|
strict_variables: "%kernel.debug%"
|
||||||
form_themes:
|
form_themes:
|
||||||
- "LexikFormFilterBundle:Form:form_div_layout.html.twig"
|
- "LexikFormFilterBundle:Form:form_div_layout.html.twig"
|
||||||
|
|
||||||
# Assetic Configuration
|
# Assetic Configuration
|
||||||
assetic:
|
assetic:
|
||||||
debug: "%kernel.debug%"
|
debug: "%kernel.debug%"
|
||||||
use_controller: false
|
use_controller: false
|
||||||
bundles: [ ]
|
bundles: [ ]
|
||||||
#java: /usr/bin/java
|
#java: /usr/bin/java
|
||||||
|
@ -75,14 +77,14 @@ assetic:
|
||||||
# Doctrine Configuration
|
# Doctrine Configuration
|
||||||
doctrine:
|
doctrine:
|
||||||
dbal:
|
dbal:
|
||||||
driver: "%database_driver%"
|
driver: "%database_driver%"
|
||||||
host: "%database_host%"
|
host: "%database_host%"
|
||||||
port: "%database_port%"
|
port: "%database_port%"
|
||||||
dbname: "%database_name%"
|
dbname: "%database_name%"
|
||||||
user: "%database_user%"
|
user: "%database_user%"
|
||||||
password: "%database_password%"
|
password: "%database_password%"
|
||||||
charset: UTF8
|
charset: UTF8
|
||||||
path: "%database_path%"
|
path: "%database_path%"
|
||||||
server_version: 5.6
|
server_version: 5.6
|
||||||
|
|
||||||
orm:
|
orm:
|
||||||
|
@ -108,10 +110,11 @@ doctrine_migrations:
|
||||||
# Swiftmailer Configuration
|
# Swiftmailer Configuration
|
||||||
swiftmailer:
|
swiftmailer:
|
||||||
transport: "%mailer_transport%"
|
transport: "%mailer_transport%"
|
||||||
host: "%mailer_host%"
|
host: "%mailer_host%"
|
||||||
username: "%mailer_user%"
|
username: "%mailer_user%"
|
||||||
password: "%mailer_password%"
|
password: "%mailer_password%"
|
||||||
spool: { type: memory }
|
spool:
|
||||||
|
type: memory
|
||||||
|
|
||||||
fos_rest:
|
fos_rest:
|
||||||
param_fetcher_listener: true
|
param_fetcher_listener: true
|
||||||
|
@ -173,7 +176,7 @@ liip_theme:
|
||||||
|
|
||||||
fos_user:
|
fos_user:
|
||||||
db_driver: orm
|
db_driver: orm
|
||||||
firewall_name: main
|
firewall_name: secured_area
|
||||||
user_class: Wallabag\UserBundle\Entity\User
|
user_class: Wallabag\UserBundle\Entity\User
|
||||||
registration:
|
registration:
|
||||||
confirmation:
|
confirmation:
|
||||||
|
|
|
@ -5,7 +5,8 @@ framework:
|
||||||
router:
|
router:
|
||||||
resource: "%kernel.root_dir%/config/routing_dev.yml"
|
resource: "%kernel.root_dir%/config/routing_dev.yml"
|
||||||
strict_requirements: true
|
strict_requirements: true
|
||||||
profiler: { only_exceptions: false }
|
profiler:
|
||||||
|
only_exceptions: false
|
||||||
|
|
||||||
web_profiler:
|
web_profiler:
|
||||||
toolbar: true
|
toolbar: true
|
||||||
|
@ -14,19 +15,19 @@ web_profiler:
|
||||||
monolog:
|
monolog:
|
||||||
handlers:
|
handlers:
|
||||||
main:
|
main:
|
||||||
type: stream
|
type: stream
|
||||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||||
level: debug
|
level: debug
|
||||||
channels: ['!event']
|
channels: ['!event']
|
||||||
console:
|
console:
|
||||||
type: console
|
type: console
|
||||||
bubble: false
|
bubble: false
|
||||||
verbosity_levels:
|
verbosity_levels:
|
||||||
VERBOSITY_VERBOSE: INFO
|
VERBOSITY_VERBOSE: INFO
|
||||||
VERBOSITY_VERY_VERBOSE: DEBUG
|
VERBOSITY_VERY_VERBOSE: DEBUG
|
||||||
channels: ['!event', '!doctrine']
|
channels: ['!event', '!doctrine']
|
||||||
console_very_verbose:
|
console_very_verbose:
|
||||||
type: console
|
type: console
|
||||||
bubble: false
|
bubble: false
|
||||||
verbosity_levels:
|
verbosity_levels:
|
||||||
VERBOSITY_VERBOSE: NOTICE
|
VERBOSITY_VERBOSE: NOTICE
|
||||||
|
|
|
@ -14,12 +14,12 @@ imports:
|
||||||
monolog:
|
monolog:
|
||||||
handlers:
|
handlers:
|
||||||
main:
|
main:
|
||||||
type: fingers_crossed
|
type: fingers_crossed
|
||||||
action_level: error
|
action_level: error
|
||||||
handler: nested
|
handler: nested
|
||||||
nested:
|
nested:
|
||||||
type: stream
|
type: stream
|
||||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||||
level: debug
|
level: debug
|
||||||
console:
|
console:
|
||||||
type: console
|
type: console
|
||||||
|
|
|
@ -4,8 +4,8 @@ wallabag_annotation:
|
||||||
|
|
||||||
wallabag_import:
|
wallabag_import:
|
||||||
resource: "@WallabagImportBundle/Controller/"
|
resource: "@WallabagImportBundle/Controller/"
|
||||||
type: annotation
|
type: annotation
|
||||||
prefix: /import
|
prefix: /import
|
||||||
|
|
||||||
wallabag_api:
|
wallabag_api:
|
||||||
resource: "@WallabagApiBundle/Resources/config/routing.yml"
|
resource: "@WallabagApiBundle/Resources/config/routing.yml"
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
_wdt:
|
_wdt:
|
||||||
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
|
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
|
||||||
prefix: /_wdt
|
prefix: /_wdt
|
||||||
|
|
||||||
_profiler:
|
_profiler:
|
||||||
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
|
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
|
||||||
prefix: /_profiler
|
prefix: /_profiler
|
||||||
|
|
||||||
_errors:
|
_errors:
|
||||||
resource: "@TwigBundle/Resources/config/routing/errors.xml"
|
resource: "@TwigBundle/Resources/config/routing/errors.xml"
|
||||||
prefix: /_error
|
prefix: /_error
|
||||||
|
|
||||||
_main:
|
_main:
|
||||||
resource: routing.yml
|
resource: routing.yml
|
||||||
|
|
|
@ -3,12 +3,14 @@ security:
|
||||||
FOS\UserBundle\Model\UserInterface: sha512
|
FOS\UserBundle\Model\UserInterface: sha512
|
||||||
|
|
||||||
role_hierarchy:
|
role_hierarchy:
|
||||||
ROLE_ADMIN: ROLE_USER
|
ROLE_ADMIN: ROLE_USER
|
||||||
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
|
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
|
||||||
|
|
||||||
providers:
|
providers:
|
||||||
administrators:
|
administrators:
|
||||||
entity: { class: WallabagUserBundle:User, property: username }
|
entity:
|
||||||
|
class: WallabagUserBundle:User
|
||||||
|
property: username
|
||||||
fos_userbundle:
|
fos_userbundle:
|
||||||
id: fos_user.user_provider.username
|
id: fos_user.user_provider.username
|
||||||
|
|
||||||
|
@ -31,7 +33,7 @@ security:
|
||||||
anonymous: true
|
anonymous: true
|
||||||
|
|
||||||
login_firewall:
|
login_firewall:
|
||||||
pattern: ^/login$
|
pattern: ^/login$
|
||||||
anonymous: ~
|
anonymous: ~
|
||||||
|
|
||||||
secured_area:
|
secured_area:
|
||||||
|
@ -40,12 +42,12 @@ security:
|
||||||
provider: fos_userbundle
|
provider: fos_userbundle
|
||||||
csrf_token_generator: security.csrf.token_manager
|
csrf_token_generator: security.csrf.token_manager
|
||||||
|
|
||||||
anonymous: true
|
anonymous: true
|
||||||
remember_me:
|
remember_me:
|
||||||
secret: "%secret%"
|
secret: "%secret%"
|
||||||
lifetime: 31536000
|
lifetime: 31536000
|
||||||
path: /
|
path: /
|
||||||
domain: ~
|
domain: ~
|
||||||
|
|
||||||
logout:
|
logout:
|
||||||
path: /logout
|
path: /logout
|
||||||
|
|
|
@ -36,7 +36,7 @@ class SecurityControllerTest extends WallabagCoreTestCase
|
||||||
$em->persist($user);
|
$em->persist($user);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$this->logInAs('admin');
|
$this->logInAsUsingHttp('admin');
|
||||||
$crawler = $client->request('GET', '/config');
|
$crawler = $client->request('GET', '/config');
|
||||||
$this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
|
$this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,12 @@ class TagControllerTest extends WallabagCoreTestCase
|
||||||
$client->submit($form, $data);
|
$client->submit($form, $data);
|
||||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||||
|
|
||||||
|
// be sure to reload the entry
|
||||||
|
$entry = $client->getContainer()
|
||||||
|
->get('doctrine.orm.entity_manager')
|
||||||
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
|
->findOneByUsernameAndNotArchived('admin');
|
||||||
|
|
||||||
$this->assertEquals(1, count($entry->getTags()));
|
$this->assertEquals(1, count($entry->getTags()));
|
||||||
|
|
||||||
# tag already exists and already assigned
|
# tag already exists and already assigned
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Tests\Wallabag\CoreBundle;
|
namespace Tests\Wallabag\CoreBundle;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\BrowserKit\Cookie;
|
||||||
|
|
||||||
abstract class WallabagCoreTestCase extends WebTestCase
|
abstract class WallabagCoreTestCase extends WebTestCase
|
||||||
{
|
{
|
||||||
|
@ -20,7 +21,38 @@ abstract class WallabagCoreTestCase extends WebTestCase
|
||||||
$this->client = static::createClient();
|
$this->client = static::createClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Login a user without making a HTTP request.
|
||||||
|
* If we make a HTTP request we lose ability to mock service in the container.
|
||||||
|
*
|
||||||
|
* @param string $username User to log in
|
||||||
|
*/
|
||||||
public function logInAs($username)
|
public function logInAs($username)
|
||||||
|
{
|
||||||
|
$container = $this->client->getContainer();
|
||||||
|
$session = $container->get('session');
|
||||||
|
|
||||||
|
$userManager = $container->get('fos_user.user_manager');
|
||||||
|
$loginManager = $container->get('fos_user.security.login_manager');
|
||||||
|
$firewallName = $container->getParameter('fos_user.firewall_name');
|
||||||
|
|
||||||
|
$user = $userManager->findUserBy(array('username' => $username));
|
||||||
|
$loginManager->loginUser($firewallName, $user);
|
||||||
|
|
||||||
|
$session->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken()));
|
||||||
|
$session->save();
|
||||||
|
|
||||||
|
$cookie = new Cookie($session->getName(), $session->getId());
|
||||||
|
$this->client->getCookieJar()->set($cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instead of `logInAs` this method use a HTTP request to log in the user.
|
||||||
|
* Could be better for some tests.
|
||||||
|
*
|
||||||
|
* @param string $username User to log in
|
||||||
|
*/
|
||||||
|
public function logInAsUsingHttp($username)
|
||||||
{
|
{
|
||||||
$crawler = $this->client->request('GET', '/login');
|
$crawler = $this->client->request('GET', '/login');
|
||||||
$form = $crawler->filter('button[type=submit]')->form();
|
$form = $crawler->filter('button[type=submit]')->form();
|
||||||
|
|
|
@ -22,15 +22,13 @@ class PocketControllerTest extends WallabagCoreTestCase
|
||||||
$this->logInAs('admin');
|
$this->logInAs('admin');
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
|
|
||||||
$crawler = $client->request('GET', '/import/pocket/auth');
|
$client->request('GET', '/import/pocket/auth');
|
||||||
|
|
||||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testImportPocketAuth()
|
public function testImportPocketAuth()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('PocketImport: Find a way to properly mock a service.');
|
|
||||||
|
|
||||||
$this->logInAs('admin');
|
$this->logInAs('admin');
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
|
|
||||||
|
@ -43,9 +41,9 @@ class PocketControllerTest extends WallabagCoreTestCase
|
||||||
->method('getRequestToken')
|
->method('getRequestToken')
|
||||||
->willReturn('token');
|
->willReturn('token');
|
||||||
|
|
||||||
$client->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
|
static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
|
||||||
|
|
||||||
$crawler = $client->request('GET', '/import/pocket/auth');
|
$client->request('GET', '/import/pocket/auth');
|
||||||
|
|
||||||
$this->assertEquals(301, $client->getResponse()->getStatusCode());
|
$this->assertEquals(301, $client->getResponse()->getStatusCode());
|
||||||
$this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location'));
|
$this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location'));
|
||||||
|
@ -56,10 +54,55 @@ class PocketControllerTest extends WallabagCoreTestCase
|
||||||
$this->logInAs('admin');
|
$this->logInAs('admin');
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
|
|
||||||
$crawler = $client->request('GET', '/import/pocket/callback');
|
$pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$pocketImport
|
||||||
|
->expects($this->once())
|
||||||
|
->method('authorize')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
|
||||||
|
|
||||||
|
$client->request('GET', '/import/pocket/callback');
|
||||||
|
|
||||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||||
$this->assertContains('import/pocket', $client->getResponse()->headers->get('location'));
|
$this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage');
|
||||||
$this->assertEquals('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
|
$this->assertEquals('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testImportPocketCallback()
|
||||||
|
{
|
||||||
|
$this->logInAs('admin');
|
||||||
|
$client = $this->getClient();
|
||||||
|
|
||||||
|
$pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$pocketImport
|
||||||
|
->expects($this->once())
|
||||||
|
->method('authorize')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$pocketImport
|
||||||
|
->expects($this->once())
|
||||||
|
->method('setMarkAsRead')
|
||||||
|
->with(false)
|
||||||
|
->willReturn($pocketImport);
|
||||||
|
|
||||||
|
$pocketImport
|
||||||
|
->expects($this->once())
|
||||||
|
->method('import')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
|
||||||
|
|
||||||
|
$client->request('GET', '/import/pocket/callback');
|
||||||
|
|
||||||
|
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||||
|
$this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage');
|
||||||
|
$this->assertEquals('flashes.import.notice.summary', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
tests/Wallabag/ImportBundle/fixtures/unnamed.png
Normal file
BIN
tests/Wallabag/ImportBundle/fixtures/unnamed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
Loading…
Reference in a new issue