aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-31 11:24:46 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commit7019c7cf6c6af39c0f458769e20c3f9306477943 (patch)
tree12acceaa458cdf6d24367eba85f690265acddcdb /src
parentb1d05721cf37ab94ec1a6837fe79cf19474dd0ff (diff)
downloadwallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.tar.gz
wallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.tar.zst
wallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.zip
Add tagged services for import
- list services in /import - add url to import service - ImportBundle routing are now prefixed by /import - optimize flush in each import (flushing each 20 contents) - improve design of each import - add more tests
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Wallabag/CoreBundle/Resources/views/themes/material/public/css/main.css6
-rw-r--r--src/Wallabag/ImportBundle/Controller/ImportController.php6
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php10
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php21
-rw-r--r--src/Wallabag/ImportBundle/Form/Type/UploadImportType.php7
-rw-r--r--src/Wallabag/ImportBundle/Import/ImportChain.php34
-rw-r--r--src/Wallabag/ImportBundle/Import/ImportCompilerPass.php33
-rw-r--r--src/Wallabag/ImportBundle/Import/ImportInterface.php7
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php18
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php26
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/services.yml7
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig12
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig10
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig16
-rw-r--r--src/Wallabag/ImportBundle/Tests/Controller/ImportControllerTest.php29
-rw-r--r--src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php42
-rw-r--r--src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php69
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php21
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php47
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php3
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php3
-rw-r--r--src/Wallabag/ImportBundle/Tests/fixtures/test.html0
-rw-r--r--src/Wallabag/ImportBundle/Tests/fixtures/test.txt0
-rw-r--r--src/Wallabag/ImportBundle/WallabagImportBundle.php8
24 files changed, 393 insertions, 42 deletions
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/public/css/main.css b/src/Wallabag/CoreBundle/Resources/views/themes/material/public/css/main.css
index d6031530..516f6fdf 100755
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/public/css/main.css
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/public/css/main.css
@@ -497,4 +497,8 @@ footer [class^="icon-"]:hover, footer [class*=" icon-"]:hover {
497/* force height on non-input field in the settings page */ 497/* force height on non-input field in the settings page */
498div.settings div.input-field div, div.settings div.input-field ul { 498div.settings div.input-field div, div.settings div.input-field ul {
499 margin-top: 40px; 499 margin-top: 40px;
500} \ No newline at end of file 500}
501/* but avoid to kill all file input */
502div.settings div.file-field div {
503 margin-top: inherit;
504}
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php
index 2a0d6ab5..c1486e38 100644
--- a/src/Wallabag/ImportBundle/Controller/ImportController.php
+++ b/src/Wallabag/ImportBundle/Controller/ImportController.php
@@ -8,10 +8,12 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8class ImportController extends Controller 8class ImportController extends Controller
9{ 9{
10 /** 10 /**
11 * @Route("/import", name="import") 11 * @Route("/", name="import")
12 */ 12 */
13 public function importAction() 13 public function importAction()
14 { 14 {
15 return $this->render('WallabagImportBundle:Import:index.html.twig', []); 15 return $this->render('WallabagImportBundle:Import:index.html.twig', [
16 'imports' => $this->get('wallabag_import.chain')->getAll(),
17 ]);
16 } 18 }
17} 19}
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php
index ebcee099..a0853383 100644
--- a/src/Wallabag/ImportBundle/Controller/PocketController.php
+++ b/src/Wallabag/ImportBundle/Controller/PocketController.php
@@ -8,15 +8,17 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8class PocketController extends Controller 8class PocketController extends Controller
9{ 9{
10 /** 10 /**
11 * @Route("/import/pocket", name="import_pocket") 11 * @Route("/pocket", name="import_pocket")
12 */ 12 */
13 public function indexAction() 13 public function indexAction()
14 { 14 {
15 return $this->render('WallabagImportBundle:Pocket:index.html.twig', []); 15 return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
16 'import' => $this->get('wallabag_import.pocket.import'),
17 ]);
16 } 18 }
17 19
18 /** 20 /**
19 * @Route("/import/pocket/auth", name="import_pocket_auth") 21 * @Route("/pocket/auth", name="import_pocket_auth")
20 */ 22 */
21 public function authAction() 23 public function authAction()
22 { 24 {
@@ -32,7 +34,7 @@ class PocketController extends Controller
32 } 34 }
33 35
34 /** 36 /**
35 * @Route("/import/pocket/callback", name="import_pocket_callback") 37 * @Route("/pocket/callback", name="import_pocket_callback")
36 */ 38 */
37 public function callbackAction() 39 public function callbackAction()
38 { 40 {
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
index de200184..e50a6c35 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
@@ -10,20 +10,20 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType;
10class WallabagV1Controller extends Controller 10class WallabagV1Controller extends Controller
11{ 11{
12 /** 12 /**
13 * @Route("/import/wallabag-v1", name="import_wallabag_v1") 13 * @Route("/wallabag-v1", name="import_wallabag_v1")
14 */ 14 */
15 public function indexAction(Request $request) 15 public function indexAction(Request $request)
16 { 16 {
17 $importForm = $this->createForm(new UploadImportType()); 17 $form = $this->createForm(new UploadImportType());
18 $importForm->handleRequest($request); 18 $form->handleRequest($request);
19 $user = $this->getUser();
20 19
21 if ($importForm->isValid()) { 20 $wallabag = $this->get('wallabag_import.wallabag_v1.import');
22 $file = $importForm->get('file')->getData(); 21
23 $name = $user->getId().'.json'; 22 if ($form->isValid()) {
23 $file = $form->get('file')->getData();
24 $name = $this->getUser()->getId().'.json';
24 25
25 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 26 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
26 $wallabag = $this->get('wallabag_import.wallabag_v1.import');
27 $res = $wallabag 27 $res = $wallabag
28 ->setUser($this->getUser()) 28 ->setUser($this->getUser())
29 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 29 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
@@ -34,7 +34,7 @@ class WallabagV1Controller extends Controller
34 $summary = $wallabag->getSummary(); 34 $summary = $wallabag->getSummary();
35 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; 35 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
36 36
37 @unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 37 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
38 } 38 }
39 39
40 $this->get('session')->getFlashBag()->add( 40 $this->get('session')->getFlashBag()->add(
@@ -52,7 +52,8 @@ class WallabagV1Controller extends Controller
52 } 52 }
53 53
54 return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [ 54 return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [
55 'form' => $importForm->createView(), 55 'form' => $form->createView(),
56 'import' => $wallabag,
56 ]); 57 ]);
57 } 58 }
58} 59}
diff --git a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
index 5d894318..415890f3 100644
--- a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
+++ b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
@@ -15,13 +15,6 @@ class UploadImportType extends AbstractType
15 ; 15 ;
16 } 16 }
17 17
18 public function getDefaultOptions(array $options)
19 {
20 return array(
21 'csrf_protection' => false,
22 );
23 }
24
25 public function getName() 18 public function getName()
26 { 19 {
27 return 'upload_import_file'; 20 return 'upload_import_file';
diff --git a/src/Wallabag/ImportBundle/Import/ImportChain.php b/src/Wallabag/ImportBundle/Import/ImportChain.php
new file mode 100644
index 00000000..9dd77956
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Import/ImportChain.php
@@ -0,0 +1,34 @@
1<?php
2
3namespace Wallabag\ImportBundle\Import;
4
5class ImportChain
6{
7 private $imports;
8
9 public function __construct()
10 {
11 $this->imports = [];
12 }
13
14 /**
15 * Add an import to the chain.
16 *
17 * @param ImportInterface $import
18 * @param string $alias
19 */
20 public function addImport(ImportInterface $import, $alias)
21 {
22 $this->imports[$alias] = $import;
23 }
24
25 /**
26 * Get all imports.
27 *
28 * @return array<ImportInterface>
29 */
30 public function getAll()
31 {
32 return $this->imports;
33 }
34}
diff --git a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
new file mode 100644
index 00000000..a363a566
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
@@ -0,0 +1,33 @@
1<?php
2
3namespace Wallabag\ImportBundle\Import;
4
5use Symfony\Component\DependencyInjection\ContainerBuilder;
6use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7use Symfony\Component\DependencyInjection\Reference;
8
9class ImportCompilerPass implements CompilerPassInterface
10{
11 public function process(ContainerBuilder $container)
12 {
13 if (!$container->hasDefinition('wallabag_import.chain')) {
14 return;
15 }
16
17 $definition = $container->getDefinition(
18 'wallabag_import.chain'
19 );
20
21 $taggedServices = $container->findTaggedServiceIds(
22 'wallabag_import.import'
23 );
24 foreach ($taggedServices as $id => $tagAttributes) {
25 foreach ($tagAttributes as $attributes) {
26 $definition->addMethodCall(
27 'addImport',
28 [new Reference($id), $attributes['alias']]
29 );
30 }
31 }
32 }
33}
diff --git a/src/Wallabag/ImportBundle/Import/ImportInterface.php b/src/Wallabag/ImportBundle/Import/ImportInterface.php
index 8cf238aa..25dc0d85 100644
--- a/src/Wallabag/ImportBundle/Import/ImportInterface.php
+++ b/src/Wallabag/ImportBundle/Import/ImportInterface.php
@@ -14,6 +14,13 @@ interface ImportInterface extends LoggerAwareInterface
14 public function getName(); 14 public function getName();
15 15
16 /** 16 /**
17 * Url to start the import.
18 *
19 * @return string
20 */
21 public function getUrl();
22
23 /**
17 * Description of the import. 24 * Description of the import.
18 * 25 *
19 * @return string 26 * @return string
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index aeccc7bd..b1c5bb00 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -48,9 +48,17 @@ class PocketImport implements ImportInterface
48 /** 48 /**
49 * {@inheritdoc} 49 * {@inheritdoc}
50 */ 50 */
51 public function getUrl()
52 {
53 return 'import_pocket';
54 }
55
56 /**
57 * {@inheritdoc}
58 */
51 public function getDescription() 59 public function getDescription()
52 { 60 {
53 return 'This importer will import all your <a href="https://getpocket.com">Pocket</a> data.'; 61 return 'This importer will import all your <a href="https://getpocket.com">Pocket</a> data. Pocket doesn\'t allow us to retrieve content from their service, so the readable content of each article will be re-fetched by Wallabag.';
54 } 62 }
55 63
56 /** 64 /**
@@ -196,6 +204,8 @@ class PocketImport implements ImportInterface
196 */ 204 */
197 private function parseEntries($entries) 205 private function parseEntries($entries)
198 { 206 {
207 $i = 1;
208
199 foreach ($entries as $pocketEntry) { 209 foreach ($entries as $pocketEntry) {
200 $url = isset($pocketEntry['resolved_url']) && $pocketEntry['resolved_url'] != '' ? $pocketEntry['resolved_url'] : $pocketEntry['given_url']; 210 $url = isset($pocketEntry['resolved_url']) && $pocketEntry['resolved_url'] != '' ? $pocketEntry['resolved_url'] : $pocketEntry['given_url'];
201 211
@@ -241,6 +251,12 @@ class PocketImport implements ImportInterface
241 251
242 $this->em->persist($entry); 252 $this->em->persist($entry);
243 ++$this->importedEntries; 253 ++$this->importedEntries;
254
255 // flush every 20 entries
256 if (($i % 20) === 0) {
257 $em->flush();
258 }
259 ++$i;
244 } 260 }
245 261
246 $this->em->flush(); 262 $this->em->flush();
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
index 7b012674..aff5af40 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
@@ -53,9 +53,17 @@ class WallabagV1Import implements ImportInterface
53 /** 53 /**
54 * {@inheritdoc} 54 * {@inheritdoc}
55 */ 55 */
56 public function getUrl()
57 {
58 return 'import_wallabag_v1';
59 }
60
61 /**
62 * {@inheritdoc}
63 */
56 public function getDescription() 64 public function getDescription()
57 { 65 {
58 return 'This importer will import all your wallabag v1 articles.'; 66 return 'This importer will import all your wallabag v1 articles. On your config page, click on "JSON export" in the "Export your wallabag data" section. You will have a "wallabag-export-1-xxxx-xx-xx.json" file.';
59 } 67 }
60 68
61 /** 69 /**
@@ -75,7 +83,13 @@ class WallabagV1Import implements ImportInterface
75 return false; 83 return false;
76 } 84 }
77 85
78 $this->parseEntries(json_decode(file_get_contents($this->filepath), true)); 86 $data = json_decode(file_get_contents($this->filepath), true);
87
88 if (empty($data)) {
89 return false;
90 }
91
92 $this->parseEntries($data);
79 93
80 return true; 94 return true;
81 } 95 }
@@ -108,6 +122,8 @@ class WallabagV1Import implements ImportInterface
108 */ 122 */
109 private function parseEntries($entries) 123 private function parseEntries($entries)
110 { 124 {
125 $i = 1;
126
111 foreach ($entries as $importedEntry) { 127 foreach ($entries as $importedEntry) {
112 $existingEntry = $this->em 128 $existingEntry = $this->em
113 ->getRepository('WallabagCoreBundle:Entry') 129 ->getRepository('WallabagCoreBundle:Entry')
@@ -130,6 +146,12 @@ class WallabagV1Import implements ImportInterface
130 146
131 $this->em->persist($entry); 147 $this->em->persist($entry);
132 ++$this->importedEntries; 148 ++$this->importedEntries;
149
150 // flush every 20 entries
151 if (($i % 20) === 0) {
152 $em->flush();
153 }
154 ++$i;
133 } 155 }
134 156
135 $this->em->flush(); 157 $this->em->flush();
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml
index e73ec0c8..e4dde100 100644
--- a/src/Wallabag/ImportBundle/Resources/config/services.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/services.yml
@@ -1,4 +1,7 @@
1services: 1services:
2 wallabag_import.chain:
3 class: Wallabag\ImportBundle\Import\ImportChain
4
2 wallabag_import.pocket.client: 5 wallabag_import.pocket.client:
3 class: GuzzleHttp\Client 6 class: GuzzleHttp\Client
4 arguments: 7 arguments:
@@ -18,6 +21,8 @@ services:
18 calls: 21 calls:
19 - [ setClient, [ "@wallabag_import.pocket.client" ] ] 22 - [ setClient, [ "@wallabag_import.pocket.client" ] ]
20 - [ setLogger, [ "@logger" ]] 23 - [ setLogger, [ "@logger" ]]
24 tags:
25 - { name: wallabag_import.import, alias: pocket }
21 26
22 wallabag_import.wallabag_v1.import: 27 wallabag_import.wallabag_v1.import:
23 class: Wallabag\ImportBundle\Import\WallabagV1Import 28 class: Wallabag\ImportBundle\Import\WallabagV1Import
@@ -25,3 +30,5 @@ services:
25 - "@doctrine.orm.entity_manager" 30 - "@doctrine.orm.entity_manager"
26 calls: 31 calls:
27 - [ setLogger, [ "@logger" ]] 32 - [ setLogger, [ "@logger" ]]
33 tags:
34 - { name: wallabag_import.import, alias: wallabag_v1 }
diff --git a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
index bd51f730..27baa1e3 100644
--- a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
+++ b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
@@ -1,15 +1,19 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %} 1{% extends "WallabagCoreBundle::layout.html.twig" %}
2{% block title %}{% trans %}import{% endtrans %}{% endblock %} 2{% block title %}{% trans %}Import{% endtrans %}{% endblock %}
3 3
4{% block content %} 4{% block content %}
5
6<div class="row"> 5<div class="row">
7 <div class="col s12"> 6 <div class="col s12">
8 <div class="card-panel settings"> 7 <div class="card-panel settings">
9 {% trans %}Welcome on wallabag importer. Please select your previous service that you want to migrate.{% endtrans %} 8 {% trans %}Welcome on wallabag importer. Please select your previous service that you want to migrate.{% endtrans %}
10 <ul> 9 <ul>
11 <li><a href="{{ path('import_pocket') }}">Pocket</a></li> 10 {% for import in imports %}
12 <li><a href="{{ path('import_wallabag_v1') }}">Wallabag v1</a></li> 11 <li>
12 <h5>{{ import.name }}</h5>
13 <blockquote>{{ import.description|raw }}</blockquote>
14 <p><a class="waves-effect waves-light btn" href="{{ path(import.url) }}">Import contents</a></p>
15 </li>
16 {% endfor %}
13 </ul> 17 </ul>
14 </div> 18 </div>
15 </div> 19 </div>
diff --git a/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig
index 940fe4cc..9803896c 100644
--- a/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig
+++ b/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig
@@ -1,14 +1,16 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %} 1{% extends "WallabagCoreBundle::layout.html.twig" %}
2{% block title %}{% trans %}import{% endtrans %}{% endblock %} 2{% block title %}{% trans %}Import > Pocket{% endtrans %}{% endblock %}
3 3
4{% block content %} 4{% block content %}
5
6<div class="row"> 5<div class="row">
7 <div class="col s12"> 6 <div class="col s12">
8 <div class="card-panel settings"> 7 <div class="card-panel settings">
9 {% trans %}You can import your data from your Pocket account. You just have to click on the below button and authorize the application to connect to getpocket.com.{% endtrans %} 8 <blockquote>{{ import.description|raw }}</blockquote>
9 <p>{% trans %}You can import your data from your Pocket account. You just have to click on the below button and authorize the application to connect to getpocket.com.{% endtrans %}</p>
10 <form method="post" action="{{ path('import_pocket_auth') }}"> 10 <form method="post" action="{{ path('import_pocket_auth') }}">
11 <input type="submit" value="Connect to Pocket and import data" /> 11 <button class="btn waves-effect waves-light" type="submit" name="action">
12 Connect to Pocket and import data
13 </button>
12 </form> 14 </form>
13 </div> 15 </div>
14 </div> 16 </div>
diff --git a/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig
index 328ab473..23d3e146 100644
--- a/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig
+++ b/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig
@@ -1,20 +1,26 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %} 1{% extends "WallabagCoreBundle::layout.html.twig" %}
2{% block title %}{% trans %}import{% endtrans %}{% endblock %} 2{% block title %}{% trans %}Import > Wallabag v1{% endtrans %}{% endblock %}
3 3
4{% block content %} 4{% block content %}
5
6<div class="row"> 5<div class="row">
7 <div class="col s12"> 6 <div class="col s12">
8 <div class="card-panel settings"> 7 <div class="card-panel settings">
9 <div class="row"> 8 <div class="row">
9 <blockquote>{{ import.description|raw }}</blockquote>
10 <p>{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}</p>
10 <div class="col s12"> 11 <div class="col s12">
11 {{ form_start(form, {'method': 'POST'}) }} 12 {{ form_start(form, {'method': 'POST'}) }}
12 {{ form_errors(form) }} 13 {{ form_errors(form) }}
13 <div class="row"> 14 <div class="row">
14 <div class="input-field col s12"> 15 <div class="file-field input-field col s12">
15 <p>{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}</p>
16 {{ form_errors(form.file) }} 16 {{ form_errors(form.file) }}
17 {{ form_widget(form.file) }} 17 <div class="btn">
18 <span>File</span>
19 {{ form_widget(form.file) }}
20 </div>
21 <div class="file-path-wrapper">
22 <input class="file-path validate" type="text">
23 </div>
18 </div> 24 </div>
19 </div> 25 </div>
20 <div class="hidden">{{ form_rest(form) }}</div> 26 <div class="hidden">{{ form_rest(form) }}</div>
diff --git a/src/Wallabag/ImportBundle/Tests/Controller/ImportControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/ImportControllerTest.php
new file mode 100644
index 00000000..30009af4
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/Controller/ImportControllerTest.php
@@ -0,0 +1,29 @@
1<?php
2
3namespace Wallabag\ImportBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6
7class ImportControllerTest extends WallabagCoreTestCase
8{
9 public function testLogin()
10 {
11 $client = $this->getClient();
12
13 $client->request('GET', '/import/');
14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
17 }
18
19 public function testImportList()
20 {
21 $this->logInAs('admin');
22 $client = $this->getClient();
23
24 $crawler = $client->request('GET', '/import/');
25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27 $this->assertEquals(2, $crawler->filter('blockquote')->count());
28 }
29}
diff --git a/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php
new file mode 100644
index 00000000..c2acd68c
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php
@@ -0,0 +1,42 @@
1<?php
2
3namespace Wallabag\ImportBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6
7class PocketControllerTest extends WallabagCoreTestCase
8{
9 public function testImportPocket()
10 {
11 $this->logInAs('admin');
12 $client = $this->getClient();
13
14 $crawler = $client->request('GET', '/import/pocket');
15
16 $this->assertEquals(200, $client->getResponse()->getStatusCode());
17 $this->assertEquals(1, $crawler->filter('button[type=submit]')->count());
18 }
19
20 public function testImportPocketAuth()
21 {
22 $this->logInAs('admin');
23 $client = $this->getClient();
24
25 $crawler = $client->request('GET', '/import/pocket/auth');
26
27 $this->assertEquals(301, $client->getResponse()->getStatusCode());
28 $this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location'));
29 }
30
31 public function testImportPocketCallbackWithBadToken()
32 {
33 $this->logInAs('admin');
34 $client = $this->getClient();
35
36 $crawler = $client->request('GET', '/import/pocket/callback');
37
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
39 $this->assertContains('import/pocket', $client->getResponse()->headers->get('location'));
40 $this->assertEquals('Import failed, please try again.', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
41 }
42}
diff --git a/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php
new file mode 100644
index 00000000..e12ea429
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php
@@ -0,0 +1,69 @@
1<?php
2
3namespace Wallabag\ImportBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class WallabagV1ControllerTest extends WallabagCoreTestCase
9{
10 public function testImportWallabag()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/wallabag-v1');
16
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
20 }
21
22 public function testImportWallabagWithFile()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $crawler = $client->request('GET', '/import/wallabag-v1');
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
29
30 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
31
32 $data = array(
33 'upload_import_file[file]' => $file,
34 );
35
36 $client->submit($form, $data);
37
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
39
40 $crawler = $client->followRedirect();
41
42 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
43 $this->assertContains('Import summary', $alert[0]);
44 }
45
46 public function testImportWallabagWithEmptyFile()
47 {
48 $this->logInAs('admin');
49 $client = $this->getClient();
50
51 $crawler = $client->request('GET', '/import/wallabag-v1');
52 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
53
54 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
55
56 $data = array(
57 'upload_import_file[file]' => $file,
58 );
59
60 $client->submit($form, $data);
61
62 $this->assertEquals(302, $client->getResponse()->getStatusCode());
63
64 $crawler = $client->followRedirect();
65
66 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
67 $this->assertContains('Import failed, please try again', $alert[0]);
68 }
69}
diff --git a/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php b/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php
new file mode 100644
index 00000000..702d2a9b
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php
@@ -0,0 +1,21 @@
1<?php
2
3namespace Wallabag\ImportBundle\Tests\Import;
4
5use Wallabag\ImportBundle\Import\ImportChain;
6
7class ImportChainTest extends \PHPUnit_Framework_TestCase
8{
9 public function testGetAll()
10 {
11 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\ImportInterface')
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $importChain = new ImportChain();
16 $importChain->addImport($import, 'alias');
17
18 $this->assertCount(1, $importChain->getAll());
19 $this->assertEquals($import, $importChain->getAll()['alias']);
20 }
21}
diff --git a/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php b/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php
new file mode 100644
index 00000000..bd62ab3b
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php
@@ -0,0 +1,47 @@
1<?php
2
3namespace Wallabag\ImportBundle\Tests\Import;
4
5use Symfony\Component\DependencyInjection\ContainerBuilder;
6use Wallabag\ImportBundle\Import\ImportCompilerPass;
7
8class ImportCompilerPassTest extends \PHPUnit_Framework_TestCase
9{
10 public function testProcessNoDefinition()
11 {
12 $container = new ContainerBuilder();
13 $res = $this->process($container);
14
15 $this->assertNull($res);
16 }
17
18 public function testProcess()
19 {
20 $container = new ContainerBuilder();
21 $container
22 ->register('wallabag_import.chain')
23 ->setPublic(false)
24 ;
25
26 $container
27 ->register('foo')
28 ->addTag('wallabag_import.import', array('alias' => 'pocket'))
29 ;
30
31 $this->process($container);
32
33 $this->assertTrue($container->hasDefinition('wallabag_import.chain'));
34
35 $definition = $container->getDefinition('wallabag_import.chain');
36 $this->assertTrue($definition->hasMethodCall('addImport'));
37
38 $calls = $definition->getMethodCalls();
39 $this->assertEquals('pocket', $calls[0][1][1]);
40 }
41
42 protected function process(ContainerBuilder $container)
43 {
44 $repeatedPass = new ImportCompilerPass();
45 $repeatedPass->process($container);
46 }
47}
diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
index cf706fa9..6ee70db0 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
@@ -74,7 +74,8 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
74 $pocketImport = $this->getPocketImport(); 74 $pocketImport = $this->getPocketImport();
75 75
76 $this->assertEquals('Pocket', $pocketImport->getName()); 76 $this->assertEquals('Pocket', $pocketImport->getName());
77 $this->assertEquals('This importer will import all your <a href="https://getpocket.com">Pocket</a> data.', $pocketImport->getDescription()); 77 $this->assertNotEmpty($pocketImport->getUrl());
78 $this->assertContains('This importer will import all your <a href="https://getpocket.com">Pocket</a> data.', $pocketImport->getDescription());
78 } 79 }
79 80
80 public function testOAuthRequest() 81 public function testOAuthRequest()
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
index fc66d402..8a8eb3fa 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
@@ -39,7 +39,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
39 $wallabagV1Import = $this->getWallabagV1Import(); 39 $wallabagV1Import = $this->getWallabagV1Import();
40 40
41 $this->assertEquals('Wallabag v1', $wallabagV1Import->getName()); 41 $this->assertEquals('Wallabag v1', $wallabagV1Import->getName());
42 $this->assertEquals('This importer will import all your wallabag v1 articles.', $wallabagV1Import->getDescription()); 42 $this->assertNotEmpty($wallabagV1Import->getUrl());
43 $this->assertContains('This importer will import all your wallabag v1 articles.', $wallabagV1Import->getDescription());
43 } 44 }
44 45
45 public function testImport() 46 public function testImport()
diff --git a/src/Wallabag/ImportBundle/Tests/fixtures/test.html b/src/Wallabag/ImportBundle/Tests/fixtures/test.html
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/fixtures/test.html
diff --git a/src/Wallabag/ImportBundle/Tests/fixtures/test.txt b/src/Wallabag/ImportBundle/Tests/fixtures/test.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/fixtures/test.txt
diff --git a/src/Wallabag/ImportBundle/WallabagImportBundle.php b/src/Wallabag/ImportBundle/WallabagImportBundle.php
index d00f2fe9..a5ddc1b4 100644
--- a/src/Wallabag/ImportBundle/WallabagImportBundle.php
+++ b/src/Wallabag/ImportBundle/WallabagImportBundle.php
@@ -3,7 +3,15 @@
3namespace Wallabag\ImportBundle; 3namespace Wallabag\ImportBundle;
4 4
5use Symfony\Component\HttpKernel\Bundle\Bundle; 5use Symfony\Component\HttpKernel\Bundle\Bundle;
6use Symfony\Component\DependencyInjection\ContainerBuilder;
7use Wallabag\ImportBundle\Import\ImportCompilerPass;
6 8
7class WallabagImportBundle extends Bundle 9class WallabagImportBundle extends Bundle
8{ 10{
11 public function build(ContainerBuilder $container)
12 {
13 parent::build($container);
14
15 $container->addCompilerPass(new ImportCompilerPass());
16 }
9} 17}