Merge remote-tracking branch 'origin/master' into 2.5.0

This commit is contained in:
Jeremy Benoist
2022-05-13 13:50:50 +02:00
106 changed files with 2100 additions and 1461 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace Tests\Wallabag\ApiBundle\Controller;
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
class ConfigRestControllerTest extends WallabagApiTestCase
{
public function testGetConfig()
{
$this->client->request('GET', '/api/config.json');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$config = json_decode($this->client->getResponse()->getContent(), true);
$this->assertArrayHasKey('id', $config);
$this->assertArrayHasKey('items_per_page', $config);
$this->assertArrayHasKey('language', $config);
$this->assertArrayHasKey('reading_speed', $config);
$this->assertArrayHasKey('action_mark_as_read', $config);
$this->assertArrayHasKey('list_mode', $config);
$this->assertSame(200.0, $config['reading_speed']);
$this->assertSame('en', $config['language']);
$this->assertCount(6, $config);
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
public function testGetConfigWithoutAuthentication()
{
$client = static::createClient();
$client->request('GET', '/api/config.json');
$this->assertSame(401, $client->getResponse()->getStatusCode());
$config = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('error', $config);
$this->assertArrayHasKey('error_description', $config);
$this->assertSame('access_denied', $config['error']);
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
}
}

View File

@ -15,6 +15,7 @@ class EntryControllerTest extends WallabagCoreTestCase
const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
public $downloadImagesEnabled = false;
public $url = 'https://www.lemonde.fr/pixels/article/2019/06/18/ce-qu-il-faut-savoir-sur-le-libra-la-cryptomonnaie-de-facebook_5477887_4408996.html';
private $entryDataTestAttribute = '[data-test="entry"]';
/**
* @after
@ -101,14 +102,14 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->request('GET', '/');
$this->assertCount(4, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter($this->entryDataTestAttribute));
// Good URL
$client->request('GET', '/bookmarklet', ['url' => $this->url]);
$this->assertSame(302, $client->getResponse()->getStatusCode());
$client->followRedirect();
$crawler = $client->request('GET', '/');
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(5, $crawler->filter($this->entryDataTestAttribute));
$em = $client->getContainer()
->get('doctrine.orm.entity_manager');
@ -176,6 +177,42 @@ class EntryControllerTest extends WallabagCoreTestCase
$client->getContainer()->get('craue_config')->set('store_article_headers', 0);
}
/**
* @group NetworkCalls
*/
public function testPostNewOkWithTaggingRules()
{
$this->logInAs('empty');
$client = $this->getClient();
$crawler = $client->request('GET', '/new');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$form = $crawler->filter('form[name=entry]')->form();
$data = [
'entry[url]' => $this->url,
];
$client->submit($form, $data);
$this->assertSame(302, $client->getResponse()->getStatusCode());
$content = $client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
$tags = $content->getTagsLabel();
/*
* Without the custom reading speed of `empty` user, it'll be inversed
*/
$this->assertContains('longread', $tags);
$this->assertNotContains('shortread', $tags);
}
/**
* @group NetworkCalls
*/
@ -734,7 +771,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnReadingTimeWithNegativeValue()
@ -754,7 +791,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
// forcing negative value results in no entry displayed
$this->assertCount(0, $crawler->filter('li.entry'));
$this->assertCount(0, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnReadingTimeOnlyUpper()
@ -763,7 +800,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$client = $this->getClient();
$crawler = $client->request('GET', '/all/list');
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(5, $crawler->filter($this->entryDataTestAttribute));
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url);
@ -772,7 +809,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->getEntityManager()->flush();
$crawler = $client->request('GET', '/all/list');
$this->assertCount(6, $crawler->filter('li.entry'));
$this->assertCount(6, $crawler->filter($this->entryDataTestAttribute));
$form = $crawler->filter('button[id=submit-filter]')->form();
@ -782,7 +819,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(5, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnReadingTimeOnlyLower()
@ -800,7 +837,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(0, $crawler->filter('li.entry'));
$this->assertCount(0, $crawler->filter($this->entryDataTestAttribute));
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url);
@ -809,7 +846,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->getEntityManager()->flush();
$crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnUnreadStatus()
@ -827,7 +864,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter($this->entryDataTestAttribute));
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url);
@ -837,7 +874,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(5, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnCreationDate()
@ -868,7 +905,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter($this->entryDataTestAttribute));
$data = [
'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
@ -877,7 +914,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter($this->entryDataTestAttribute));
$data = [
'entry_filter[createdAt][left_date]' => '1970-01-01',
@ -886,7 +923,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(0, $crawler->filter('li.entry'));
$this->assertCount(0, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnAnnotatedStatus()
@ -968,7 +1005,7 @@ class EntryControllerTest extends WallabagCoreTestCase
];
$crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter($this->entryDataTestAttribute));
$crawler = $client->request('GET', '/unread/list');
$form = $crawler->filter('button[id=submit-filter]')->form();
@ -977,7 +1014,7 @@ class EntryControllerTest extends WallabagCoreTestCase
];
$crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter($this->entryDataTestAttribute));
$form = $crawler->filter('button[id=submit-filter]')->form();
$data = [
@ -985,7 +1022,7 @@ class EntryControllerTest extends WallabagCoreTestCase
];
$crawler = $client->submit($form, $data);
$this->assertCount(0, $crawler->filter('li.entry'));
$this->assertCount(0, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnStatus()
@ -1000,14 +1037,14 @@ class EntryControllerTest extends WallabagCoreTestCase
$form['entry_filter[isUnread]']->untick();
$crawler = $client->submit($form);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
$form = $crawler->filter('button[id=submit-filter]')->form();
$form['entry_filter[isArchived]']->untick();
$form['entry_filter[isStarred]']->tick();
$crawler = $client->submit($form);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterPreselectedStatus()
@ -1044,7 +1081,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$form['entry_filter[isPublic]']->tick();
$crawler = $client->submit($form);
$this->assertCount(0, $crawler->filter('li.entry'));
$this->assertCount(0, $crawler->filter($this->entryDataTestAttribute));
}
public function testPreviewPictureFilter()
@ -1057,7 +1094,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$form['entry_filter[previewPicture]']->tick();
$crawler = $client->submit($form);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
}
public function testFilterOnLanguage()
@ -1078,7 +1115,7 @@ class EntryControllerTest extends WallabagCoreTestCase
];
$crawler = $client->submit($form, $data);
$this->assertCount(3, $crawler->filter('li.entry'));
$this->assertCount(3, $crawler->filter($this->entryDataTestAttribute));
$form = $crawler->filter('button[id=submit-filter]')->form();
$data = [
@ -1086,7 +1123,7 @@ class EntryControllerTest extends WallabagCoreTestCase
];
$crawler = $client->submit($form, $data);
$this->assertCount(2, $crawler->filter('li.entry'));
$this->assertCount(2, $crawler->filter($this->entryDataTestAttribute));
}
public function testShareEntryPublicly()
@ -1289,7 +1326,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url);
@ -1312,7 +1349,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(2, $crawler->filter('li.entry'));
$this->assertCount(2, $crawler->filter($this->entryDataTestAttribute));
$crawler = $client->request('GET', '/all/list');
$form = $crawler->filter('button[id=submit-filter]')->form();
@ -1323,7 +1360,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(8, $crawler->filter('li.entry'));
$this->assertCount(8, $crawler->filter($this->entryDataTestAttribute));
}
public function testSearch()
@ -1347,7 +1384,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter($this->entryDataTestAttribute));
// Search on starred list
$crawler = $client->request('GET', '/starred/list');
@ -1366,7 +1403,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
$crawler = $client->request('GET', '/archive/list');
@ -1385,7 +1422,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
$client->request('GET', '/delete/' . $entry->getId());
// test on list of all articles
@ -1398,7 +1435,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(0, $crawler->filter('li.entry'));
$this->assertCount(0, $crawler->filter($this->entryDataTestAttribute));
// test url search on list of all articles
$entry = new Entry($this->getLoggedInUser());
@ -1417,7 +1454,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
// same as previous test but for case-sensitivity
$crawler = $client->request('GET', '/all/list');
@ -1429,7 +1466,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('li.entry'));
$this->assertCount(1, $crawler->filter($this->entryDataTestAttribute));
}
public function dataForLanguage()

View File

@ -347,6 +347,8 @@ class ExportControllerTest extends WallabagCoreTestCase
private function getSanitizedFilename($title)
{
return preg_replace('/[^A-Za-z0-9\- \']/', '', iconv('utf-8', 'us-ascii//TRANSLIT', $title));
$transliterator = \Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', \Transliterator::FORWARD);
return preg_replace('/[^A-Za-z0-9\- \']/', '', $transliterator->transliterate($title));
}
}

View File

@ -213,15 +213,62 @@ class FeedControllerTest extends WallabagCoreTestCase
$config->setFeedToken('SUPERTOKEN');
$config->setFeedLimit(null);
$em->persist($config);
$entry1 = $em
->getRepository('WallabagCoreBundle:Entry')
->find(1)
;
$entry4 = $em
->getRepository('WallabagCoreBundle:Entry')
->find(4)
;
$now = new \DateTimeImmutable('now');
$day1 = $now->modify('-8 days');
$day2 = $now->modify('-6 days');
$day3 = $now->modify('-4 days');
$day4 = $now->modify('-2 days');
$entry1->setCreatedAt($day1);
$entry4->setCreatedAt($day2);
$property = (new \ReflectionObject($entry1))->getProperty('updatedAt');
$property->setAccessible(true);
$property->setValue($entry1, $day4);
$property = (new \ReflectionObject($entry4))->getProperty('updatedAt');
$property->setAccessible(true);
$property->setValue($entry4, $day3);
$em->flush();
$client = $this->getClient();
$client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo');
// tag foo - without sort
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertSame('test title entry4', $crawler->filterXPath('//feed/entry[1]/title')->text());
$this->assertSame('test title entry1', $crawler->filterXPath('//feed/entry[2]/title')->text());
$this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo');
// tag foo - with sort created
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo?sort=created');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertSame('test title entry4', $crawler->filterXPath('//feed/entry[1]/title')->text());
$this->assertSame('test title entry1', $crawler->filterXPath('//feed/entry[2]/title')->text());
// tag foo - with sort updated
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo?sort=updated');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertSame('test title entry1', $crawler->filterXPath('//feed/entry[1]/title')->text());
$this->assertSame('test title entry4', $crawler->filterXPath('//feed/entry[2]/title')->text());
// tag foo - with invalid sort
$client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo?sort=invalid');
$this->assertSame(400, $client->getResponse()->getStatusCode());
// tag foo/3000
$client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000');
$this->assertSame(302, $client->getResponse()->getStatusCode());
}

View File

@ -476,4 +476,35 @@ class TagControllerTest extends WallabagCoreTestCase
$this->assertNotFalse(array_search('cache', $tags, true), 'Tag cache is assigned to the entry');
$this->assertNotFalse(array_search('caché', $tags, true), 'Tag caché is assigned to the entry');
}
public function testAssignTagsOnSearchResults()
{
$this->logInAs('admin');
$client = $this->getClient();
// Search on unread list
$crawler = $client->request('GET', '/unread/list');
$form = $crawler->filter('form[name=search]')->form();
$data = [
'search_entry[term]' => 'title',
];
$crawler = $client->submit($form, $data);
$client->click($crawler->selectLink('entry.list.assign_search_tag')->link());
$client->followRedirect();
$entries = $client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getBuilderForSearchByUser($this->getLoggedInUserId(), 'title', 'unread')
->getQuery()->getResult();
foreach ($entries as $entry) {
$tags = $entry->getTagsLabel();
$this->assertContains('title', $tags);
}
}
}

View File

@ -65,6 +65,7 @@ class DownloadImagesTest extends TestCase
['image/jpeg', 'jpeg'],
['image/png', 'png'],
['image/gif', 'gif'],
['image/webp', 'webp'],
];
}

View File

@ -202,10 +202,29 @@ class RuleBasedTaggerTest extends TestCase
->method('satisfies')
->willReturn(true);
$this->rulerz
->method('filter')
$query = $this->getMockBuilder('Doctrine\ORM\AbstractQuery')
->disableOriginalConstructor()
->getMock();
$query
->expects($this->once())
->method('getResult')
->willReturn([new Entry($user), new Entry($user)]);
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
->disableOriginalConstructor()
->getMock();
$qb
->expects($this->once())
->method('getQuery')
->willReturn($query);
$this->entryRepository
->expects($this->once())
->method('getBuilderForAllByUser')
->willReturn($qb);
$entries = $this->tagger->tagAllForUser($user);
$this->assertCount(2, $entries);
@ -222,6 +241,7 @@ class RuleBasedTaggerTest extends TestCase
{
$user = new User();
$config = new Config($user);
$config->setReadingSpeed(200);
$user->setConfig($config);

View File

@ -114,13 +114,13 @@ class ChromeControllerTest extends WallabagCoreTestCase
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->findByUrlAndUserId(
'https://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730',
'https://www.20minutes.fr/sport/3256363-20220321-tournoi-vi-nations-trophee-gagne-xv-france-fini-fond-seine',
$this->getLoggedInUserId()
);
$this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
$this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok');
$this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok');
$this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.20minutes.fr is ok');
$this->assertNotEmpty($content->getLanguage(), 'Language for https://www.20minutes.fr is ok');
$this->assertCount(1, $content->getTags());
$createdAt = $content->getCreatedAt();

View File

@ -1,38 +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
"checksum": "f3aa0e9c0edad632a246f7e98ec64918",
"roots": {
"bookmark_bar": {
"children": [ {
"date_added": "13118850929335823",
"id": "6",
"name": "Tournoi des VI Nations : Le trophée gagné par le XV de France a-t-il fini au fond de la Seine ?",
"type": "url",
"url": "https://www.20minutes.fr/sport/3256363-20220321-tournoi-vi-nations-trophee-gagne-xv-france-fini-fond-seine"
} ],
"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
}