From 03e3753f6bd36f12c0757c76b49b683c49de48ae Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Sep 2016 08:00:30 +0200 Subject: Add Readability import Based on the JSON export instead of the API (which will be shutting down by the September 30, 2016) --- .../ImportBundle/fixtures/readability.json | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/fixtures/readability.json (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/fixtures/readability.json b/tests/Wallabag/ImportBundle/fixtures/readability.json new file mode 100644 index 00000000..34379905 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/readability.json @@ -0,0 +1,25 @@ +{ + "bookmarks": [ + { + "article__excerpt": "When Twitter started it had so much promise to change the way we communicate. But now it has been ruined by the amount of garbage and hate we have to wade through. It’s like that polluted…", + "favorite": false, + "date_archived": null, + "article__url": "https://venngage.com/blog/hashtags-are-worthless/", + "date_added": "2016-08-25T12:05:00", + "date_favorited": null, + "article__title": "We Looked At 167,943 Tweets & Found Out Hashtags Are Worthless", + "archive": false + }, + { + "article__excerpt": "TL;DR: Re-use your DOM elements and remove the ones that are far away from the viewport. Use placeholders to account for delayed data. Here’s a demo and the code for the infinite…", + "favorite": false, + "date_archived": "2016-08-26T12:21:54", + "article__url": "https://developers.google.com/web/updates/2016/07/infinite-scroller?imm_mid=0e6839&cmp=em-webops-na-na-newsltr_20160805", + "date_added": "2016-08-06T05:35:26", + "date_favorited": null, + "article__title": "Complexities of an infinite scroller | Web Updates", + "archive": true + } + ], + "recommendations": [] +} -- cgit v1.2.3 From ca15aaac188a1ad4b08595d3dbb06634320183ed Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Sep 2016 09:36:11 +0200 Subject: Fix import count tests --- tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index 96b5300b..d869cdf9 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(3, $crawler->filter('blockquote')->count()); + $this->assertEquals(4, $crawler->filter('blockquote')->count()); } } -- cgit v1.2.3 From a1a107705948c724aca7326f8550c336a25a6364 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Sep 2016 09:57:02 +0200 Subject: Add tests on ReadabilityImport --- .../Controller/ReadabilityControllerTest.php | 122 +++++++++++++++++ .../ImportBundle/Import/ReadabilityImportTest.php | 150 +++++++++++++++++++++ .../ImportBundle/fixtures/readability-read.json | 25 ++++ 3 files changed, 297 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php create mode 100644 tests/Wallabag/ImportBundle/fixtures/readability-read.json (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php new file mode 100644 index 00000000..92cf4bfc --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -0,0 +1,122 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportReadabilityWithFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://venngage.com/blog/hashtags-are-worthless/', + $this->getLoggedInUserId() + ); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + } + + public function testImportReadabilityWithFileAndMarkAllAsRead() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/readability-read.json', 'readability-read.json'); + + $data = [ + 'upload_import_file[file]' => $file, + 'upload_import_file[mark_as_read]' => 1, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content1 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content1->isArchived()); + + $content2 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://facebook.github.io/graphql/', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content2->isArchived()); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + } + + public function testImportReadabilityWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php new file mode 100644 index 00000000..706d707b --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -0,0 +1,150 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new ReadabilityImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $readabilityImport = $this->getReadabilityImport(); + + $this->assertEquals('Readability', $readabilityImport->getName()); + $this->assertNotEmpty($readabilityImport->getUrl()); + $this->assertEquals('import.readability.description', $readabilityImport->getDescription()); + } + + public function testImport() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $readabilityImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, false)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(2)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + } + + public function testImportBadFile() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $readabilityImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $readabilityImport = $this->getReadabilityImport(true); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $readabilityImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} diff --git a/tests/Wallabag/ImportBundle/fixtures/readability-read.json b/tests/Wallabag/ImportBundle/fixtures/readability-read.json new file mode 100644 index 00000000..c60767dc --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/readability-read.json @@ -0,0 +1,25 @@ +{ + "bookmarks": [ + { + "article__excerpt": "This is a guest post from Moritz Beller from the Delft University of Technology in The Netherlands. His team produced amazing research on several million Travis CI builds, creating invaluable…", + "favorite": false, + "date_archived": "2016-08-02T06:49:30", + "article__url": "https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/", + "date_added": "2016-08-01T05:24:16", + "date_favorited": null, + "article__title": "Travis", + "archive": true + }, + { + "article__excerpt": "The GraphQL Type system describes the capabilities of a GraphQL server and is used to determine if a query is valid. The type system also describes the input types of query variables to determine if…", + "favorite": false, + "date_archived": "2016-07-19T06:48:31", + "article__url": "https://facebook.github.io/graphql/", + "date_added": "2016-06-24T17:50:16", + "date_favorited": null, + "article__title": "GraphQL", + "archive": true + } + ], + "recommendations": [] +} -- cgit v1.2.3 From 9401696fe4ac78863fa5318de9cd9765c3a139bf Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Sep 2016 16:38:08 +0200 Subject: Export dates from entries --- .../ImportBundle/fixtures/wallabag-v2-read.json | 4 ++ .../ImportBundle/fixtures/wallabag-v2.json | 48 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json index 3fa0bddf..d8609280 100644 --- a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json +++ b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json @@ -4,6 +4,8 @@ "title": "Wikimedia Foundation removes The Diary of Anne Frank due to copyright law requirements « Wikimedia blog", "url": "https://blog.wikimedia.org/2016/02/10/anne-frank-diary-removal/", "is_archived": true, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "

\"AnneFrankSchoolPhoto\"
Anne Frank in 1940. Photo by Collectie Anne Frank Stichting Amsterdam, public domain.

\n

Today, in an unfortunate example of the overreach of the United States’ current copyright law, the Wikimedia Foundation removed the Dutch-language text of The Diary of a Young Girl—more commonly known in English as the Diary of Anne Frank—from Wikisource.[1]

\n

We took this action to comply with the United States’ Digital Millennium Copyright Act (DMCA), as we believe the diary is still under US copyright protection under the law as it is currently written. Nevertheless, our removal serves as an excellent example of why the law should be changed to prevent repeated extensions of copyright terms, an issue that has plagued our communities for years.

\n

What prompted us to remove the diary?

\n

The deletion was required because the Foundation is under the jurisdiction of US law and is therefore subject to the DMCA, specifically title 17, chapter 5, section 512 of the United States Code. As we noted in 2013, “The location of the servers, incorporation, and headquarters are just three of many factors that establish US jurisdiction … if infringing content is linked to or embedded in Wikimedia projects, then  the Foundation may still be subject to liability for such use—either as a direct or contributory infringer.

\n

Based on email discussions sent to the Wikimedia Foundation at legal[at]wikimedia.org, we determined that the Wikimedia Foundation had either “actual knowledge” (i in the statute quoted below) or what is commonly called “red flag knowledge” (ii in the statute quoted below) that the Anne Frank text was hosted on Wikisource and was under copyright. The statute section states that a service provider is only protected by the DMCA when it:

\n

(i) does not have actual knowledge that the material or an activity using the material on the system or network is infringing;

\n

(ii) in the absence of such actual knowledge, is not aware of facts or circumstances from which infringing activity is apparent; or

\n

(The rest applies when we get a proper DMCA takedown notice.)

\n

Of particular concern, the US’ 9th Circuit Court of Appeals stated in their ruling for UMG Recordings, Inc. v. Shelter Capital Partners LLC that in circumstances where a hosting provider (like the Wikimedia Foundation) is informed by a third party (like an unrelated user) about infringing copyrighted content, that would likely constitute either actual or red flag knowledge under the DMCA.

\n

We believe, based on the detail and specificity contained in the emails, that we received that we had actual knowledge sufficient for the DMCA to require us to perform a takedown even in the absence of a demand letter.

\n

How is the diary still copyrighted?

\n

You may wonder why or how the Anne Frank text is copyrighted at all, as Anne Frank died in February 1945. With 70 years having passed since her death, the text may have passed into public domain in the Netherlands on January 1, 2016, where it was first published, although there is still some dispute about this.

\n

However, in the United States, the Anne Frank original text will be under copyright until 2042. This is the result of several factors coming together, and the English-language Wikipedia has actually covered this issue with a multi-part test on its non-US copyrights content guideline.

\n

In short, there are three major laws that together make the diary still copyrighted:

\n
  1. In general, the U.S. copyright for works published before 1978 is 95 years from date of publication. This came about because copyrights in the U.S. were originally for 28 years, with the ability to then extend that for a second 28 years (making a total of 56). Starting with the 1976 Copyright Act and extending to several more acts, the renewal became automatic and was extended. Today, the total term of works published before 1978 is 95 years from date of publication.
  2. \n
  3. Foreign works of countries that are treaty partners to the United States are covered as if they were US works.
  4. \n
  5. Even if a country was not a treaty partner under copyright law at the time of a publication, the 1994 Uruguay Round Agreements Act (URAA) restored copyright to works that:\n
    • had been published in a foreign country
    • \n
    • were still under copyright in that country in 1996
    • \n
    • and would have had U.S. copyright but for the fact they were published abroad.
    • \n
  6. \n
\n

Court challenges to the URAA have all failed, with the most notable (Golan v. Holder) resulting in a Supreme Court ruling that upheld the URAA.

\n

What that means for Anne Frank’s diary is unfortunately simple: no matter how it wound up in the United States and regardless of what formal copyright notices they used, the US grants it copyright until the year 2042, or 95 years after its original publication in 1947.

\n

Under current copyright law, this remains true regardless of its copyright status anywhere else in the world and regardless of whether it may have been in the public domain in the United States in the past.

\n

Jacob Rogers, Legal Counsel*
Wikimedia Foundation

\n

*Special thanks to Anisha Mangalick, Legal Fellow, for her assistance in this matter.

\n

[1] The diary text was originally located at https://nl.wikisource.org/wiki/Het_Achterhuis_(Anne_Frank).

\n

This article was edited to clarify that it is not just the location of the Wikimedia Foundation’s servers that determine whether we fall in US jurisdiction.

\n\t\t\t\t\t\t\t\t\t\t\t", "mimetype": "text/html", @@ -17,6 +19,8 @@ "title": "Tails - Tails 2.0.1 is out", "url": "https://tails.boum.org/news/version_2.0.1/index.en.html", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "
\n

This release fixes numerous security issues. All users must upgrade as soon as possible.

\n\n

New features

\n
  • \n

    Tails now uses the GNOME Shell desktop environment, in its Classic mode. GNOME Shell provides a modern, simple, and actively developed desktop environment. The Classic mode keeps the traditional Applications, Places menu, and windows list. Accessibility and non-Latin input sources are also better integrated.

    \n

    To find your way around, read our introduction to GNOME and the Tails desktop.

    \n\n\n
    The desktop and Applications menu
    \"Tails
    \n\n
    The activities overview
    \"Tails
  • \n

Upgrades and changes

\n
  • \n

    Debian 8 upgrades most included software, for example:

    \n
    • Many core GNOME utilities from 3.4 to 3.14: Files, Disks, Videos, etc.
    • \n
    • LibreOffice from 3.5 to 4.3
    • \n
    • PiTiVi from 0.15 to 0.93
    • \n
    • Git from 1.7.10 to 2.1.4
    • \n
    • Poedit from 1.5.4 to 1.6.10
    • \n
    • Liferea from 1.8.6 to 1.10
    • \n
  • \n
  • \n

    Update Tor Browser to 5.5 (based on Firefox 38.6.0 ESR):

    \n
    • Add Japanese support.
    • \n
  • \n
  • \n

    Remove the Windows camouflage which is currently broken in GNOME Shell. We started working on adding it back but your help is needed!

    \n
  • \n
  • \n

    Change to systemd as init system and use it to:

    \n
    • Sandbox many services using Linux namespaces and make them harder to exploit.
    • \n
    • Make the launching of Tor and the memory wipe on shutdown more robust.
    • \n
    • Sanitize our code base by replacing many custom scripts.
    • \n
  • \n
  • \n

    Update most firmware packages which might improve hardware compatibility.

    \n
  • \n
  • \n

    Notify the user if Tails is running from a non-free virtualization software.

    \n
  • \n
  • \n

    Remove Claws Mail, replaced by Icedove, a rebranded version of Mozilla Thunderbird.

    \n
  • \n

Fixed problems

\n
  • \n

    HiDPI displays are better supported. (#8659)

    \n
  • \n
  • \n

    Remove the option to open a download with an external application in Tor Browser as this is usually impossible due to the AppArmor confinement. (#9285)

    \n
  • \n
  • \n

    Close Vidalia before restarting Tor.

    \n
  • \n
  • \n

    Allow Videos to access the DVD drive. (#10455, #9990)

    \n
  • \n
  • \n

    Allow configuring printers without administration password. (#8443)

    \n
  • \n
\n

See the current list of known issues.

\n

Go to the download or upgrade page.

\n

If your Tails does not boot after an automatic upgrade, please upgrade your Tails manually.

\n

The next Tails release is scheduled for March 08.

\n

Have a look at our roadmap to see where we are heading to.

\n

We need your help and there are many ways to contribute to Tails (donating is only one of them). Come talk to us!

\n
\n

Tags: announce

\n

Pages linking to this one: inc/stable i386 release notes security/Numerous security holes in 2.0

\n

Last edited Sat 13 Feb 2016 02:23:58 PM CET

\n
", "mimetype": "text/html", diff --git a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json index 37c59668..efa8faf2 100644 --- a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json +++ b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json @@ -4,6 +4,8 @@ "title": "Site d'information français d'actualités indépendant et participatif en ligne | Mediapart", "url": "https://www.mediapart.fr/", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "
Édition CAMédia\n

Deux nouvelles éditions pour débattre dans le club sur la laïcité et sur la démocratie

\n

18 janv. 2016 | Par

\n

CAMédia après un échange sur « l'éthique du débat » a lancé deux discussions , l'une sur le thème de la laïcité, l'autre ( encore en cours) sur celui de la démocratie. Nous sommes heureux de pouvoir signaler la création de deux nouvelles éditions participatives sur ces thèmes. Nous vous invitons à les lire et à participer à leurs débats.

\n
\n

De l'importance de rêver, éloge du merveilleux

\n

17 janv. 2016 | Par

\n

Je parlerai ici des rêves comme moteur de vie, de ces rêves qui vous rattachent et vous font espérer à ce qu’il y a de plus humain dans l’homme, même au milieu de la plus noire des détresses.

\n
\n

Fin(s) d'une toute-puissance

\n

18 janv. 2016 | Par

\n

En ce début d’année, je recommande la lecture du dernier ouvrage de Guillaume Duval, La France ne sera jamais plus une grande puissance ? Tant mieux !

\n
\n

L’Allier, département de destruction massive du tissu culturel

\n

18 janv. 2016 | Par

\n

Les temps sont durs pour les petites structures, les associations culturelles qui, de bourgades en villages, travaillent au cœur des régions. Leurs subventions sont souvent revues à la baisse. Le département de l’Allier les a carrément supprimées. Pour favoriser « l’événementiel ».

\n
Édition Les invités de Mediapart\n

La démocratie déjà attaquée par la coopération réglementaire transatlantique

\n

18 janv. 2016 | Par

\n

Lora Verheecke et David Lundy travaillent pour Corporate Europe Observatory, une ONG basée à Bruxelles qui enquête sur le pouvoir des lobbies des grandes entreprises sur la politique de l’Union européenne. Ils révèlent que depuis 25 ans le projet de « coopération réglementaire » mené par l’Union européenne et les États-Unis a été dominé par les grandes entreprises. ET que le TTIP cherche à entériner ce projet.

\n
\n

2016, une année test pour Jacob Zuma et son gouvernement

\n

18 janv. 2016 | Par

\n

Les turbulences de l’an passé ont toutes les chances de continuer à troubler le climat politique et social de l’Afrique du Sud en 2016. La situation exige des changements profonds dans la conduite des affaires du pays. Jacob Zuma tout en admettant la nécessité de ces changements, est-il l’homme de la situation ? Son gouvernement répondra-t-il aux attentes des citoyens sud-africains ?

\n
\n

Un mal fou (janvier 2016)

\n

14 janv. 2016 | Par

\n

J’ai une fringale d’aventure, d’aventures à venir. J’ai la fringale de la fringale des aventures et soudain, rupture. Je n’y arrive plus, tout est bloqué, tout empêché. Faut dire que depuis un an environ, tout est devenu plus compliqué. Ecrire va de moins en moins de soi.

\n
\n

Redoublement : le changement à bas bruit ?

\n

17 janv. 2016 | Par

\n

S’il est une caractéristique de la forme scolaire française bien établie dans la culture des personnels, des élèves et des parents, c’est bien le redoublement, censé sanctionner des résultats insuffisants pour envisager le passage dans la classe supérieure. Or, en ce domaine, l’évolution est nette.

\n
\n

Samedi-sciences (196): des chasseurs de mammouths en Arctique il y a 45 000 ans

\n

16 janv. 2016 | Par Michel de Pracontal

\n

Les restes d’un mammouth retrouvés en Arctique sibérien, datés de 45 000 ans, portent les traces de blessures infligées par des chasseurs humains. Les scientifiques pensaient jusqu’ici que notre espèce ne s’était pas aventurée dans cette région glaciale il y a plus de 30 000 ou 35 0000 ans. En réalité, des hommes ont réussi à survivre en Arctique au moins 10 000 ans plus tôt que l’on croyait.

\n
\n

De la démocratie, du citoyen et de l'éthique

\n

14 janv. 2016 | Par

\n

Trois ouvrages sont parus au Seuil, qui font état de la nécessité d’intégrer le citoyen dans la gouvernance de la nation. Non pas à titre consultatif mais doté d’un pouvoir délibératif pour constituer une contre-force face aux clans politico-financiers qui dominent la vie publique.

\n
", "mimetype": "text/html", @@ -21,6 +23,8 @@ "title": "Réfugiés: l'UE va créer 100 000 places d'accueil dans les Balkans", "url": "http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "

Pour un sommet sur les réfugiés qui devait se concentrer sur des «mesures opérationnelles immédiates» dans les Balkans, la réunion, dimanche à Bruxelles, de 11 chefs d’Etat et de gouvernement, dont 8 Européens, a été agitée. Dès leur arrivée, Viktor Orbán (Hongrie) et Aléxis Tsípras (Grèce) se sont jeté des anathèmes. Le Premier ministre grec a dénoncé l’attitude «not in my backyard» (pas de ça chez moi) de certains Etats européens, alors que son pays est montré du doigt par d’autres dirigeants, dont Orbán : ils reprochent à la Grèce de ne pas suffisamment contrôler ses frontières avec la Turquie et ne pas montrer assez de zèle dans l’enregistrement des demandeurs d’asile.

\n

Le sommet, convoqué par la Commission européenne, sur suggestion de l’Allemagne, aura au moins permis à ces 11 Etats – Autriche, Bulgarie, Croatie, Allemagne, Grèce, Hongrie, Roumanie, Slovénie côté européen, et 3 pays «non UE», Albanie, Macédoine et Serbie – de discuter ensemble.

\n

400 policiers européens en Slovénie

\n

L’objectif, rappelé par Angela Merkel, était de trouver une «réponse coordonnée» à la crise des réfugiés. Quelques mesures ont été annoncées : 100 000 places d’accueil seront créées, dont 50 000 en Grèce, et le reste le long de la route des Balkans. 400 officiers de police de pays européens partiront en Slovénie, actuellement submergée, pour aider au contrôle des frontières. Frontex, l’agence européenne de surveillance des frontières, s’impliquera aux frontières gréco-macédonienne et gréco-albanaise pour des contrôles et identifications.

\n

Ce sommet est intervenu dans un contexte de fortes tensions, marqué par des fermetures de frontières bloquant les réfugiés dans des zones tampon. Ces obstacles ont été partiellement levés ces derniers jours, les autorités tentant d’organiser un «corridor» informel vers l’Allemagne, qui pourtant durcit sa politique d’accueil et souhaite désormais ralentir le flux. Mais la situation des réfugiés est catastrophique. L’ONG Human Rights Watch craint que des réfugiés ne meurent dans les Balkans. Des groupes de centaines, voire de milliers de personnes, bloqués près des postes-frontières, se retrouvent dans des conditions humanitaires intenables.

\n

Depuis mi-septembre, 250 000 personnes ont traversé les Balkans. En une semaine, la Slovénie a vu 60 000 réfugiés fouler le sol de son territoire. Dimanche, 15 000 personnes ont transité en Slovénie.

\n

Des zones tampon

\n

L’enjeu principal du sommet, aux yeux de nombreux Etats de l’Union européenne, était aussi que les pays des Balkans «prennent leur part» face à la crise : qu’ils accueillent et enregistrent davantage de réfugiés. Ces Etats craignent que l’Autriche ou l’Allemagne ne ferment leurs frontières et fassent de leurs pays des «zones tampon», comme s’en inquiétait Boyko Borissov, Premier ministre bulgare.

\n

« Aujourd’hui, plusieurs Etats du nord de l’Europe veulent que l’on enregistre les migrants puis que l’on détermine leur éligibilité au statut de réfugié, explique Marc Pierini, du think tank Carnegie Europe. La difficulté, c’est que les gens sont en mouvement. Pour le faire, il faut se poser quelque part. La crainte des pays intermédiaires, donc ceux des Balkans, est qu’on enregistre ces personnes sur leur territoire et qu’ils soient contraints de rester sur leur sol. Donc les pays des Balkans ne sont pas désireux d’accueillir ces réfugiés et ces derniers veulent avancer.»

\n

Le sommet a élaboré quelques principes. L’idée générale est de rendre effective la «logique de hotspot» : un enregistrement des demandeurs d’asile à leur point d’entrée dans l’Union européenne, suivi de l’expulsion de ceux qui ne correspondraient pas aux critères de la Convention de Genève, et la répartition des autres, via le mécanisme de relocalisation.

\n

Dans ce cadre, l’enregistrement des demandeurs d’asile est un élément clé. «Pas d’enregistrement, pas de droit», a prévenu le président de la Commission européenne, Jean-Claude Juncker, dimanche soir. Les Etats ont tenu à rappeler que les migrants qui refusent de demander l’asile à la frontière peuvent se voir refuser l’entrée dans un pays.

\n

Et les Etats «décourageront les mouvements de réfugiés» de frontière en frontière. La politique consistant à laisser passer les migrants vers un autre pays est officiellement jugée «inacceptable».

\n

Se jeter dans la gueule du loup

\n

Voilà pour la théorie. En pratique, la relocalisation ne devrait concerner que 160 000 réfugiés en deux ans, alors que près de 700 000 personnes sont arrivées en Europe depuis le début de l’année. De plus, les Etats ne jouent pas le jeu. La semaine passée, seules 854 places de relocalisation avaient été proposées.

\n

Dans ce contexte, il est probable que les Etats des Balkans ne s’impliqueront pas outre mesure dans les solutions proposées, craignant de devoir «garder» les réfugiés alors que l’Union européenne tarde à mettre en œuvre leur répartition.

\n

Quant aux réfugiés, ils préfèrent traverser les frontières par eux-mêmes, plutôt que de se jeter dans ces «hotspots», considérés comme la gueule du loup.

\nCédric Vallet", "mimetype": "", @@ -34,6 +38,8 @@ "title": "No title found", "url": "http://news.nationalgeographic.com/2016/02/160211-albatrosses-mothers-babies-animals-science/&sf20739758=1", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": true, "content": "Oh, what a shame, no content", "mimetype": "", @@ -44,6 +50,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 612, "title": "Échecs", @@ -58,6 +66,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 608, "title": "90% des dossiers médicaux des Coréens du sud vendus à des entreprises privées - ZATAZ", @@ -73,6 +83,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 606, "title": "Mass Surveillance As Art", @@ -87,6 +99,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 605, "title": "What David Cameron did to the pig, his party is now doing to the country", @@ -102,6 +116,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 604, "title": "CLICK HERE to support 2016 CES Winner, Revolutionary Auto-Tracking Robot", @@ -116,6 +132,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 1, "id": 603, "title": "No title found", @@ -129,6 +147,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 602, "title": "Présentation d'Arduino - Tuto Arduino - Le blog d'Eskimon", @@ -144,6 +164,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 543, "title": "Lenovo ThinkPad X1 Carbon Ultrabook Review", @@ -159,6 +181,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 541, "title": "Visitons le Château de Landsberg !", @@ -174,6 +198,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 454, "title": "Contrer les stéréotypes par les livres : “C'est dès l'enfance qu'ils se construisent”", @@ -189,6 +215,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 99, "title": "[ROM][6.0.1][Layers][N5] TipsyOS official builds {UBER TCs}", @@ -204,6 +232,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 98, "title": "Top 15 Podcasts All Web Developers Should Follow - Envato Tuts+ Code Article", @@ -218,6 +248,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 97, "title": "University of Mississippi", @@ -232,6 +264,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 96, "title": "FinnChristiansen.de Jetzt Dank Let’s Encrypt Per HTTPS Erreichbar", @@ -246,6 +280,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 82, "title": "Le développeur et l'ingénierie logicielle", @@ -259,6 +295,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 78, "title": "The Role of Methylation in Gene Expression", @@ -273,6 +311,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 53, "title": "E-Mail-Adresse kostenlos, FreeMail, De-Mail & Nachrichten", @@ -287,6 +327,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 48, "title": "OpenSSH Server on Arch Linux | DominicM test", @@ -302,6 +344,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 39, "title": "Site Moved | Site Help", @@ -316,6 +360,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 38, "title": "#Maroc : le stylo anti-pédophiles EAGLE d’AMESYS est moins bien configuré que les faux-lowers Twitter du roi Mohammed VI", @@ -331,6 +377,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 3, "title": "Simple Cloud Infrastructure for Developers", -- cgit v1.2.3 From 56c778b4152a1b886353933276ee3626e4e8c004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 15 Jan 2016 08:24:32 +0100 Subject: 1st draft for rabbitMQ --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 8534e1c8..a0f943ee 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -27,8 +27,9 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $contentProxy; protected $logHandler; + protected $producer; - private function getPocketImport($consumerKey = 'ConsumerKey') + private function getPocketImport($consumerKey = 'ConsumerKey', $rabbitMQ = false) { $this->user = new User(); @@ -65,11 +66,17 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->with('pocket_consumer_key') ->willReturn($consumerKey); + $this->producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + $pocket = new PocketImportMock( $this->tokenStorage, $this->em, $this->contentProxy, - $config + $config, + $rabbitMQ, + $this->producer ); $this->logHandler = new TestHandler(); -- cgit v1.2.3 From 40d2a29443df8ef6fdf1f2d09b5ba8808543c245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 15 Feb 2016 21:30:55 +0100 Subject: Replace RabbitMQ injection with CraueConfiguration --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index a0f943ee..5bf47d96 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -75,7 +75,6 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->em, $this->contentProxy, $config, - $rabbitMQ, $this->producer ); -- cgit v1.2.3 From ef75e1220ebb76a8df019d946460ad612759f0bb Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 3 Sep 2016 17:36:57 +0200 Subject: Send every imported item to the queue Instead of queing real Entry to process, we queue all the item to import from Pocket in a raw format. Then, the worker retrieve that information, find / create the entry and save it. --- .../ImportBundle/Import/PocketImportTest.php | 28 +++------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 5bf47d96..d6b9617e 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -27,32 +27,15 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $contentProxy; protected $logHandler; - protected $producer; - private function getPocketImport($consumerKey = 'ConsumerKey', $rabbitMQ = false) + private function getPocketImport($consumerKey = 'ConsumerKey') { $this->user = new User(); - $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') - ->disableOriginalConstructor() - ->getMock(); - - $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); - $token->expects($this->once()) - ->method('getUser') - ->willReturn($this->user); - - $this->tokenStorage->expects($this->once()) - ->method('getToken') - ->willReturn($token); - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() ->getMock(); @@ -66,17 +49,12 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->with('pocket_consumer_key') ->willReturn($consumerKey); - $this->producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') - ->disableOriginalConstructor() - ->getMock(); - $pocket = new PocketImportMock( - $this->tokenStorage, $this->em, $this->contentProxy, - $config, - $this->producer + $config ); + $pocket->setUser($this->user); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); -- cgit v1.2.3 From 02f64895728fe9aee2c696a627e0bbe27a24faf2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 5 Sep 2016 07:13:09 +0200 Subject: Retrieve all items from Pocket 5000 by 5000. Also, retrieve newest item first. --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index d6b9617e..26c6b825 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -12,14 +12,6 @@ use GuzzleHttp\Stream\Stream; use Monolog\Logger; use Monolog\Handler\TestHandler; -class PocketImportMock extends PocketImport -{ - public function getAccessToken() - { - return $this->accessToken; - } -} - class PocketImportTest extends \PHPUnit_Framework_TestCase { protected $token; @@ -49,7 +41,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->with('pocket_consumer_key') ->willReturn($consumerKey); - $pocket = new PocketImportMock( + $pocket = new PocketImport( $this->em, $this->contentProxy, $config -- cgit v1.2.3 From 6d65c0a8b089d3caa6f8e20d7935a9fe2f87d926 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 09:36:07 +0200 Subject: Add ability to define created_at for all import At the moment only Readability & wallabag v2 import allow created_at import. Pocket removed `time_added` field from their API v2 to v3... And wallabag v1 doesn't export that value. --- .../Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | 7 +++++++ .../Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php | 6 ++++++ .../Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | 2 ++ 3 files changed, 15 insertions(+) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 92cf4bfc..fb39356a 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -49,6 +49,13 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); + $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d')); } public function testImportReadabilityWithFileAndMarkAllAsRead() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index c1025b41..ff1bf6f0 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -56,6 +56,12 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertEmpty($content->getMimetype()); + $this->assertEmpty($content->getPreviewPicture()); + $this->assertEmpty($content->getLanguage()); + $this->assertEquals(1, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); } public function testImportWallabagWithFileAndMarkAllAsRead() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index d8d2c8bf..149e88bb 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -67,6 +67,8 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(2, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); + $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); } public function testImportWallabagWithEmptyFile() -- cgit v1.2.3 From 13470c3596d0b1490bbf18b39128a05bbb3c7f3e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 18:02:29 +0200 Subject: Add test for RabbitMQ Also update Symfony deps --- .../Consumer/AMPQ/EntryConsumerTest.php | 225 +++++++++++++++++++++ .../Controller/PocketControllerTest.php | 15 ++ .../Controller/ReadabilityControllerTest.php | 16 ++ .../Controller/WallabagV1ControllerTest.php | 16 ++ .../Controller/WallabagV2ControllerTest.php | 16 ++ .../ImportBundle/Import/PocketImportTest.php | 81 ++++++++ .../ImportBundle/Import/ReadabilityImportTest.php | 40 ++++ .../ImportBundle/Import/WallabagV1ImportTest.php | 40 ++++ .../ImportBundle/Import/WallabagV2ImportTest.php | 36 ++++ 9 files changed, 485 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php new file mode 100644 index 00000000..7141874c --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php @@ -0,0 +1,225 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new EntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new EntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new EntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index e0e61df8..098cf356 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -17,6 +17,21 @@ class PocketControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); } + public function testImportPocketWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/pocket'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportPocketAuthBadToken() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index fb39356a..e12a723d 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -19,6 +19,22 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } + public function testImportReadabilityWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportReadabilityWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index ff1bf6f0..96556717 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -19,6 +19,22 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } + public function testImportWallabagWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/wallabag-v1'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 149e88bb..250d0d3e 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -19,6 +19,22 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } + public function testImportWallabagWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/wallabag-v2'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 26c6b825..5ad3e435 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -343,6 +343,87 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); } + /** + * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. + */ + public function testImportWithRabbit() + { + $client = new Client(); + + $body = <<<'JSON' +{ + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "0", + "has_image": "0", + "word_count": "3197" +} +JSON; + + $mock = new Mock([ + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' + { + "status": 1, + "list": { + "229279690": '.$body.' + } + } + ')), + ]); + + $client->getEmitter()->attach($mock); + + $pocketImport = $this->getPocketImport(); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = new Entry($this->user); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $bodyAsArray = json_decode($body, true); + // because with just use `new User()` so it doesn't have an id + $bodyAsArray['userId'] = null; + + $producer + ->expects($this->once()) + ->method('publish') + ->with(json_encode($bodyAsArray)); + + $pocketImport->setClient($client); + $pocketImport->setRabbitmqProducer($producer); + $pocketImport->authorize('wunderbar_code'); + + $res = $pocketImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + } + public function testImportBadResponse() { $client = new Client(); diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 706d707b..69a66d6a 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -120,6 +120,46 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); } + public function testImportWithRabbit() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(2)) + ->method('publish'); + + $readabilityImport->setRabbitmqProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + } + public function testImportBadFile() { $readabilityImport = $this->getReadabilityImport(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index bdc47dac..ada5493e 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -120,6 +120,46 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary()); } + public function testImportWithRabbit() + { + $wallabagV1Import = $this->getWallabagV1Import(); + $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $wallabagV1Import->setRabbitmqProducer($producer); + + $res = $wallabagV1Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV1Import(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 4a45e0f0..51f0aada 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -116,6 +116,42 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); } + public function testImportWithRabbit() + { + $wallabagV2Import = $this->getWallabagV2Import(); + $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(24)) + ->method('publish'); + + $wallabagV2Import->setRabbitmqProducer($producer); + + $res = $wallabagV2Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV2Import(); -- cgit v1.2.3 From 7f7531171f6e49110b5842f869e37c766a682473 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 20:45:30 +0200 Subject: Retrieve created date from Pocket --- .../ImportBundle/Import/PocketImportTest.php | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 5ad3e435..1750e3a1 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -165,10 +165,16 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, "resolved_title": "The Massive Ryder Cup Preview", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", + "is_index": "0", "has_video": "1", "has_image": "1", "word_count": "3197", @@ -212,10 +218,16 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, "resolved_title": "The Massive Ryder Cup Preview", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", + "is_index": "0", "has_video": "0", "has_image": "0", "word_count": "3197" @@ -278,6 +290,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", "has_video": "1", @@ -291,6 +308,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", "has_video": "0", @@ -358,6 +380,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, "resolved_title": "The Massive Ryder Cup Preview", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", -- cgit v1.2.3 From b3437d58ae224121375c99e9288d8b808524e624 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 21:02:03 +0200 Subject: Enable Redis async import - using javibravo/simpleue - internal config value are now `import_with_redis` & `import_with_rabbit` which are more clear - if both option are enable rabbit will be choosen - services imports related to async are now splitted into 2 files: `redis.yml` & `rabbit.yml` - --- .../Consumer/AMPQ/EntryConsumerTest.php | 225 --------------------- .../Consumer/AMPQEntryConsumerTest.php | 225 +++++++++++++++++++++ .../Consumer/RedisEntryConsumerTest.php | 224 ++++++++++++++++++++ .../Controller/PocketControllerTest.php | 19 +- .../Controller/ReadabilityControllerTest.php | 20 +- .../Controller/WallabagV1ControllerTest.php | 20 +- .../Controller/WallabagV2ControllerTest.php | 20 +- .../ImportBundle/Import/PocketImportTest.php | 86 +++++++- .../ImportBundle/Import/ReadabilityImportTest.php | 45 ++++- .../ImportBundle/Import/WallabagV1ImportTest.php | 45 ++++- .../ImportBundle/Import/WallabagV2ImportTest.php | 41 +++- 11 files changed, 733 insertions(+), 237 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php create mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php create mode 100644 tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php deleted file mode 100644 index 7141874c..00000000 --- a/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php +++ /dev/null @@ -1,225 +0,0 @@ -getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->once()) - ->method('flush'); - - $em - ->expects($this->exactly(2)) - ->method('clear'); - - $body = <<<'JSON' -{ - "item_id": "1402935436", - "resolved_id": "1402935436", - "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "favorite": "0", - "status": "0", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", - "is_article": "1", - "is_index": "0", - "has_video": "0", - "has_image": "1", - "word_count": "200", - "tags": { - "ifttt": { - "item_id": "1402935436", - "tag": "ifttt" - }, - "mashable": { - "item_id": "1402935436", - "tag": "mashable" - } - }, - "authors": { - "2484273": { - "item_id": "1402935436", - "author_id": "2484273", - "name": "Adam Rosenberg", - "url": "http://mashable.com/author/adam-rosenberg/" - } - }, - "image": { - "item_id": "1402935436", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0" - }, - "images": { - "1": { - "item_id": "1402935436", - "image_id": "1", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0", - "credit": "Image: Steve Eichner/NameFace/Sipa USA", - "caption": "" - } - }, - "userId": 1 -} -JSON; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(1) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn($entry); - - $consumer = new EntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithBadUser() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn(null); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $consumer = new EntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithEntryProcessed() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn(null); - - $consumer = new EntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } -} diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php new file mode 100644 index 00000000..b13ade1d --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php @@ -0,0 +1,225 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new AMPQEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new AMPQEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new AMPQEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } +} diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php new file mode 100644 index 00000000..0ce7ce49 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php @@ -0,0 +1,224 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new RedisEntryConsumer( + $em, + $userRepository, + $import + ); + + $res = $consumer->manage($body); + + $this->assertTrue($res); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new RedisEntryConsumer( + $em, + $userRepository, + $import + ); + + $res = $consumer->manage($body); + + $this->assertFalse($res); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new RedisEntryConsumer( + $em, + $userRepository, + $import + ); + + $res = $consumer->manage($body); + + $this->assertFalse($res); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index 098cf356..35673261 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -22,14 +22,29 @@ class PocketControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/pocket'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportPocketWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/pocket'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportPocketAuthBadToken() diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index e12a723d..69635382 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -24,7 +24,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/readability'); @@ -32,7 +32,23 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportReadabilityWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportReadabilityWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 96556717..933ddd6c 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -24,7 +24,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/wallabag-v1'); @@ -32,7 +32,23 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportWallabagWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/wallabag-v1'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 250d0d3e..36e5221d 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -24,7 +24,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/wallabag-v2'); @@ -32,7 +32,23 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportWallabagWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/wallabag-v2'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 1750e3a1..425fa321 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -9,8 +9,11 @@ use GuzzleHttp\Client; use GuzzleHttp\Subscriber\Mock; use GuzzleHttp\Message\Response; use GuzzleHttp\Stream\Stream; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class PocketImportTest extends \PHPUnit_Framework_TestCase { @@ -442,7 +445,7 @@ JSON; ->with(json_encode($bodyAsArray)); $pocketImport->setClient($client); - $pocketImport->setRabbitmqProducer($producer); + $pocketImport->setProducer($producer); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->setMarkAsRead(true)->import(); @@ -451,6 +454,87 @@ JSON; $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); } + /** + * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. + */ + public function testImportWithRedis() + { + $client = new Client(); + + $body = <<<'JSON' +{ + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "0", + "has_image": "0", + "word_count": "3197" +} +JSON; + + $mock = new Mock([ + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' + { + "status": 1, + "list": { + "229279690": '.$body.' + } + } + ')), + ]); + + $client->getEmitter()->attach($mock); + + $pocketImport = $this->getPocketImport(); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = new Entry($this->user); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'pocket'); + $producer = new Producer($queue); + + $pocketImport->setClient($client); + $pocketImport->setProducer($producer); + $pocketImport->authorize('wunderbar_code'); + + $res = $pocketImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('pocket')); + } + public function testImportBadResponse() { $client = new Client(); diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 69a66d6a..0981eedb 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\ImportBundle\Import\ReadabilityImport; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class ReadabilityImportTest extends \PHPUnit_Framework_TestCase { @@ -152,7 +155,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(2)) ->method('publish'); - $readabilityImport->setRabbitmqProducer($producer); + $readabilityImport->setProducer($producer); $res = $readabilityImport->setMarkAsRead(true)->import(); @@ -160,6 +163,46 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); } + public function testImportWithRedis() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'readability'); + $producer = new Producer($queue); + + $readabilityImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('readability')); + } + public function testImportBadFile() { $readabilityImport = $this->getReadabilityImport(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index ada5493e..b43682cd 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\ImportBundle\Import\WallabagV1Import; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase { @@ -152,7 +155,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(4)) ->method('publish'); - $wallabagV1Import->setRabbitmqProducer($producer); + $wallabagV1Import->setProducer($producer); $res = $wallabagV1Import->setMarkAsRead(true)->import(); @@ -160,6 +163,46 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); } + public function testImportWithRedis() + { + $wallabagV1Import = $this->getWallabagV1Import(); + $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'wallabag_v1'); + $producer = new Producer($queue); + + $wallabagV1Import->setProducer($producer); + + $res = $wallabagV1Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV1Import(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 51f0aada..18998b35 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\ImportBundle\Import\WallabagV2Import; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase { @@ -144,7 +147,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(24)) ->method('publish'); - $wallabagV2Import->setRabbitmqProducer($producer); + $wallabagV2Import->setProducer($producer); $res = $wallabagV2Import->setMarkAsRead(true)->import(); @@ -152,6 +155,42 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); } + public function testImportWithRedis() + { + $wallabagV2Import = $this->getWallabagV2Import(); + $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'wallabag_v2'); + $producer = new Producer($queue); + + $wallabagV2Import->setProducer($producer); + + $res = $wallabagV2Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV2Import(); -- cgit v1.2.3 From 7230e4c39f84e5aca97f439953adfd265b8d9ba4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 18:19:41 +0200 Subject: Enable Redis on Travis Add generated files from `composer up` Add more articles for Readability tests --- .../ImportBundle/Import/ReadabilityImportTest.php | 20 +-- .../ImportBundle/fixtures/readability.json | 167 ++++++++++++++++++++- 2 files changed, 169 insertions(+), 18 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 0981eedb..67917154 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -61,9 +61,9 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(24)) ->method('findByUrlAndUserId') - ->will($this->onConsecutiveCalls(false, true)); + ->willReturn(false); $this->em ->expects($this->any()) @@ -75,14 +75,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(1)) + ->expects($this->exactly(24)) ->method('updateEntry') ->willReturn($entry); $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -96,7 +96,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') - ->will($this->onConsecutiveCalls(false, false)); + ->will($this->onConsecutiveCalls(false, true)); $this->em ->expects($this->any()) @@ -104,7 +104,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->willReturn($entryRepo); $this->contentProxy - ->expects($this->exactly(2)) + ->expects($this->exactly(1)) ->method('updateEntry') ->willReturn(new Entry($this->user)); @@ -120,7 +120,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); } public function testImportWithRabbit() @@ -152,7 +152,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(2)) + ->expects($this->exactly(24)) ->method('publish'); $readabilityImport->setProducer($producer); @@ -160,7 +160,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -198,7 +198,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } diff --git a/tests/Wallabag/ImportBundle/fixtures/readability.json b/tests/Wallabag/ImportBundle/fixtures/readability.json index 34379905..32f6fa53 100644 --- a/tests/Wallabag/ImportBundle/fixtures/readability.json +++ b/tests/Wallabag/ImportBundle/fixtures/readability.json @@ -11,14 +11,165 @@ "archive": false }, { - "article__excerpt": "TL;DR: Re-use your DOM elements and remove the ones that are far away from the viewport. Use placeholders to account for delayed data. Here’s a demo and the code for the infinite…", - "favorite": false, - "date_archived": "2016-08-26T12:21:54", - "article__url": "https://developers.google.com/web/updates/2016/07/infinite-scroller?imm_mid=0e6839&cmp=em-webops-na-na-newsltr_20160805", - "date_added": "2016-08-06T05:35:26", - "date_favorited": null, - "article__title": "Complexities of an infinite scroller | Web Updates", - "archive": true + "article__title": "Réfugiés: l'UE va créer 100 000 places d'accueil dans les Balkans", + "article__url": "http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867", + "archive": false, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": false + }, + { + "article__title": "No title found", + "article__url": "http://news.nationalgeographic.com/2016/02/160211-albatrosses-mothers-babies-animals-science/&sf20739758=1", + "archive": false, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": true + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Échecs", + "article__url": "https://fr.wikipedia.org/wiki/Échecs" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "90% des dossiers médicaux des Coréens du sud vendus à des entreprises privées - ZATAZ", + "article__url": "http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Mass Surveillance As Art", + "article__url": "https://www.nationaljournal.com/s/73311/mass-surveillance-art" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "What David Cameron did to the pig, his party is now doing to the country", + "article__url": "http://www.newstatesman.com/2015/09/what-david-cameron-did-pig-his-party-now-doing-country" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "CLICK HERE to support 2016 CES Winner, Revolutionary Auto-Tracking Robot", + "article__url": "https://www.indiegogo.com/projects/2016-ces-winner-revolutionary-auto-tracking-robot" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 1, + "article__title": "No title found", + "article__url": "http://carnetdevol.shost.ca/wordpress/aide-memoire-sur-les-commandes-associees-a-systemd/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Présentation d'Arduino - Tuto Arduino - Le blog d'Eskimon", + "article__url": "http://eskimon.fr/73-arduino-101-presentation" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Lenovo ThinkPad X1 Carbon Ultrabook Review", + "article__url": "http://www.notebookcheck.net/Lenovo-ThinkPad-X1-Carbon-Ultrabook-Review.138033.0.html" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Visitons le Château de Landsberg !", + "article__url": "http://autour-du-mont-sainte-odile.overblog.com/2016/01/visitons-le-chateau-de-landsberg.html" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Contrer les stéréotypes par les livres : “C'est dès l'enfance qu'ils se construisent”", + "article__url": "https://www.actualitte.com/article/monde-edition/contrer-les-stereotypes-par-les-livres-c-est-des-l-enfance-qu-ils-se-construisent/64058" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "[ROM][6.0.1][Layers][N5] TipsyOS official builds {UBER TCs}", + "article__url": "http://forum.xda-developers.com/google-nexus-5/development/rom-tipsyos-official-builds-uber-tcs-t3325989" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Top 15 Podcasts All Web Developers Should Follow - Envato Tuts+ Code Article", + "article__url": "http://code.tutsplus.com/articles/top-15-podcasts-all-web-developers-should-follow--net-14461" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "University of Mississippi", + "article__url": "http://olemiss.edu" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "FinnChristiansen.de Jetzt Dank Let’s Encrypt Per HTTPS Erreichbar", + "article__url": "https://www.finnchristiansen.de/2015/12/06/finnchristiansen-de-jetzt-dank-lets-encrypt-per-https-erreichbar/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Le développeur et l'ingénierie logicielle", + "article__url": "http://wemucs.com/le-developpeur-et-lingenierie-logicielle/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "The Role of Methylation in Gene Expression", + "article__url": "http://www.nature.com/scitable/topicpage/the-role-of-methylation-in-gene-expression-1070" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "E-Mail-Adresse kostenlos, FreeMail, De-Mail & Nachrichten", + "article__url": "http://web.de" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "OpenSSH Server on Arch Linux | DominicM test", + "article__url": "http://dominicm.com/openssh-server-arch-linux/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Site Moved | Site Help", + "article__url": "http://g1.com/help/sitemoved.asp" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "#Maroc : le stylo anti-pédophiles EAGLE d’AMESYS est moins bien configuré que les faux-lowers Twitter du roi Mohammed VI", + "article__url": "https://reflets.info/maroc-le-stylo-anti-pedophiles-eagle-damesys-est-moins-bien-configure-que-les-faux-lowers-twitter-du-roi-mohammed-vi/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Simple Cloud Infrastructure for Developers", + "article__url": "https://www.digitalocean.com/" } ], "recommendations": [] -- cgit v1.2.3 From 015c7a8359c950f9621b38b11c3973860a981da8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 20:24:04 +0200 Subject: Add more tests And ability to define how many messages can be hanle by the redis worker before stopping (usefull for tests) --- .../Command/RedisWorkerCommandTest.php | 74 ++++++++++++++++++++++ .../Consumer/RedisEntryConsumerTest.php | 1 + .../Controller/ReadabilityControllerTest.php | 17 +++++ .../Controller/WallabagV1ControllerTest.php | 17 +++++ .../Controller/WallabagV2ControllerTest.php | 17 +++++ 5 files changed, 126 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php new file mode 100644 index 00000000..74952847 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php @@ -0,0 +1,74 @@ +getClient()->getKernel()); + $application->add(new RedisWorkerCommand()); + + $command = $application->find('wallabag:import:redis-worker'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage No queue or consumer found for service name + */ + public function testRunRedisWorkerCommandWithBadService() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new RedisWorkerCommand()); + + $command = $application->find('wallabag:import:redis-worker'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'serviceName' => 'YOMONSERVICE', + ]); + } + + public function testRunRedisWorkerCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new RedisWorkerCommand()); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock); + + // put a fake message in the queue so the worker will stop after reading that message + // instead of waiting for others + $redisMock->lpush('wallabag.import.readability', '{}'); + + $command = $application->find('wallabag:import:redis-worker'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'serviceName' => 'readability', + '--maxIterations' => 1, + ]); + + $this->assertContains('Worker started at', $tester->getDisplay()); + $this->assertContains('Waiting for message', $tester->getDisplay()); + } +} diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php index 0ce7ce49..5e8ee41d 100644 --- a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php +++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php @@ -220,5 +220,6 @@ JSON; $res = $consumer->manage($body); $this->assertFalse($res); + $this->assertFalse($consumer->isStopJob($body)); } } diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 69635382..fb835f62 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -51,6 +51,23 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } + public function testImportReadabilityBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testImportReadabilityWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 933ddd6c..f1113365 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -51,6 +51,23 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } + public function testImportWallabagBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/wallabag-v1'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 36e5221d..b20226ad 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -51,6 +51,23 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } + public function testImportWallabagBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/wallabag-v2'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); -- cgit v1.2.3 From ebf5e5087d2f79ece42a660ee7bddaa3ff3ebe1e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 21:40:08 +0200 Subject: Add tests on ImportCommand --- .../ImportBundle/Command/ImportCommandTest.php | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Command/ImportCommandTest.php (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php new file mode 100644 index 00000000..eb7fce79 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -0,0 +1,86 @@ +getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage not found + */ + public function testRunImportCommandWithoutFilepath() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'userId' => 1, + 'filepath' => 1, + ]); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage User with id + */ + public function testRunImportCommandWithoutUserId() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'userId' => 0, + 'filepath' => './', + ]); + } + + public function testRunImportCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'userId' => 1, + 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', + '--importer' => 'v2', + ]); + + $this->assertContains('imported', $tester->getDisplay()); + $this->assertContains('already saved', $tester->getDisplay()); + } +} -- cgit v1.2.3 From 886d47973466b5516a633b0e6dd43269082f1676 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 23:57:27 +0200 Subject: Fix tests --- tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index b20226ad..ca20c85b 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -99,9 +99,9 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->getLoggedInUserId() ); - $this->assertEmpty($content->getMimetype()); - $this->assertEmpty($content->getPreviewPicture()); - $this->assertEmpty($content->getLanguage()); + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); $content = $client->getContainer() -- cgit v1.2.3 From c80cc01afa315dcfa38b2a01c5b05d4516659c24 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 13 Sep 2016 21:09:05 +0200 Subject: Change flash message for queued articles --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 10 +++++----- tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 12 ++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 425fa321..a3f68892 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -270,7 +270,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -365,7 +365,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -451,7 +451,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); } /** @@ -530,7 +530,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('pocket')); } @@ -607,6 +607,6 @@ JSON; $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 0], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 0, 'queued' => 0], $pocketImport->getSummary()); } } diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 67917154..d98cd486 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -82,7 +82,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -120,7 +120,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportWithRabbit() @@ -160,7 +160,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -198,7 +198,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index b43682cd..5ab4ad00 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -82,7 +82,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportAndMarkAllAsRead() @@ -120,7 +120,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportWithRabbit() @@ -160,7 +160,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); } public function testImportWithRedis() @@ -198,7 +198,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 18998b35..b4017f72 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -78,7 +78,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 22, 'imported' => 2], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportAndMarkAllAsRead() @@ -116,7 +116,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithRabbit() @@ -152,7 +152,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); } public function testImportWithRedis() @@ -186,7 +186,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); } @@ -227,7 +227,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertFalse($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithExceptionFromGraby() @@ -256,6 +256,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 24, 'imported' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 24, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); } } -- cgit v1.2.3 From 47d7c682a453a4831c07db926d22461f310642c6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 13 Sep 2016 22:27:27 +0200 Subject: =?UTF-8?q?Add=20more=20=E2=80=9Creal=E2=80=9D=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ReadabilityControllerTest.php | 39 ++++++++++++++++------ .../Controller/WallabagV1ControllerTest.php | 39 ++++++++++++++++------ .../Controller/WallabagV2ControllerTest.php | 39 ++++++++++++++++------ 3 files changed, 87 insertions(+), 30 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index fb835f62..7b88d891 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -35,37 +35,56 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); } - public function testImportReadabilityWithRedisEnabled() + public function testImportReadabilityBadFile() { $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); - $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $data = [ + 'upload_import_file[file]' => '', + ]; - $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); } - public function testImportReadabilityBadFile() + public function testImportReadabilityWithRedisEnabled() { $this->logInAs('admin'); $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json'); + $data = [ - 'upload_import_file[file]' => '', + 'upload_import_file[file]' => $file, ]; $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.readability')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportReadabilityWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index f1113365..98e85d45 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -35,37 +35,56 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); } - public function testImportWallabagWithRedisEnabled() + public function testImportWallabagBadFile() { $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); - $crawler = $client->request('GET', '/import/wallabag-v1'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $data = [ + 'upload_import_file[file]' => '', + ]; - $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); } - public function testImportWallabagBadFile() + public function testImportWallabagWithRedisEnabled() { $this->logInAs('admin'); $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + $crawler = $client->request('GET', '/import/wallabag-v1'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json'); + $data = [ - 'upload_import_file[file]' => '', + 'upload_import_file[file]' => $file, ]; $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.wallabag_v1')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index ca20c85b..74d61f9a 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -35,37 +35,56 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); } - public function testImportWallabagWithRedisEnabled() + public function testImportWallabagBadFile() { $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); - $crawler = $client->request('GET', '/import/wallabag-v2'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $data = [ + 'upload_import_file[file]' => '', + ]; - $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); } - public function testImportWallabagBadFile() + public function testImportWallabagWithRedisEnabled() { $this->logInAs('admin'); $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + $crawler = $client->request('GET', '/import/wallabag-v2'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json'); + $data = [ - 'upload_import_file[file]' => '', + 'upload_import_file[file]' => $file, ]; $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.wallabag_v2')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() -- cgit v1.2.3 From ac87e0db2ac5db90f1b0639a2d31c7098b4eaa20 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 14 Sep 2016 10:17:22 +0200 Subject: AMPQ -> AMQP --- .../Consumer/AMPQEntryConsumerTest.php | 225 --------------------- .../Consumer/AMQPEntryConsumerTest.php | 225 +++++++++++++++++++++ 2 files changed, 225 insertions(+), 225 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php create mode 100644 tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php deleted file mode 100644 index b13ade1d..00000000 --- a/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php +++ /dev/null @@ -1,225 +0,0 @@ -getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->once()) - ->method('flush'); - - $em - ->expects($this->exactly(2)) - ->method('clear'); - - $body = <<<'JSON' -{ - "item_id": "1402935436", - "resolved_id": "1402935436", - "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "favorite": "0", - "status": "0", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", - "is_article": "1", - "is_index": "0", - "has_video": "0", - "has_image": "1", - "word_count": "200", - "tags": { - "ifttt": { - "item_id": "1402935436", - "tag": "ifttt" - }, - "mashable": { - "item_id": "1402935436", - "tag": "mashable" - } - }, - "authors": { - "2484273": { - "item_id": "1402935436", - "author_id": "2484273", - "name": "Adam Rosenberg", - "url": "http://mashable.com/author/adam-rosenberg/" - } - }, - "image": { - "item_id": "1402935436", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0" - }, - "images": { - "1": { - "item_id": "1402935436", - "image_id": "1", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0", - "credit": "Image: Steve Eichner/NameFace/Sipa USA", - "caption": "" - } - }, - "userId": 1 -} -JSON; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(1) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn($entry); - - $consumer = new AMPQEntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithBadUser() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn(null); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $consumer = new AMPQEntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithEntryProcessed() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn(null); - - $consumer = new AMPQEntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } -} diff --git a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php new file mode 100644 index 00000000..a3263771 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php @@ -0,0 +1,225 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new AMQPEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new AMQPEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new AMQPEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } +} -- cgit v1.2.3 From ebe0787e093f4f2934430033015d6ebad1c64dca Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 16 Sep 2016 22:22:25 +0200 Subject: Moved Pocket token to user config --- .../Wallabag/ImportBundle/Import/PocketImportTest.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index a3f68892..48fbbfb6 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -4,6 +4,7 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\Config; use Wallabag\ImportBundle\Import\PocketImport; use GuzzleHttp\Client; use GuzzleHttp\Subscriber\Mock; @@ -27,6 +28,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase { $this->user = new User(); + $config = new Config($this->user); + $config->setPocketConsumerKey('xxx'); + + $this->user->setConfig($config); + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); @@ -35,19 +41,9 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $config = $this->getMockBuilder('Craue\ConfigBundle\Util\Config') - ->disableOriginalConstructor() - ->getMock(); - - $config->expects($this->any()) - ->method('get') - ->with('pocket_consumer_key') - ->willReturn($consumerKey); - $pocket = new PocketImport( $this->em, - $this->contentProxy, - $config + $this->contentProxy ); $pocket->setUser($this->user); -- cgit v1.2.3 From 59b97fae996d8307b9d957d210d46200f6d206bf Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 17 Sep 2016 07:40:56 +0200 Subject: Avoid losing entry when fetching fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of just say “Failed to save entry” we’ll save the entry at all cost and try to fetch content. If fetching content failed, the entry will still be saved at least, but without content. --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 4 +++- tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 48fbbfb6..952521a2 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -566,6 +566,8 @@ JSON; "status": 1, "list": { "229279689": { + "status": "1", + "favorite": "1", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" } } @@ -603,6 +605,6 @@ JSON; $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 0, 'queued' => 0], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); } } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index b4017f72..12bd6bdd 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -256,6 +256,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 24, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } } -- cgit v1.2.3 From 0e0102b6fcd17266f39dd63a808740d01ab9bd8a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 24 Sep 2016 19:57:59 +0200 Subject: =?UTF-8?q?Avoid=20failing=20test=20for=20user=20who=20didn?= =?UTF-8?q?=E2=80=99t=20install=20Redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php | 1 + tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | 1 + tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php | 1 + tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | 1 + 4 files changed, 4 insertions(+) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index 35673261..7d6a300f 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -34,6 +34,7 @@ class PocketControllerTest extends WallabagCoreTestCase public function testImportPocketWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 7b88d891..87ecb9d3 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -54,6 +54,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase public function testImportReadabilityWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 98e85d45..3497c4b8 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -54,6 +54,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase public function testImportWallabagWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 74d61f9a..27d2d52b 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -54,6 +54,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase public function testImportWallabagWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); -- cgit v1.2.3 From 401135852c6b25c8d5ab97beaefb02d1bd023ec9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 11:26:15 +0200 Subject: Use scheduled entity insertions to avoid tag duplicate Using `getScheduledEntityInsertions()` we can retrieve not yet flushed but already persisted entities and then avoid tags duplication on import. --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 14 ++++++++++++++ .../Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 14 ++++++++++++++ .../Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 14 ++++++++++++++ 3 files changed, 42 insertions(+) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 952521a2..9ec7935c 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -41,6 +41,20 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + $pocket = new PocketImport( $this->em, $this->contentProxy diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 5ab4ad00..82dc4c7e 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -26,6 +26,20 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 12bd6bdd..bea89efb 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -26,6 +26,20 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); -- cgit v1.2.3 From ae669126e718ede5dbf76929215d8514cd960976 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 12 Jul 2016 13:51:05 +0200 Subject: Import Firefox & Chrome bookmarks into wallabag --- .../Controller/BrowserControllerTest.php | 94 ++++++++++++++++++++++ tests/Wallabag/ImportBundle/fixtures/Bookmarks | 61 ++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/fixtures/Bookmarks (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php new file mode 100644 index 00000000..8016227c --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -0,0 +1,94 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportWallabagWithFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/Bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertEmpty($content->getLanguage()); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/fixtures/Bookmarks b/tests/Wallabag/ImportBundle/fixtures/Bookmarks new file mode 100644 index 00000000..8b78b8a4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/Bookmarks @@ -0,0 +1,61 @@ +{ + "checksum": "ef1e30cddf64cb94c63d7835640165be", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13112787540531997", + "id": "7", + "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", + "type": "url", + "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" + } ], + "date_added": "13112787380480144", + "date_modified": "13112787542724942", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ { + "date_added": "13112787503900822", + "id": "6", + "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", + "type": "url", + "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + }, { + "children": [ { + "date_added": "13112787564443378", + "id": "9", + "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "type": "url", + "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + } ], + "date_added": "13112787556763735", + "date_modified": "13112794390493325", + "id": "8", + "name": "test", + "type": "folder" + }, { + "date_added": "13112794390493325", + "id": "12", + "name": "JSON Formatter & Validator", + "type": "url", + "url": "https://jsonformatter.curiousconcept.com/" + } ], + "date_added": "13112787380480151", + "date_modified": "13112794393509988", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13112787380480155", + "date_modified": "0", + "id": "3", + "name": "Mobile bookmarks", + "type": "folder" + } + }, + "version": 1 +} -- cgit v1.2.3 From efe659ab84df5db23d95203c0cef8c43ed0914e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Sep 2016 13:53:45 +0200 Subject: Add Chrome path for Mac OS --- tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index d869cdf9..23a7c877 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(4, $crawler->filter('blockquote')->count()); + $this->assertEquals(5, $crawler->filter('blockquote')->count()); } } -- cgit v1.2.3 From 06d13ddfbc6dad568bb28d5c33daab9e54dc6669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Sep 2016 15:21:07 +0200 Subject: Indentation and renamed fixtures file --- .../Controller/BrowserControllerTest.php | 2 +- tests/Wallabag/ImportBundle/fixtures/Bookmarks | 61 ---------------------- .../Wallabag/ImportBundle/fixtures/bookmarks.json | 61 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/fixtures/Bookmarks create mode 100644 tests/Wallabag/ImportBundle/fixtures/bookmarks.json (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php index 8016227c..46c831f8 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -27,7 +27,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/browser'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $file = new UploadedFile(__DIR__.'/../fixtures/Bookmarks', 'Bookmarks'); + $file = new UploadedFile(__DIR__.'/../fixtures/bookmarks.json', 'Bookmarks'); $data = [ 'upload_import_file[file]' => $file, diff --git a/tests/Wallabag/ImportBundle/fixtures/Bookmarks b/tests/Wallabag/ImportBundle/fixtures/Bookmarks deleted file mode 100644 index 8b78b8a4..00000000 --- a/tests/Wallabag/ImportBundle/fixtures/Bookmarks +++ /dev/null @@ -1,61 +0,0 @@ -{ - "checksum": "ef1e30cddf64cb94c63d7835640165be", - "roots": { - "bookmark_bar": { - "children": [ { - "date_added": "13112787540531997", - "id": "7", - "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", - "type": "url", - "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" - } ], - "date_added": "13112787380480144", - "date_modified": "13112787542724942", - "id": "1", - "name": "Bookmarks bar", - "type": "folder" - }, - "other": { - "children": [ { - "date_added": "13112787503900822", - "id": "6", - "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", - "type": "url", - "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" - }, { - "children": [ { - "date_added": "13112787564443378", - "id": "9", - "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", - "type": "url", - "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" - } ], - "date_added": "13112787556763735", - "date_modified": "13112794390493325", - "id": "8", - "name": "test", - "type": "folder" - }, { - "date_added": "13112794390493325", - "id": "12", - "name": "JSON Formatter & Validator", - "type": "url", - "url": "https://jsonformatter.curiousconcept.com/" - } ], - "date_added": "13112787380480151", - "date_modified": "13112794393509988", - "id": "2", - "name": "Other bookmarks", - "type": "folder" - }, - "synced": { - "children": [ ], - "date_added": "13112787380480155", - "date_modified": "0", - "id": "3", - "name": "Mobile bookmarks", - "type": "folder" - } - }, - "version": 1 -} diff --git a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/bookmarks.json new file mode 100644 index 00000000..8b78b8a4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/bookmarks.json @@ -0,0 +1,61 @@ +{ + "checksum": "ef1e30cddf64cb94c63d7835640165be", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13112787540531997", + "id": "7", + "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", + "type": "url", + "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" + } ], + "date_added": "13112787380480144", + "date_modified": "13112787542724942", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ { + "date_added": "13112787503900822", + "id": "6", + "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", + "type": "url", + "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + }, { + "children": [ { + "date_added": "13112787564443378", + "id": "9", + "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "type": "url", + "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + } ], + "date_added": "13112787556763735", + "date_modified": "13112794390493325", + "id": "8", + "name": "test", + "type": "folder" + }, { + "date_added": "13112794390493325", + "id": "12", + "name": "JSON Formatter & Validator", + "type": "url", + "url": "https://jsonformatter.curiousconcept.com/" + } ], + "date_added": "13112787380480151", + "date_modified": "13112794393509988", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13112787380480155", + "date_modified": "0", + "id": "3", + "name": "Mobile bookmarks", + "type": "folder" + } + }, + "version": 1 +} -- cgit v1.2.3 From f7c55b38122cc593c2b58bb6425fca9d243b055e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 20 Sep 2016 16:45:13 +0200 Subject: Added tests for Chrome bookmarks import --- .../ImportBundle/Command/ImportCommandTest.php | 1 - .../Controller/BrowserControllerTest.php | 41 ++++++++++++++- .../Wallabag/ImportBundle/fixtures/bookmarks.json | 61 ---------------------- .../ImportBundle/fixtures/chrome-bookmarks | 36 +++++++++++++ .../ImportBundle/fixtures/firefox-bookmarks.json | 61 ++++++++++++++++++++++ 5 files changed, 136 insertions(+), 64 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/fixtures/bookmarks.json create mode 100644 tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks create mode 100644 tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index eb7fce79..7be1eb18 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Wallabag\ImportBundle\Command\ImportCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use M6Web\Component\RedisMock\RedisMockFactory; class ImportCommandTest extends WallabagCoreTestCase { diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php index 46c831f8..b686fcd9 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -19,7 +19,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } - public function testImportWallabagWithFile() + public function testImportWallabagWithFirefoxFile() { $this->logInAs('admin'); $client = $this->getClient(); @@ -27,7 +27,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/browser'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $file = new UploadedFile(__DIR__.'/../fixtures/bookmarks.json', 'Bookmarks'); + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); $data = [ 'upload_import_file[file]' => $file, @@ -68,6 +68,43 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); } + public function testImportWallabagWithChromeFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + } + public function testImportWallabagWithEmptyFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/bookmarks.json deleted file mode 100644 index 8b78b8a4..00000000 --- a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "checksum": "ef1e30cddf64cb94c63d7835640165be", - "roots": { - "bookmark_bar": { - "children": [ { - "date_added": "13112787540531997", - "id": "7", - "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", - "type": "url", - "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" - } ], - "date_added": "13112787380480144", - "date_modified": "13112787542724942", - "id": "1", - "name": "Bookmarks bar", - "type": "folder" - }, - "other": { - "children": [ { - "date_added": "13112787503900822", - "id": "6", - "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", - "type": "url", - "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" - }, { - "children": [ { - "date_added": "13112787564443378", - "id": "9", - "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", - "type": "url", - "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" - } ], - "date_added": "13112787556763735", - "date_modified": "13112794390493325", - "id": "8", - "name": "test", - "type": "folder" - }, { - "date_added": "13112794390493325", - "id": "12", - "name": "JSON Formatter & Validator", - "type": "url", - "url": "https://jsonformatter.curiousconcept.com/" - } ], - "date_added": "13112787380480151", - "date_modified": "13112794393509988", - "id": "2", - "name": "Other bookmarks", - "type": "folder" - }, - "synced": { - "children": [ ], - "date_added": "13112787380480155", - "date_modified": "0", - "id": "3", - "name": "Mobile bookmarks", - "type": "folder" - } - }, - "version": 1 -} diff --git a/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks new file mode 100644 index 00000000..0478eb41 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks @@ -0,0 +1,36 @@ +{ + "checksum": "f3aa0e9c0edad632a246f7e98ec64918", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13118850929335823", + "id": "6", + "name": "\"La multiplication des chefs de projet est une catastrophe managériale majeure\", affirme le sociologue François Dupuy - Ressources humaines", + "type": "url", + "url": "http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730" + } ], + "date_added": "13118829474385693", + "date_modified": "13118850929335823", + "id": "1", + "name": "Barre de favoris", + "type": "folder" + }, + "other": { + "children": [ ], + "date_added": "13118829474385701", + "date_modified": "0", + "id": "2", + "name": "Autres favoris", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13118829474385702", + "date_modified": "0", + "id": "3", + "name": "Favoris sur mobile", + "type": "folder" + } + }, + "version": 1 +} diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json new file mode 100644 index 00000000..8b78b8a4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -0,0 +1,61 @@ +{ + "checksum": "ef1e30cddf64cb94c63d7835640165be", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13112787540531997", + "id": "7", + "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", + "type": "url", + "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" + } ], + "date_added": "13112787380480144", + "date_modified": "13112787542724942", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ { + "date_added": "13112787503900822", + "id": "6", + "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", + "type": "url", + "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + }, { + "children": [ { + "date_added": "13112787564443378", + "id": "9", + "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "type": "url", + "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + } ], + "date_added": "13112787556763735", + "date_modified": "13112794390493325", + "id": "8", + "name": "test", + "type": "folder" + }, { + "date_added": "13112794390493325", + "id": "12", + "name": "JSON Formatter & Validator", + "type": "url", + "url": "https://jsonformatter.curiousconcept.com/" + } ], + "date_added": "13112787380480151", + "date_modified": "13112794393509988", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13112787380480155", + "date_modified": "0", + "id": "3", + "name": "Mobile bookmarks", + "type": "folder" + } + }, + "version": 1 +} -- cgit v1.2.3 From 59201088b4fc13fd361238396f630dabd9bd1990 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2016 17:47:47 +0200 Subject: bring chrome and firefox as separate imports --- .../Controller/BrowserControllerTest.php | 131 ------------ .../Controller/ChromeControllerTest.php | 149 +++++++++++++ .../Controller/FirefoxControllerTest.php | 161 ++++++++++++++ .../Controller/ImportControllerTest.php | 2 +- .../Controller/ReadabilityControllerTest.php | 1 - .../ImportBundle/Import/ChromeImportTest.php | 233 +++++++++++++++++++++ .../ImportBundle/Import/FirefoxImportTest.php | 233 +++++++++++++++++++++ 7 files changed, 777 insertions(+), 133 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Import/ChromeImportTest.php create mode 100644 tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php deleted file mode 100644 index b686fcd9..00000000 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ /dev/null @@ -1,131 +0,0 @@ -logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - } - - public function testImportWallabagWithFirefoxFile() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - - $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); - - $data = [ - 'upload_import_file[file]' => $file, - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.import.notice.summary', $body[0]); - - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId( - 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', - $this->getLoggedInUserId() - ); - - $this->assertNotEmpty($content->getMimetype()); - $this->assertNotEmpty($content->getPreviewPicture()); - $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); - - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId( - 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', - $this->getLoggedInUserId() - ); - - $this->assertNotEmpty($content->getMimetype()); - $this->assertNotEmpty($content->getPreviewPicture()); - $this->assertEmpty($content->getLanguage()); - } - - public function testImportWallabagWithChromeFile() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - - $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); - - $data = [ - 'upload_import_file[file]' => $file, - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.import.notice.summary', $body[0]); - - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId( - 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', - $this->getLoggedInUserId() - ); - - $this->assertNotEmpty($content->getMimetype()); - $this->assertNotEmpty($content->getPreviewPicture()); - $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); - } - - public function testImportWallabagWithEmptyFile() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - - $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); - - $data = [ - 'upload_import_file[file]' => $file, - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.import.notice.failed', $body[0]); - } -} diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php new file mode 100644 index 00000000..448e559f --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -0,0 +1,149 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportChromeWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportChromeBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportChromeWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.chrome')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + + public function testImportWallabagWithChromeFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', + $this->getLoggedInUserId() + ); + + $this->assertEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php new file mode 100644 index 00000000..2de0aa09 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -0,0 +1,161 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportFirefoxWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportFirefoxBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportFirefoxWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.firefox')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + + public function testImportWallabagWithFirefoxFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertEmpty($content->getLanguage()); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index 23a7c877..b6783a56 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(5, $crawler->filter('blockquote')->count()); + $this->assertEquals(6, $crawler->filter('blockquote')->count()); } } diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 87ecb9d3..916dd297 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -57,7 +57,6 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); $crawler = $client->request('GET', '/import/readability'); diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php new file mode 100644 index 00000000..f781a4d2 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new ChromeImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $chromeImport = $this->getChromeImport(); + + $this->assertEquals('Chrome', $chromeImport->getName()); + $this->assertNotEmpty($chromeImport->getUrl()); + $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); + } + + public function testImport() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(4)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(4)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $chromeImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $chromeImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + } + + public function testImportWithRabbit() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $chromeImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + } + + public function testImportWithRedis() + { + $chromeImport = $this->getReadabilityImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'chrome'); + $producer = new Producer($queue); + + $chromeImport->setProducer($producer); + + $res = $chromeImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('chrome')); + } + + public function testImportBadFile() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $chromeImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $chromeImport = $this->getChromeImport(true); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $chromeImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php new file mode 100644 index 00000000..0b4a28b4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new FirefoxImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $firefoxImport = $this->getFirefoxImport(); + + $this->assertEquals('Firefox', $firefoxImport->getName()); + $this->assertNotEmpty($firefoxImport->getUrl()); + $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); + } + + public function testImport() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(4)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(4)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $firefoxImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $firefoxImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + } + + public function testImportWithRabbit() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $firefoxImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + } + + public function testImportWithRedis() + { + $firefoxImport = $this->getReadabilityImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'firefox'); + $producer = new Producer($queue); + + $firefoxImport->setProducer($producer); + + $res = $firefoxImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('firefox')); + } + + public function testImportBadFile() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $firefoxImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $firefoxImport = $this->getFirefoxImport(true); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $firefoxImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} -- cgit v1.2.3 From 64b1229b2d711e6b2f0e60de482802d9e86b912f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2016 19:24:19 +0200 Subject: fix tests --- .../Controller/ChromeControllerTest.php | 1 - .../ImportBundle/Import/ChromeImportTest.php | 30 +++++++++++----------- .../ImportBundle/Import/FirefoxImportTest.php | 24 ++++++++--------- 3 files changed, 27 insertions(+), 28 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 448e559f..8890c5b1 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -117,7 +117,6 @@ class ChromeControllerTest extends WallabagCoreTestCase $this->getLoggedInUserId() ); - $this->assertEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index f781a4d2..1e52615c 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -61,7 +61,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(1)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -75,26 +75,26 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('updateEntry') ->willReturn($entry); $res = $chromeImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportAndMarkAllAsRead() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(1)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,13 +120,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportWithRabbit() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -152,20 +152,20 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('publish'); $chromeImport->setProducer($producer); - $res = $readabilityImport->setMarkAsRead(true)->import(); + $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); } public function testImportWithRedis() { - $chromeImport = $this->getReadabilityImport(); + $chromeImport = $this->getChromeImport(); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') @@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('chrome')); } @@ -213,21 +213,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $chromeImport = $this->getChromeImport(true); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $res = $chromeImport->import(); $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } } diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index 0b4a28b4..e8f0f3c7 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -88,13 +88,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase public function testImportAndMarkAllAsRead() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(4)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,13 +120,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -152,20 +152,20 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('publish'); $firefoxImport->setProducer($producer); - $res = $readabilityImport->setMarkAsRead(true)->import(); + $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); } public function testImportWithRedis() { - $firefoxImport = $this->getReadabilityImport(); + $firefoxImport = $this->getFirefoxImport(); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') @@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('firefox')); } @@ -213,21 +213,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $firefoxImport = $this->getFirefoxImport(true); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $res = $firefoxImport->import(); $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } } -- cgit v1.2.3 From 27acc6ddb8b0a1549a3f015171621e3056ef65d2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 15:29:40 +0200 Subject: Fix bad date format in Browser import --- tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | 4 ++++ tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 8890c5b1..23c80bec 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -120,6 +120,10 @@ class ChromeControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 2de0aa09..10fbc225 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -133,6 +133,10 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertEmpty($content->getLanguage()); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() -- cgit v1.2.3 From 12d93e6896f2d99b6329b7979ee7b6d11e457c3a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 22:24:07 +0200 Subject: Update Firefox file With real data, the previous looks more than a Chrome converted file. Also, fix date conversion (hope so). --- .../Controller/FirefoxControllerTest.php | 4 +- .../ImportBundle/Import/FirefoxImportTest.php | 10 +- .../ImportBundle/fixtures/firefox-bookmarks.json | 119 +++++++++++---------- 3 files changed, 67 insertions(+), 66 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 10fbc225..dea5b79c 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -135,8 +135,8 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); $createdAt = $content->getCreatedAt(); - $this->assertEquals('2011', $createdAt->format('Y')); - $this->assertEquals('07', $createdAt->format('m')); + $this->assertEquals('2013', $createdAt->format('Y')); + $this->assertEquals('12', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index e8f0f3c7..007dda6a 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -61,7 +61,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -75,14 +75,14 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(4)) + ->expects($this->exactly(2)) ->method('updateEntry') ->willReturn($entry); $res = $firefoxImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -94,7 +94,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,7 +120,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index 8b78b8a4..ee06a16c 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -1,61 +1,62 @@ { - "checksum": "ef1e30cddf64cb94c63d7835640165be", - "roots": { - "bookmark_bar": { - "children": [ { - "date_added": "13112787540531997", - "id": "7", - "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", - "type": "url", - "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" - } ], - "date_added": "13112787380480144", - "date_modified": "13112787542724942", - "id": "1", - "name": "Bookmarks bar", - "type": "folder" - }, - "other": { - "children": [ { - "date_added": "13112787503900822", - "id": "6", - "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", - "type": "url", - "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" - }, { - "children": [ { - "date_added": "13112787564443378", - "id": "9", - "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", - "type": "url", - "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" - } ], - "date_added": "13112787556763735", - "date_modified": "13112794390493325", - "id": "8", - "name": "test", - "type": "folder" - }, { - "date_added": "13112794390493325", - "id": "12", - "name": "JSON Formatter & Validator", - "type": "url", - "url": "https://jsonformatter.curiousconcept.com/" - } ], - "date_added": "13112787380480151", - "date_modified": "13112794393509988", - "id": "2", - "name": "Other bookmarks", - "type": "folder" - }, - "synced": { - "children": [ ], - "date_added": "13112787380480155", - "date_modified": "0", - "id": "3", - "name": "Mobile bookmarks", - "type": "folder" - } - }, - "version": 1 + "guid": "root________", + "title": "", + "index": 0, + "dateAdded": 1388166091504000, + "lastModified": 1472897622350000, + "id": 1, + "type": "text/x-moz-place-container", + "root": "placesRoot", + "children": [ + { + "guid": "toolbar_____", + "title": "Barre personnelle", + "index": 1, + "dateAdded": 1388166091504000, + "lastModified": 1472897622263000, + "id": 3, + "annos": [ + { + "name": "bookmarkProperties/description", + "flags": 0, + "expires": 4, + "value": "Ajoutez des marque-pages dans ce dossier pour les voir apparaître sur votre barre personnelle" + } + ], + "type": "text/x-moz-place-container", + "root": "toolbarFolder", + "children": [ + { + "guid": "tard77lzbC5H", + "title": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "index": 1, + "dateAdded": 1388166091644000, + "lastModified": 1388166091644000, + "id": 4, + "type": "text/x-moz-place", + "uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + }, + { + "guid": "E385l9vZ_LVn", + "title": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java", + "index": 1, + "dateAdded": 1388166091544000, + "lastModified": 1388166091545000, + "id": 5, + "type": "text/x-moz-place", + "uri": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + } + ] + }, + { + "guid": "unfiled_____", + "title": "Autres marque-pages", + "index": 3, + "dateAdded": 1388166091504000, + "lastModified": 1388166091542000, + "id": 6, + "type": "text/x-moz-place-container", + "root": "unfiledBookmarksFolder" + } + ] } -- cgit v1.2.3 From fefef9d41b4d1bd9efbd49011159bae70bf67528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 26 Sep 2016 13:40:10 +0200 Subject: Added tags for Firefox import --- tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 2 +- tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index dea5b79c..98f13d72 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -120,7 +120,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); + $this->assertEquals(2, count($content->getTags())); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index ee06a16c..406b5697 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -32,6 +32,7 @@ "index": 1, "dateAdded": 1388166091644000, "lastModified": 1388166091644000, + "tags":"test,tag", "id": 4, "type": "text/x-moz-place", "uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" -- cgit v1.2.3 From ff1a5362f7254d686864ea53994da6c517b3d3e8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 27 Sep 2016 07:57:53 +0200 Subject: Add Instapaper import Also update ImportController with latest import (chrome, firefox & instapaper). --- .../Controller/ImportControllerTest.php | 2 +- .../ImportBundle/Import/InstapaperImportTest.php | 233 +++++++++++++++++++++ .../ImportBundle/fixtures/instapaper-export.csv | 4 + 3 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php create mode 100644 tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index b6783a56..0bc40bdd 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(6, $crawler->filter('blockquote')->count()); + $this->assertEquals(7, $crawler->filter('blockquote')->count()); } } diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php new file mode 100644 index 00000000..75900bd7 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $import = new InstapaperImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $import->setLogger($logger); + + if (false === $unsetUser) { + $import->setUser($this->user); + } + + return $import; + } + + public function testInit() + { + $instapaperImport = $this->getInstapaperImport(); + + $this->assertEquals('Instapaper', $instapaperImport->getName()); + $this->assertNotEmpty($instapaperImport->getUrl()); + $this->assertEquals('import.instapaper.description', $instapaperImport->getDescription()); + } + + public function testImport() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(3)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(3)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $instapaperImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(3)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->once()) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->once()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $instapaperImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); + } + + public function testImportWithRabbit() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(3)) + ->method('publish'); + + $instapaperImport->setProducer($producer); + + $res = $instapaperImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); + } + + public function testImportWithRedis() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'instapaper'); + $producer = new Producer($queue); + + $instapaperImport->setProducer($producer); + + $res = $instapaperImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('instapaper')); + } + + public function testImportBadFile() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $instapaperImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $instapaperImport = $this->getInstapaperImport(true); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $res = $instapaperImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} diff --git a/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv new file mode 100644 index 00000000..28a4c8e6 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv @@ -0,0 +1,4 @@ +URL,Title,Selection,Folder +http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551,Baumettes : un tour en cellule,,Unread +https://redditblog.com/2016/09/20/amp-and-reactredux/,AMP and React+Redux: Why Not?,,Archive +https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c,Why Foursquare / Swarm is still my favourite social network,,Starred -- cgit v1.2.3 From c7ea9b41f32f222fef6a59734ea0b1176bfa1f41 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 27 Sep 2016 17:01:14 +0200 Subject: Add controller test for Instapaper --- .../Controller/InstapaperControllerTest.php | 196 +++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php new file mode 100644 index 00000000..9df08e75 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php @@ -0,0 +1,196 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportInstapaperWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/instapaper'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportInstapaperBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportInstapaperWithRedisEnabled() + { + $this->checkRedis(); + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/instapaper'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper.csv'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.instapaper')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + + public function testImportInstapaperWithFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper.csv'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551', + $this->getLoggedInUserId() + ); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); + } + + public function testImportInstapaperWithFileAndMarkAllAsRead() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper-read.csv'); + + $data = [ + 'upload_import_file[file]' => $file, + 'upload_import_file[mark_as_read]' => 1, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content1 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://redditblog.com/2016/09/20/amp-and-reactredux/', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content1->isArchived()); + + $content2 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content2->isArchived()); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + } + + public function testImportInstapaperWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} -- cgit v1.2.3 From e40bed36077164cb6d83761a6554b6b88ad95097 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 10 Oct 2016 16:34:57 +0200 Subject: Avoid error when Redis isn't here in tests --- tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | 1 + tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 1 + 2 files changed, 2 insertions(+) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 23c80bec..c0417bbe 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -54,6 +54,7 @@ class ChromeControllerTest extends WallabagCoreTestCase public function testImportChromeWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); $client->getContainer()->get('craue_config')->set('import_with_redis', 1); diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 98f13d72..6154ae8d 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -54,6 +54,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase public function testImportFirefoxWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); $client->getContainer()->get('craue_config')->set('import_with_redis', 1); -- cgit v1.2.3