Merge pull request #2708 from jcharaoui/import-disablecontentupdate

Import disableContentUpdate
This commit is contained in:
Jérémy Benoist
2017-06-02 11:26:37 +02:00
committed by GitHub
20 changed files with 160 additions and 103 deletions

View File

@ -123,7 +123,7 @@ class TagControllerTest extends WallabagCoreTestCase
$this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertEquals($entryUri, $client->getResponse()->getTargetUrl());
// re-retrieve the entry to be sure to get fresh data from database (mostly for tags)
// re-retrieve the entry to be sure to get fresh data from database (mostly for tags)
$entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
$this->assertNotContains($this->tagName, $entry->getTags());

View File

@ -3,14 +3,14 @@
namespace Tests\Wallabag\CoreBundle\Helper;
use Psr\Log\NullLogger;
use Monolog\Logger;
use Monolog\Handler\TestHandler;
use Wallabag\CoreBundle\Helper\ContentProxy;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\UserBundle\Entity\User;
use Wallabag\CoreBundle\Helper\RuleBasedTagger;
use Graby\Graby;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
class ContentProxyTest extends \PHPUnit_Framework_TestCase
{
@ -38,7 +38,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://user@:80');
$this->assertEquals('http://user@:80', $entry->getUrl());
$this->assertEmpty($entry->getTitle());
@ -72,7 +73,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://0.0.0.0');
$this->assertEquals('http://0.0.0.0', $entry->getUrl());
$this->assertEmpty($entry->getTitle());
@ -111,7 +113,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://domain.io');
$this->assertEquals('http://domain.io', $entry->getUrl());
$this->assertEquals('my title', $entry->getTitle());
@ -152,7 +155,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://0.0.0.0');
$this->assertEquals('http://1.1.1.1', $entry->getUrl());
$this->assertEquals('this is my title', $entry->getTitle());
@ -193,7 +197,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
]);
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
$entry = new Entry(new User());
$proxy->updateEntry($entry, 'http://0.0.0.0');
$this->assertEquals('http://1.1.1.1', $entry->getUrl());
$this->assertEquals('this is my title', $entry->getTitle());
@ -213,8 +218,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
->method('tag');
$proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(
new Entry(new User()),
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://0.0.0.0',
[
'html' => str_repeat('this is my content', 325),
@ -250,10 +256,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
$tagger->expects($this->once())
->method('tag');
$proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(
new Entry(new User()),
'http://0.0.0.0',
$logHandler = new TestHandler();
$logger = new Logger('test', [$logHandler]);
$proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage);
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://1.1.1.1',
[
'html' => str_repeat('this is my content', 325),
'title' => 'this is my title',
@ -285,9 +295,10 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
$logger->pushHandler($handler);
$proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(
new Entry(new User()),
'http://0.0.0.0',
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://1.1.1.1',
[
'html' => str_repeat('this is my content', 325),
'title' => 'this is my title',
@ -315,24 +326,24 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
public function testTaggerThrowException()
{
$graby = $this->getMockBuilder('Graby\Graby')
->disableOriginalConstructor()
->getMock();
$tagger = $this->getTaggerMock();
$tagger->expects($this->once())
->method('tag')
->will($this->throwException(new \Exception()));
$proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
'html' => str_repeat('this is my content', 325),
'title' => 'this is my title',
'url' => 'http://1.1.1.1',
'content_type' => 'text/html',
'language' => 'fr',
]);
$proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://1.1.1.1',
[
'html' => str_repeat('this is my content', 325),
'title' => 'this is my title',
'url' => 'http://1.1.1.1',
'content_type' => 'text/html',
'language' => 'fr',
]
);
$this->assertCount(0, $entry->getTags());
}
@ -361,8 +372,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
->method('tag');
$proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
$entry = $proxy->updateEntry(
new Entry(new User()),
$entry = new Entry(new User());
$proxy->updateEntry(
$entry,
'http://1.1.1.1',
[
'html' => $html,

View File

@ -19,6 +19,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
protected $contentProxy;
protected $tagsAssigner;
protected $uow;
protected $fetchingErrorMessageTitle = 'No title found';
protected $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/master/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.';
private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
{
@ -58,7 +60,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
->expects($this->exactly($dispatched))
->method('dispatch');
$wallabag = new WallabagV1Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$wallabag = new WallabagV1Import(
$this->em,
$this->contentProxy,
$this->tagsAssigner,
$dispatcher,
$this->fetchingErrorMessageTitle,
$this->fetchingErrorMessage
);
$this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]);