From 2bc9cad78ed43eaadfc8844c0b55700e7045cbd7 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 24 Jun 2016 11:28:07 +0200 Subject: Remove useless spaces --- app/config/config.yml | 41 ++++++++++++++++++++++------------------- app/config/config_dev.yml | 13 +++++++------ app/config/config_prod.yml | 10 +++++----- app/config/routing.yml | 4 ++-- app/config/routing_dev.yml | 6 +++--- app/config/security.yml | 16 +++++++++------- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/app/config/config.yml b/app/config/config.yml index 9e2e08a6..f1321d67 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -5,25 +5,27 @@ imports: framework: #esi: ~ - translator: { fallback: "%locale%" } - secret: "%secret%" + translator: + enabled: true + fallback: "%locale%" + secret: "%secret%" router: resource: "%kernel.root_dir%/config/routing.yml" strict_requirements: ~ - form: ~ + form: ~ csrf_protection: ~ - validation: { enable_annotations: true } + validation: + enable_annotations: true templating: engines: ['twig'] - #assets_version: SomeVersionScheme - default_locale: "%locale%" - trusted_hosts: ~ + default_locale: "%locale%" + trusted_hosts: ~ trusted_proxies: ~ session: # handler_id set to null will use default session handler from php.ini - handler_id: session.handler.native_file - save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%" - fragments: ~ + handler_id: session.handler.native_file + save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%" + fragments: ~ http_method_override: true assets: ~ @@ -54,14 +56,14 @@ wallabag_import: # Twig Configuration twig: - debug: "%kernel.debug%" + debug: "%kernel.debug%" strict_variables: "%kernel.debug%" form_themes: - "LexikFormFilterBundle:Form:form_div_layout.html.twig" # Assetic Configuration assetic: - debug: "%kernel.debug%" + debug: "%kernel.debug%" use_controller: false bundles: [ ] #java: /usr/bin/java @@ -75,14 +77,14 @@ assetic: # Doctrine Configuration doctrine: dbal: - driver: "%database_driver%" + driver: "%database_driver%" host: "%database_host%" port: "%database_port%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" - charset: UTF8 - path: "%database_path%" + charset: UTF8 + path: "%database_path%" server_version: 5.6 orm: @@ -108,10 +110,11 @@ doctrine_migrations: # Swiftmailer Configuration swiftmailer: transport: "%mailer_transport%" - host: "%mailer_host%" - username: "%mailer_user%" - password: "%mailer_password%" - spool: { type: memory } + host: "%mailer_host%" + username: "%mailer_user%" + password: "%mailer_password%" + spool: + type: memory fos_rest: param_fetcher_listener: true diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index ec23babb..0fa23dbf 100644 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -5,7 +5,8 @@ framework: router: resource: "%kernel.root_dir%/config/routing_dev.yml" strict_requirements: true - profiler: { only_exceptions: false } + profiler: + only_exceptions: false web_profiler: toolbar: true @@ -14,19 +15,19 @@ web_profiler: monolog: handlers: main: - type: stream - path: "%kernel.logs_dir%/%kernel.environment%.log" - level: debug + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug channels: ['!event'] console: - type: console + type: console bubble: false verbosity_levels: VERBOSITY_VERBOSE: INFO VERBOSITY_VERY_VERBOSE: DEBUG channels: ['!event', '!doctrine'] console_very_verbose: - type: console + type: console bubble: false verbosity_levels: VERBOSITY_VERBOSE: NOTICE diff --git a/app/config/config_prod.yml b/app/config/config_prod.yml index 65b040cc..5a4dd69e 100644 --- a/app/config/config_prod.yml +++ b/app/config/config_prod.yml @@ -14,12 +14,12 @@ imports: monolog: handlers: main: - type: fingers_crossed + type: fingers_crossed action_level: error - handler: nested + handler: nested nested: - type: stream - path: "%kernel.logs_dir%/%kernel.environment%.log" + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug console: - type: console + type: console diff --git a/app/config/routing.yml b/app/config/routing.yml index 6a6aa6ac..40cc7165 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -4,8 +4,8 @@ wallabag_annotation: wallabag_import: resource: "@WallabagImportBundle/Controller/" - type: annotation - prefix: /import + type: annotation + prefix: /import wallabag_api: resource: "@WallabagApiBundle/Resources/config/routing.yml" diff --git a/app/config/routing_dev.yml b/app/config/routing_dev.yml index 404f6a3b..95c1b026 100644 --- a/app/config/routing_dev.yml +++ b/app/config/routing_dev.yml @@ -1,14 +1,14 @@ _wdt: resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml" - prefix: /_wdt + prefix: /_wdt _profiler: resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml" - prefix: /_profiler + prefix: /_profiler _errors: resource: "@TwigBundle/Resources/config/routing/errors.xml" - prefix: /_error + prefix: /_error _main: resource: routing.yml diff --git a/app/config/security.yml b/app/config/security.yml index 0748c06c..e24e03df 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -3,12 +3,14 @@ security: FOS\UserBundle\Model\UserInterface: sha512 role_hierarchy: - ROLE_ADMIN: ROLE_USER + ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ] providers: administrators: - entity: { class: WallabagUserBundle:User, property: username } + entity: + class: WallabagUserBundle:User + property: username fos_userbundle: id: fos_user.user_provider.username @@ -31,7 +33,7 @@ security: anonymous: true login_firewall: - pattern: ^/login$ + pattern: ^/login$ anonymous: ~ secured_area: @@ -40,12 +42,12 @@ security: provider: fos_userbundle csrf_token_generator: security.csrf.token_manager - anonymous: true + anonymous: true remember_me: - secret: "%secret%" + secret: "%secret%" lifetime: 31536000 - path: / - domain: ~ + path: / + domain: ~ logout: path: /logout -- cgit v1.2.3 From fdc90ceb172bb7b237e34a1a01f53018c09f514b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 24 Jun 2016 11:55:45 +0200 Subject: Change the way to login user in tests Instead of using a HTTP request we just login user like FOSUser does. It allows us to mock service in container for functional tests. Also, fix a bad config name in fos_user for firewall And finally, add functional test to PocketImport --- app/config/config.yml | 2 +- .../Controller/SecurityControllerTest.php | 2 +- .../CoreBundle/Controller/TagControllerTest.php | 6 +++ tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 32 ++++++++++++ .../Controller/PocketControllerTest.php | 57 ++++++++++++++++++--- tests/Wallabag/ImportBundle/fixtures/unnamed.png | Bin 0 -> 3688 bytes 6 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 tests/Wallabag/ImportBundle/fixtures/unnamed.png diff --git a/app/config/config.yml b/app/config/config.yml index f1321d67..6a8078cc 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -176,7 +176,7 @@ liip_theme: fos_user: db_driver: orm - firewall_name: main + firewall_name: secured_area user_class: Wallabag\UserBundle\Entity\User registration: confirmation: diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index f503ff4b..03355f5a 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php @@ -36,7 +36,7 @@ class SecurityControllerTest extends WallabagCoreTestCase $em->persist($user); $em->flush(); - $this->logInAs('admin'); + $this->logInAsUsingHttp('admin'); $crawler = $client->request('GET', '/config'); $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index a019d36c..58450e5f 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -39,6 +39,12 @@ class TagControllerTest extends WallabagCoreTestCase $client->submit($form, $data); $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())); # tag already exists and already assigned diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index c69e8330..c0055888 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\CoreBundle; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\BrowserKit\Cookie; abstract class WallabagCoreTestCase extends WebTestCase { @@ -20,7 +21,38 @@ abstract class WallabagCoreTestCase extends WebTestCase $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) + { + $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'); $form = $crawler->filter('button[type=submit]')->form(); diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index 6aaf1b57..e0e61df8 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -22,15 +22,13 @@ class PocketControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $crawler = $client->request('GET', '/import/pocket/auth'); + $client->request('GET', '/import/pocket/auth'); $this->assertEquals(302, $client->getResponse()->getStatusCode()); } public function testImportPocketAuth() { - $this->markTestSkipped('PocketImport: Find a way to properly mock a service.'); - $this->logInAs('admin'); $client = $this->getClient(); @@ -43,9 +41,9 @@ class PocketControllerTest extends WallabagCoreTestCase ->method('getRequestToken') ->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->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location')); @@ -56,10 +54,55 @@ class PocketControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $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->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]); } + + 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]); + } } diff --git a/tests/Wallabag/ImportBundle/fixtures/unnamed.png b/tests/Wallabag/ImportBundle/fixtures/unnamed.png new file mode 100644 index 00000000..e6dd9caa Binary files /dev/null and b/tests/Wallabag/ImportBundle/fixtures/unnamed.png differ -- cgit v1.2.3