mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Merge branch 'master' into feat_referer_to_session_redirect
This commit is contained in:
commit
ced2ea4015
362 changed files with 8665 additions and 6104 deletions
|
@ -24,8 +24,6 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test fetching annotations for an entry.
|
||||
*
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
public function testGetAnnotations($prefixUrl)
|
||||
|
@ -37,15 +35,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
->findOneByUserName('admin');
|
||||
$entry = $em
|
||||
->getRepository(Entry::class)
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
|
||||
$annotation = new Annotation($user);
|
||||
$annotation->setEntry($entry);
|
||||
$annotation->setText('This is my annotation /o/');
|
||||
$annotation->setQuote('content');
|
||||
|
||||
$em->persist($annotation);
|
||||
$em->flush();
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry1', $user->getId());
|
||||
|
||||
if ('annotations' === $prefixUrl) {
|
||||
$this->logInAs('admin');
|
||||
|
@ -56,23 +46,44 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
|
||||
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||
$this->assertGreaterThanOrEqual(1, $content['total']);
|
||||
$this->assertSame($annotation->getText(), $content['rows'][0]['text']);
|
||||
|
||||
// we need to re-fetch the annotation becase after the flush, it has been "detached" from the entity manager
|
||||
$annotation = $em->getRepository(Annotation::class)->findAnnotationById($annotation->getId());
|
||||
$em->remove($annotation);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating an annotation for an entry.
|
||||
*
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
public function testGetAnnotationsFromAnOtherUser($prefixUrl)
|
||||
{
|
||||
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$otherUser = $em
|
||||
->getRepository(User::class)
|
||||
->findOneByUserName('bob');
|
||||
$entry = $em
|
||||
->getRepository(Entry::class)
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry3', $otherUser->getId());
|
||||
|
||||
if ('annotations' === $prefixUrl) {
|
||||
$this->logInAs('admin');
|
||||
}
|
||||
|
||||
$this->client->request('GET', $prefixUrl . '/' . $entry->getId() . '.json');
|
||||
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
||||
|
||||
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||
$this->assertGreaterThanOrEqual(0, $content['total']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
public function testSetAnnotation($prefixUrl)
|
||||
{
|
||||
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$user = $em
|
||||
->getRepository(User::class)
|
||||
->findOneByUserName('admin');
|
||||
|
||||
if ('annotations' === $prefixUrl) {
|
||||
$this->logInAs('admin');
|
||||
}
|
||||
|
@ -104,7 +115,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
/** @var Annotation $annotation */
|
||||
$annotation = $em
|
||||
->getRepository(Annotation::class)
|
||||
->findLastAnnotationByPageId($entry->getId(), 1);
|
||||
->findLastAnnotationByUserId($entry->getId(), $user->getId());
|
||||
|
||||
$this->assertSame('my annotation', $annotation->getText());
|
||||
}
|
||||
|
@ -197,8 +208,6 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test editing an existing annotation.
|
||||
*
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
public function testEditAnnotation($prefixUrl)
|
||||
|
@ -245,8 +254,31 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test deleting an annotation.
|
||||
*
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
public function testEditAnnotationFromAnOtherUser($prefixUrl)
|
||||
{
|
||||
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$otherUser = $em
|
||||
->getRepository(User::class)
|
||||
->findOneByUserName('bob');
|
||||
$entry = $em
|
||||
->getRepository(Entry::class)
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry3', $otherUser->getId());
|
||||
$annotation = $em
|
||||
->getRepository(Annotation::class)
|
||||
->findLastAnnotationByUserId($entry->getId(), $otherUser->getId());
|
||||
|
||||
$headers = ['CONTENT_TYPE' => 'application/json'];
|
||||
$content = json_encode([
|
||||
'text' => 'a modified annotation',
|
||||
]);
|
||||
$this->client->request('PUT', $prefixUrl . '/' . $annotation->getId() . '.json', [], [], $headers, $content);
|
||||
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
public function testDeleteAnnotation($prefixUrl)
|
||||
|
@ -289,4 +321,40 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
|
|||
|
||||
$this->assertNull($annotationDeleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForEachAnnotations
|
||||
*/
|
||||
public function testDeleteAnnotationFromAnOtherUser($prefixUrl)
|
||||
{
|
||||
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$otherUser = $em
|
||||
->getRepository(User::class)
|
||||
->findOneByUserName('bob');
|
||||
$entry = $em
|
||||
->getRepository(Entry::class)
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry3', $otherUser->getId());
|
||||
$annotation = $em
|
||||
->getRepository(Annotation::class)
|
||||
->findLastAnnotationByUserId($entry->getId(), $otherUser->getId());
|
||||
|
||||
$user = $em
|
||||
->getRepository(User::class)
|
||||
->findOneByUserName('admin');
|
||||
$entry = $em
|
||||
->getRepository(Entry::class)
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
|
||||
if ('annotations' === $prefixUrl) {
|
||||
$this->logInAs('admin');
|
||||
}
|
||||
|
||||
$headers = ['CONTENT_TYPE' => 'application/json'];
|
||||
$content = json_encode([
|
||||
'text' => 'a modified annotation',
|
||||
]);
|
||||
$this->client->request('DELETE', $prefixUrl . '/' . $annotation->getId() . '.json', [], [], $headers, $content);
|
||||
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,12 @@ class ConfigRestControllerTest extends WallabagApiTestCase
|
|||
$this->assertArrayHasKey('reading_speed', $config);
|
||||
$this->assertArrayHasKey('action_mark_as_read', $config);
|
||||
$this->assertArrayHasKey('list_mode', $config);
|
||||
$this->assertArrayHasKey('display_thumbnails', $config);
|
||||
|
||||
$this->assertSame(200.0, $config['reading_speed']);
|
||||
$this->assertSame('en', $config['language']);
|
||||
|
||||
$this->assertCount(6, $config);
|
||||
$this->assertCount(7, $config);
|
||||
|
||||
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\Wallabag\ApiBundle\Controller;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
|
||||
|
||||
class WallabagRestControllerTest extends WallabagApiTestCase
|
||||
|
@ -35,4 +36,32 @@ class WallabagRestControllerTest extends WallabagApiTestCase
|
|||
|
||||
$this->assertSame('wallabag', $content['appname']);
|
||||
}
|
||||
|
||||
public function testAllowedRegistration()
|
||||
{
|
||||
// create a new client instead of using $this->client to be sure client isn't authenticated
|
||||
$client = static::createClient();
|
||||
|
||||
if (!$client->getContainer()->getParameter('fosuser_registration')) {
|
||||
$this->markTestSkipped('fosuser_registration is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
|
||||
|
||||
$client->request('GET', '/api/info');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertTrue($content['allowed_registration']);
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
|
||||
|
||||
$client->request('GET', '/api/info');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertFalse($content['allowed_registration']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ namespace Tests\Wallabag\CoreBundle\Command;
|
|||
|
||||
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
|
@ -35,7 +35,7 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
|
||||
/** @var Connection $connection */
|
||||
$connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection();
|
||||
if ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
|
||||
if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||
/*
|
||||
* LOG: statement: CREATE DATABASE "wallabag"
|
||||
* ERROR: source database "template1" is being accessed by other users
|
||||
|
@ -89,7 +89,11 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
|
||||
/** @var InstallCommand $command */
|
||||
$command = $application->find('wallabag:install');
|
||||
$command->disableRunOtherCommands();
|
||||
|
||||
// enable calling other commands for MySQL only because rollback isn't supported
|
||||
if (!$this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
|
||||
$command->disableRunOtherCommands();
|
||||
}
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->setInputs([
|
||||
|
@ -109,6 +113,10 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
|
||||
public function testRunInstallCommandWithReset()
|
||||
{
|
||||
if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
|
||||
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
|
||||
}
|
||||
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
/** @var InstallCommand $command */
|
||||
|
@ -138,6 +146,10 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
|
||||
public function testRunInstallCommandWithDatabaseRemoved()
|
||||
{
|
||||
if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
|
||||
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
|
||||
}
|
||||
|
||||
// skipped SQLite check when database is removed because while testing for the connection,
|
||||
// the driver will create the file (so the database) before testing if database exist
|
||||
if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof SqlitePlatform) {
|
||||
|
@ -178,6 +190,10 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
|
||||
public function testRunInstallCommandChooseResetSchema()
|
||||
{
|
||||
if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
|
||||
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
|
||||
}
|
||||
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
/** @var InstallCommand $command */
|
||||
|
@ -208,7 +224,7 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
*
|
||||
* I don't know from where the "/tes_/" come from, it should be "/test/" instead ...
|
||||
*/
|
||||
if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySqlPlatform) {
|
||||
if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
|
||||
$this->markTestSkipped('That test is failing when using MySQL when clearing the cache (see code comment)');
|
||||
}
|
||||
|
||||
|
@ -244,6 +260,10 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
|
||||
public function testRunInstallCommandNoInteraction()
|
||||
{
|
||||
if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
|
||||
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
|
||||
}
|
||||
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
/** @var InstallCommand $command */
|
||||
|
|
|
@ -797,7 +797,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
|||
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
|
||||
$this->assertStringNotContainsString('config.form_user.delete.button', $body[0]);
|
||||
|
||||
$client->request('GET', '/account/delete');
|
||||
$client->request('POST', '/account/delete');
|
||||
$this->assertSame(403, $client->getResponse()->getStatusCode());
|
||||
|
||||
$user = $em
|
||||
|
@ -862,9 +862,9 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
|||
|
||||
$crawler = $client->request('GET', '/config');
|
||||
|
||||
$deleteLink = $crawler->filter('.delete-account')->last()->link();
|
||||
$deleteForm = $crawler->filter('form[name=delete-account]')->form();
|
||||
|
||||
$client->click($deleteLink);
|
||||
$client->submit($deleteForm);
|
||||
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
||||
|
||||
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
||||
|
@ -936,7 +936,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
|||
|
||||
$annotationsReset = $em
|
||||
->getRepository(Annotation::class)
|
||||
->findAnnotationsByPageId($entry->getId(), $user->getId());
|
||||
->findByEntryIdAndUserId($entry->getId(), $user->getId());
|
||||
|
||||
$this->assertEmpty($annotationsReset, 'Annotations were reset');
|
||||
|
||||
|
@ -1046,7 +1046,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
|||
|
||||
$annotationsReset = $em
|
||||
->getRepository(Annotation::class)
|
||||
->findAnnotationsByPageId($annotationArchived->getId(), $user->getId());
|
||||
->findByEntryIdAndUserId($annotationArchived->getId(), $user->getId());
|
||||
|
||||
$this->assertEmpty($annotationsReset, 'Annotations were reset');
|
||||
}
|
||||
|
@ -1105,7 +1105,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
|||
|
||||
$annotationsReset = $em
|
||||
->getRepository(Annotation::class)
|
||||
->findAnnotationsByPageId($entry->getId(), $user->getId());
|
||||
->findByEntryIdAndUserId($entry->getId(), $user->getId());
|
||||
|
||||
$this->assertEmpty($annotationsReset, 'Annotations were reset');
|
||||
}
|
||||
|
@ -1354,4 +1354,40 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
|||
$this->assertCount(5, $taggingRules);
|
||||
$this->assertSame('title matches "football"', $taggingRules[4]->getRule());
|
||||
}
|
||||
|
||||
public function testSwitchDisplayThumbnails()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
// Change configuration to show thumbnails
|
||||
$crawler = $client->request('GET', '/config');
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
$form = $crawler->filter('button[id=config_save]')->form();
|
||||
$data = [
|
||||
'config[display_thumbnails]' => true,
|
||||
];
|
||||
$client->submit($form, $data);
|
||||
$client->followRedirect();
|
||||
|
||||
$client->request('GET', '/unread/list');
|
||||
|
||||
$this->assertStringContainsString('class="preview"', $client->getResponse()->getContent());
|
||||
|
||||
// Change configuration to hide thumbnails
|
||||
$crawler = $client->request('GET', '/config');
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
$form = $crawler->filter('button[id=config_save]')->form();
|
||||
$data = [
|
||||
'config[display_thumbnails]' => false,
|
||||
];
|
||||
$client->submit($form, $data);
|
||||
$client->followRedirect();
|
||||
|
||||
$client->request('GET', '/unread/list');
|
||||
|
||||
$this->assertStringNotContainsString('class="preview"', $client->getResponse()->getContent());
|
||||
|
||||
$client->request('GET', '/config/view-mode');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Wallabag\UserBundle\Entity\User;
|
|||
|
||||
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 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"]';
|
||||
|
@ -591,8 +591,8 @@ class EntryControllerTest extends WallabagCoreTestCase
|
|||
|
||||
$this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
|
||||
$this->assertStringContainsString('My updated title hehe :)', $title[0]);
|
||||
$this->assertGreaterThan(1, $stats = $crawler->filter('div[class="tools grey-text"] ul[class=stats] li a[class="tool grey-text"]')->extract(['_text']));
|
||||
$this->assertStringContainsString('example.io', trim($stats[1]));
|
||||
$originUrl = $crawler->filter('[data-tests="entry-origin-url"]')->text();
|
||||
$this->assertStringContainsString('example.io', $originUrl);
|
||||
}
|
||||
|
||||
public function testEditRemoveOriginUrl()
|
||||
|
@ -626,9 +626,8 @@ class EntryControllerTest extends WallabagCoreTestCase
|
|||
$this->assertGreaterThan(1, $title);
|
||||
$this->assertStringContainsString('My updated title hehe :)', $title[0]);
|
||||
|
||||
$stats = $crawler->filter('div[class="tools grey-text"] ul[class=stats] li a[class="tool grey-text"]')->extract(['_text']);
|
||||
$this->assertCount(1, $stats);
|
||||
$this->assertStringNotContainsString('example.io', trim($stats[0]));
|
||||
$originUrl = $crawler->filter('[data-tests="entry-origin-url"]')->extract(['_text']);
|
||||
$this->assertCount(0, $originUrl);
|
||||
}
|
||||
|
||||
public function testToggleArchive()
|
||||
|
@ -1502,7 +1501,7 @@ class EntryControllerTest extends WallabagCoreTestCase
|
|||
'pt_BR',
|
||||
],
|
||||
'es-ES' => [
|
||||
'https://elpais.com/internacional/2022-10-09/ultima-hora-de-la-guerra-en-ucrania-hoy-en-directo.html',
|
||||
'https://elpais.com/internacional/2022-11-03/ultima-hora-de-la-guerra-entre-rusia-y-ucrania-hoy-en-directo.html',
|
||||
'es',
|
||||
],
|
||||
];
|
||||
|
|
|
@ -10,6 +10,8 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
{
|
||||
private $adminEntry;
|
||||
private $bobEntry;
|
||||
private $sameDomainEntry;
|
||||
private $sameDomainEntry2;
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
|
@ -58,7 +60,7 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->assertSame(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testBadEntryId()
|
||||
public function testNonExistingEntryId()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
@ -68,6 +70,21 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->assertSame(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testForbiddenEntryId()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
$content = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository(Entry::class)
|
||||
->findOneByUsernameAndNotArchived('bob');
|
||||
|
||||
$client->request('GET', '/export/' . $content->getId() . '.mobi');
|
||||
|
||||
$this->assertSame(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testEpubExport()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
|
@ -124,7 +141,7 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->assertSame('binary', $headers->get('content-transfer-encoding'));
|
||||
|
||||
ob_start();
|
||||
$crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo-bar');
|
||||
$crawler = $client->request('GET', '/export/tag_entries.pdf?tag=t:foo-bar');
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
|
@ -311,6 +328,26 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at);
|
||||
}
|
||||
|
||||
public function testJsonExportFromSameDomain()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getTestClient();
|
||||
|
||||
ob_start();
|
||||
$crawler = $client->request('GET', '/export/same_domain.json?entry=1');
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$headers = $client->getResponse()->headers;
|
||||
$this->assertSame('application/json', $headers->get('content-type'));
|
||||
$this->assertSame('attachment; filename="Same domain articles.json"', $headers->get('content-disposition'));
|
||||
$this->assertSame('UTF-8', $headers->get('content-transfer-encoding'));
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(4, $content);
|
||||
}
|
||||
|
||||
private function setUpForJsonExportFromSearch()
|
||||
{
|
||||
$client = $this->getTestClient();
|
||||
|
|
|
@ -237,42 +237,46 @@ class FeedControllerTest extends WallabagCoreTestCase
|
|||
$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);
|
||||
|
||||
// We have to flush and sleep here to be sure that $entry1 and $entry4 have different updatedAt values
|
||||
$em->flush();
|
||||
sleep(2);
|
||||
|
||||
$property = (new \ReflectionObject($entry1))->getProperty('updatedAt');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($entry1, $day4);
|
||||
|
||||
$em->flush();
|
||||
|
||||
$client = $this->getTestClient();
|
||||
|
||||
// tag foo - without sort
|
||||
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo');
|
||||
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/t: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());
|
||||
|
||||
// tag foo - with sort created
|
||||
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo?sort=created');
|
||||
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/t: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');
|
||||
$crawler = $client->request('GET', '/feed/admin/SUPERTOKEN/tags/t: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');
|
||||
$client->request('GET', '/feed/admin/SUPERTOKEN/tags/t:foo?sort=invalid');
|
||||
$this->assertSame(400, $client->getResponse()->getStatusCode());
|
||||
|
||||
// tag foo/3000
|
||||
$client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000');
|
||||
$client->request('GET', '/feed/admin/SUPERTOKEN/tags/t:foo/3000');
|
||||
$this->assertSame(302, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
|
|
|
@ -32,12 +32,6 @@ class SecurityControllerTest extends WallabagCoreTestCase
|
|||
{
|
||||
$client = $this->getTestClient();
|
||||
|
||||
if (!$client->getContainer()->getParameter('twofactor_auth')) {
|
||||
$this->markTestSkipped('twofactor_auth is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$client->followRedirects();
|
||||
|
||||
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
||||
|
@ -65,12 +59,6 @@ class SecurityControllerTest extends WallabagCoreTestCase
|
|||
{
|
||||
$client = $this->getTestClient();
|
||||
|
||||
if (!$client->getContainer()->getParameter('twofactor_auth')) {
|
||||
$this->markTestSkipped('twofactor_auth is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$client->followRedirects();
|
||||
|
||||
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
||||
|
|
|
@ -560,5 +560,12 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
|
||||
$this->assertContains('title', $tags);
|
||||
}
|
||||
|
||||
$tag = $client->getContainer()
|
||||
->get(EntityManagerInterface::class)
|
||||
->getRepository(Tag::class)
|
||||
->findByLabelsAndUser(['title'], $this->getLoggedInUserId());
|
||||
|
||||
$this->assertCount(1, $tag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ class LocaleListenerTest extends TestCase
|
|||
$dispatcher->addSubscriber($listener);
|
||||
|
||||
$dispatcher->dispatch(
|
||||
KernelEvents::REQUEST,
|
||||
$event
|
||||
$event,
|
||||
KernelEvents::REQUEST
|
||||
);
|
||||
|
||||
$this->assertSame('fr', $request->getLocale());
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace Tests\Wallabag\CoreBundle\Event\Subscriber;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
|
||||
|
@ -18,20 +18,20 @@ class TablePrefixSubscriberTest extends TestCase
|
|||
public function dataForPrefix()
|
||||
{
|
||||
return [
|
||||
['wallabag_', User::class, '`user`', 'user', 'wallabag_user', '"wallabag_user"', new PostgreSqlPlatform()],
|
||||
['wallabag_', User::class, '`user`', 'user', 'wallabag_user', '`wallabag_user`', new MySqlPlatform()],
|
||||
['wallabag_', User::class, '`user`', 'user', 'wallabag_user', '"wallabag_user"', new PostgreSQLPlatform()],
|
||||
['wallabag_', User::class, '`user`', 'user', 'wallabag_user', '`wallabag_user`', new MySQLPlatform()],
|
||||
['wallabag_', User::class, '`user`', 'user', 'wallabag_user', '"wallabag_user"', new SqlitePlatform()],
|
||||
|
||||
['wallabag_', User::class, 'user', 'user', 'wallabag_user', 'wallabag_user', new PostgreSqlPlatform()],
|
||||
['wallabag_', User::class, 'user', 'user', 'wallabag_user', 'wallabag_user', new MySqlPlatform()],
|
||||
['wallabag_', User::class, 'user', 'user', 'wallabag_user', 'wallabag_user', new PostgreSQLPlatform()],
|
||||
['wallabag_', User::class, 'user', 'user', 'wallabag_user', 'wallabag_user', new MySQLPlatform()],
|
||||
['wallabag_', User::class, 'user', 'user', 'wallabag_user', 'wallabag_user', new SqlitePlatform()],
|
||||
|
||||
['', User::class, '`user`', 'user', 'user', '"user"', new PostgreSqlPlatform()],
|
||||
['', User::class, '`user`', 'user', 'user', '`user`', new MySqlPlatform()],
|
||||
['', User::class, '`user`', 'user', 'user', '"user"', new PostgreSQLPlatform()],
|
||||
['', User::class, '`user`', 'user', 'user', '`user`', new MySQLPlatform()],
|
||||
['', User::class, '`user`', 'user', 'user', '"user"', new SqlitePlatform()],
|
||||
|
||||
['', User::class, 'user', 'user', 'user', 'user', new PostgreSqlPlatform()],
|
||||
['', User::class, 'user', 'user', 'user', 'user', new MySqlPlatform()],
|
||||
['', User::class, 'user', 'user', 'user', 'user', new PostgreSQLPlatform()],
|
||||
['', User::class, 'user', 'user', 'user', 'user', new MySQLPlatform()],
|
||||
['', User::class, 'user', 'user', 'user', 'user', new SqlitePlatform()],
|
||||
];
|
||||
}
|
||||
|
@ -115,6 +115,6 @@ class TablePrefixSubscriberTest extends TestCase
|
|||
|
||||
$this->assertSame('yo_entry', $metaDataEvent->getClassMetadata()->getTableName());
|
||||
$this->assertSame('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']);
|
||||
$this->assertSame('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new MySqlPlatform()));
|
||||
$this->assertSame('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new MySQLPlatform()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -859,6 +859,16 @@ class ContentProxyTest extends TestCase
|
|||
|
||||
public function testPdfWithInvalidCharacterInTitleRemoveInvalidCharacter()
|
||||
{
|
||||
/*
|
||||
* I spend too much time on trying to solve the problem of that test.
|
||||
* Starting with PHP 8.1 this test fails because the string with invalid character is detected as WINDOWS-1252 and then converted.
|
||||
* In PHP < 8.1, the string encoding can't be detected and nothing is then converted.
|
||||
* So the removal of the invalid char happens in `sanitizeUTF8Text`
|
||||
*
|
||||
* So, I don't understand why the string with invalid char is detected as WINDOWS-1252 in PHP 8.1 and not before.
|
||||
*/
|
||||
$this->markTestSkipped('Encoding issue in PHP >= 8.1');
|
||||
|
||||
// See http://graphemica.com for more info about the characters
|
||||
// '😻ℤ<F09F98BB>z' (U+1F63B or F09F98BB; U+2124 or E284A4; invalid character 81; U+007A or 7A) in hexadecimal and UTF-8
|
||||
// 0x81 is not a valid character for UTF16, UTF8 and WINDOWS-1252
|
||||
|
|
|
@ -184,6 +184,23 @@ class DownloadImagesTest extends TestCase
|
|||
$this->assertStringNotContainsString('f_auto,q_auto', $res, 'Image srcset attribute were not replaced');
|
||||
}
|
||||
|
||||
public function testProcessImageWithNumericHtmlEntitySeparator()
|
||||
{
|
||||
$httpMockClient = new HttpMockClient();
|
||||
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/jpeg'], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
|
||||
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/jpeg'], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
|
||||
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/jpeg'], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg')));
|
||||
|
||||
$logHandler = new TestHandler();
|
||||
$logger = new Logger('test', [$logHandler]);
|
||||
|
||||
$download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
|
||||
// wordpress.com sites using & as an & alternative
|
||||
$res = $download->processHtml(123, '<img srcset="https://example.com/20191204_133626-scaled.jpg?strip=info&w=600&ssl=1 600w,https://example.com/20191204_133626-scaled.jpg?strip=info&w=900&ssl=1 900w" src="https://example.com/20191204_133626-scaled.jpg?ssl=1"/>', 'https://example.com/about/');
|
||||
|
||||
$this->assertStringNotContainsString('https://example.com', $res, 'Image srcset attribute were not replaced');
|
||||
}
|
||||
|
||||
public function testProcessImageWithNullPath()
|
||||
{
|
||||
$httpMockClient = new HttpMockClient();
|
||||
|
@ -248,4 +265,19 @@ class DownloadImagesTest extends TestCase
|
|||
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
|
||||
public function testFollowRedirection()
|
||||
{
|
||||
$httpMockClient = new HttpMockClient();
|
||||
$httpMockClient->addResponse(new Response(301, ['content-type' => 'image/png', 'location' => '/final-path.png']));
|
||||
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
|
||||
|
||||
$logHandler = new TestHandler();
|
||||
$logger = new Logger('test', [$logHandler]);
|
||||
|
||||
$download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
|
||||
$res = $download->processSingleImage(123, '', 'https://example.com/unnamed.png');
|
||||
|
||||
$this->assertStringContainsString('/assets/images/9/b/9b0ead26/66953334.png', $res, "Fetch client didn't follow the HTTP redirection");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Tests\Wallabag\CoreBundle\ParamConverter;
|
||||
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Tests\Wallabag\CoreBundle\Twig;
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\CoreBundle\Repository\TagRepository;
|
||||
use Wallabag\CoreBundle\Twig\WallabagExtension;
|
||||
|
|
|
@ -57,8 +57,8 @@ class AuthenticationFailureListenerTest extends TestCase
|
|||
);
|
||||
|
||||
$this->dispatcher->dispatch(
|
||||
AuthenticationEvents::AUTHENTICATION_FAILURE,
|
||||
$event
|
||||
$event,
|
||||
AuthenticationEvents::AUTHENTICATION_FAILURE
|
||||
);
|
||||
|
||||
$records = $this->logHandler->getRecords();
|
||||
|
|
|
@ -38,6 +38,7 @@ class CreateConfigListenerTest extends TestCase
|
|||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
$session
|
||||
);
|
||||
|
||||
|
@ -72,8 +73,8 @@ class CreateConfigListenerTest extends TestCase
|
|||
->method('flush');
|
||||
|
||||
$this->dispatcher->dispatch(
|
||||
FOSUserEvents::REGISTRATION_COMPLETED,
|
||||
$event
|
||||
$event,
|
||||
FOSUserEvents::REGISTRATION_COMPLETED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Tests\Wallabag\UserBundle\Mailer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
@ -10,19 +12,10 @@ use Wallabag\UserBundle\Mailer\AuthCodeMailer;
|
|||
|
||||
class AuthCodeMailerTest extends TestCase
|
||||
{
|
||||
protected $mailer;
|
||||
protected $spool;
|
||||
protected $twig;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->spool = new CountableMemorySpool();
|
||||
$transport = new \Swift_Transport_SpoolTransport(
|
||||
new \Swift_Events_SimpleEventDispatcher(),
|
||||
$this->spool
|
||||
);
|
||||
$this->mailer = new \Swift_Mailer($transport);
|
||||
|
||||
$twigTemplate = <<<'TWIG'
|
||||
{% block subject %}subject{% endblock %}
|
||||
{% block body_html %}html body {{ code }}{% endblock %}
|
||||
|
@ -34,6 +27,31 @@ TWIG;
|
|||
|
||||
public function testSendEmail()
|
||||
{
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$mailer->expects($this->once())
|
||||
->method('send')
|
||||
->with($this->callback(function ($email) {
|
||||
$this->assertSame('subject', $email->getSubject());
|
||||
$this->assertSame('text body http://0.0.0.0/support', $email->getTextBody());
|
||||
$this->assertSame('html body 666666', $email->getHtmlBody());
|
||||
|
||||
$this->assertCount(1, $email->getTo());
|
||||
/** @var Address[] $addresses */
|
||||
$addresses = $email->getTo();
|
||||
$this->assertInstanceOf(Address::class, $addresses[0]);
|
||||
$this->assertSame('', $addresses[0]->getName());
|
||||
$this->assertSame('test@wallabag.io', $addresses[0]->getAddress());
|
||||
|
||||
$this->assertCount(1, $email->getFrom());
|
||||
/** @var Address[] $addresses */
|
||||
$addresses = $email->getFrom();
|
||||
$this->assertInstanceOf(Address::class, $addresses[0]);
|
||||
$this->assertSame('wallabag test', $addresses[0]->getName());
|
||||
$this->assertSame('nobody@test.io', $addresses[0]->getAddress());
|
||||
|
||||
return true;
|
||||
}));
|
||||
|
||||
$user = new User();
|
||||
$user->setEmailTwoFactor(true);
|
||||
$user->setEmailAuthCode(666666);
|
||||
|
@ -41,7 +59,7 @@ TWIG;
|
|||
$user->setName('Bob');
|
||||
|
||||
$authCodeMailer = new AuthCodeMailer(
|
||||
$this->mailer,
|
||||
$mailer,
|
||||
$this->twig,
|
||||
'nobody@test.io',
|
||||
'wallabag test',
|
||||
|
@ -50,14 +68,5 @@ TWIG;
|
|||
);
|
||||
|
||||
$authCodeMailer->sendAuthCode($user);
|
||||
|
||||
$this->assertCount(1, $this->spool);
|
||||
|
||||
$msg = $this->spool->getMessages()[0];
|
||||
$this->assertArrayHasKey('test@wallabag.io', $msg->getTo());
|
||||
$this->assertSame(['nobody@test.io' => 'wallabag test'], $msg->getFrom());
|
||||
$this->assertSame('subject', $msg->getSubject());
|
||||
$this->assertStringContainsString('text body http://0.0.0.0/support', $msg->toString());
|
||||
$this->assertStringContainsString('html body 666666', $msg->toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Wallabag\UserBundle\Mailer;
|
||||
|
||||
/**
|
||||
* @see https://www.pmg.com/blog/integration-testing-swift-mailer/
|
||||
*/
|
||||
final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable
|
||||
{
|
||||
public function count()
|
||||
{
|
||||
return \count($this->messages);
|
||||
}
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue