Compare commits

...

26 Commits
2.3.7 ... 2.3.8

Author SHA1 Message Date
9bbafdaad4 Release wallabag 2.3.8 2019-05-14 11:24:07 +02:00
227a1a27f1 Merge pull request #3966 from wallabag/prepare-2.3.8
Prepare 2.3.8 release
2019-05-14 11:14:37 +02:00
cc181629a0 Prepare 2.3.8 release 2019-05-14 10:16:46 +02:00
eb06edba0c Merge pull request #3964 from wallabag/fix/intl
Fix Intl Locale issue
2019-05-14 09:36:46 +02:00
b50ecd0c8a Fix Intl Locale issue
Some issue appeared after the release of PHP 7.2.17 about Intl Memory
Leak / infinite loop.
To fix it we should upgrade to Symfony 3.4 (which is done in wallabag
2.4) but for the 2.3 branch, we'll use a temporary fix for the Locale
issue.
2019-05-13 14:04:33 +02:00
a73cb8a689 Merge pull request #3922 from burkemw3/patch-5
Remove preview picture from share view page for #1875
2019-05-13 06:40:16 +02:00
295b714426 Merge pull request #3943 from wallabag/img-referrer
Enable no-referrer on img tags, enable strict-origin-when-cross-origin by default
2019-05-12 23:44:33 +02:00
19822ecb31 Remove preview picture from share view page for #1875
Essentially, same as commit 038fccd for single entry views. From that commit:
> Showing the preview picture usually leads to showing a duplicate
> image, and frequently leads to showing duplicate images directly
> adjacent to each other.
2019-05-12 12:32:22 -04:00
9ae5bd9e10 assets: regenerate material.css
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
2019-05-10 23:08:23 +02:00
2dbb5b2307 Enable no-referrer on img tags, enable strict-origin-when-cross-origin by default
Fixes #3889

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
2019-05-10 23:07:26 +02:00
570113208b Merge pull request #3942 from wallabag/issue-3838
material: add metadata to list view
2019-05-09 15:45:07 +03:00
4b5b228650 material: add metadata to list view
Add reading time and creation date to rows of list view.
Refactor styles using a sass mixin.

Fixes #3838

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
2019-05-01 15:47:48 +02:00
ea54c2adb1 Merge pull request #3937 from wallabag/fix/credential-subdomain
Add ability to match many domains for credentials
2019-04-27 10:58:26 +02:00
35359bd3c6 Adding more tests to cover different scenario 2019-04-24 15:28:15 +02:00
ff8f338dc2 FIx unrelated failing test 2019-04-23 22:48:04 +02:00
f45496336f Add ability to match many domains for credentials
Instead of fetching one domain, we use the same method as in site config (to retrieve the matching file) and handle api.example.org, example.org, .org (yes the last one isn’t useful).
If one of these match, we got it and use it.
2019-04-23 22:39:31 +02:00
bfd69c74e5 Merge pull request #3909 from wallabag/fix/html-not-defined
Fix PHP warning
2019-03-18 09:26:33 +01:00
8ab5dcc467 Merge pull request #3908 from wallabag/epub-issue-3642
epub: fix exception when articles have the same title
2019-03-18 09:26:16 +01:00
893f107fa1 Merge pull request #3860 from baurmatt/fix/posix_compatibility
Make dev/install/update script posix compatible
2019-03-18 09:25:00 +01:00
8ca858ee73 Fix PHP warning
Looks like sometimes (usually from import) the `html` key isn’t available.
2019-03-18 06:23:41 +01:00
41d476d7e7 epub: fix exception when articles have the same title
This commit fixes an exception occuring when exporting as epub several
articles with the same title. The chapter filename is now derived from
title and url.

Fixes #3642

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
2019-03-17 23:36:10 +01:00
7c553a6017 Properly source require.sh
Fixes #3571.
2019-03-12 15:44:38 +01:00
a48ff25d4c Merge pull request #3901 from wallabag/fix-pr-3893
material: fix left padding on non-entry pages introduced by #3893
2019-03-09 12:19:31 +01:00
cf0010cf4a material: fix left padding on non-entry pages introduced by #3893
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
2019-03-09 00:27:50 +01:00
13d2fe6d2e Merge pull request #3897 from wallabag/2.3.8-dev
Jump to 2.3.8-dev
2019-03-04 15:23:06 +01:00
3d7a1f4caf Jump to 2.3.8-dev 2019-03-04 13:49:23 +01:00
34 changed files with 8039 additions and 85 deletions

View File

@ -73,7 +73,7 @@ before_script:
- sudo swapon -s
script:
- travis_wait bash composer install -o --no-interaction --no-progress --prefer-dist
- travis_wait bash composer update -o --no-interaction --no-progress --prefer-dist
- echo "travis_fold:start:prepare"
- make prepare DB=$DB
- echo "travis_fold:end:prepare"

View File

@ -1,5 +1,21 @@
# Changelog
## [2.3.8](https://github.com/wallabag/wallabag/tree/2.3.8)
[Full Changelog](https://github.com/wallabag/wallabag/compare/2.3.7...2.3.8)
### Fixes
- Jump to 2.3.8-dev [#3897](https://github.com/wallabag/wallabag/pull/3897)
- material: fix left padding on non-entry pages [#3901](https://github.com/wallabag/wallabag/pull/3901)
- Make dev/install/update script posix compatible [#3860](https://github.com/wallabag/wallabag/pull/3860)
- epub: fix exception when articles have the same title [#3908](https://github.com/wallabag/wallabag/pull/3908)
- Fix PHP warning [#3909](https://github.com/wallabag/wallabag/pull/3909)
- Add ability to match many domains for credentials [#3937](https://github.com/wallabag/wallabag/pull/3937)
- material: add metadata to list view [#3942](https://github.com/wallabag/wallabag/pull/3942)
- Enable no-referrer on img tags, enable strict-origin-when-cross-origin by default [#3943](https://github.com/wallabag/wallabag/pull/3943)
- Remove preview picture from share view page#3922
- Fix Intl Locale issue [#3964](https://github.com/wallabag/wallabag/pull/3964)
## [2.3.7](https://github.com/wallabag/wallabag/tree/2.3.7)
[Full Changelog](https://github.com/wallabag/wallabag/compare/2.3.6...2.3.7)

View File

@ -18,6 +18,24 @@ main {
overflow: hidden;
}
@mixin mixin-reading-time {
.reading-time {
display: inline-flex;
vertical-align: middle;
.card-reading-time,
.card-created-at {
display: inline-flex;
}
span {
margin-right: 5px;
}
@content;
}
}
.card {
.card-content .card-title,
.card-reveal .card-title {
@ -98,19 +116,7 @@ main {
margin-right: 5px !important;
}
.reading-time {
display: inline-flex;
vertical-align: middle;
.card-reading-time,
.card-created-at {
display: inline-flex;
}
span {
margin-right: 5px;
}
}
@include mixin-reading-time;
}
.card-image {
@ -224,10 +230,18 @@ a.original:not(.waves-effect) {
}
div.metadata {
overflow: hidden;
height: 1.5em;
display: flex;
ul.tags {
margin-left: 4px;
}
.chip {
background-color: $blueAccentColor;
padding: 0 7px;
margin: auto 2px;
margin: auto 1px;
border-radius: 6px;
line-height: 22px;
height: 22px;
@ -244,6 +258,16 @@ a.original:not(.waves-effect) {
padding-left: 8px;
}
}
@include mixin-reading-time {
padding: 0 5px;
flex-wrap: wrap;
margin-left: auto;
i.material-icons {
font-size: 20px;
}
}
}
div.card-content {

View File

@ -19,7 +19,7 @@
}
@media screen and (min-width: 993px) {
main #content {
body.entry main #content {
padding-left: 70px;
}
}
@ -173,6 +173,10 @@
.row .col {
padding: 0;
}
.card-stacked div.metadata .reading-time {
display: none;
}
}
@media screen and (max-width: 310px),

View File

@ -1,5 +1,5 @@
wallabag_core:
version: 2.3.7
version: 2.3.8
paypal_url: "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9UBA65LG3FX9Y&lc=gb"
languages:
en: 'English'

View File

@ -86,7 +86,8 @@
"friendsofsymfony/jsrouting-bundle": "^1.6.3",
"bdunogier/guzzle-site-authenticator": "^1.0.0",
"defuse/php-encryption": "^2.1",
"html2text/html2text": "^4.1"
"html2text/html2text": "^4.1",
"sulu/symfony-intl-fix": "^1.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "~2.2",
@ -125,7 +126,11 @@
},
"autoload": {
"psr-4": { "Wallabag\\": "src/Wallabag/" },
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ],
"exclude-from-classmap": [
"vendor/symfony/intl/Locale.php",
"vendor/symfony/symfony/src/Symfony/Component/Intl/Locale.php"
]
},
"autoload-dev": {
"psr-4": { "Tests\\": "tests/" }

7748
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,10 +3,14 @@
# eg: `sh dev.sh`
COMPOSER_COMMAND='composer'
REQUIRE_FILE='scripts/require.sh'
DIR="${BASH_SOURCE}"
if [ ! -d "$DIR" ]; then DIR="$PWD/scripts"; fi
. "$DIR/require.sh"
if [ ! -f "$REQUIRE_FILE" ]; then
echo "Cannot find $REQUIRE_FILE"
exit 1
fi
. "$REQUIRE_FILE"
$COMPOSER_COMMAND install
php bin/console wallabag:install

View File

@ -25,10 +25,14 @@ if [ "$IGNORE_ROOT" -eq 0 ] && [ "$EUID" == "0" ]; then
fi
COMPOSER_COMMAND='composer'
REQUIRE_FILE='scripts/require.sh'
DIR="${BASH_SOURCE}"
if [ ! -d "$DIR" ]; then DIR="$PWD/scripts"; fi
. "$DIR/require.sh"
if [ ! -f "$REQUIRE_FILE" ]; then
echo "Cannot find $REQUIRE_FILE"
exit 1
fi
. "$REQUIRE_FILE"
TAG=$(git describe --tags $(git rev-list --tags --max-count=1))

View File

@ -28,10 +28,14 @@ set -e
set -u
COMPOSER_COMMAND='composer'
REQUIRE_FILE='scripts/require.sh'
DIR="${BASH_SOURCE}"
if [ ! -d "$DIR" ]; then DIR="$PWD/scripts"; fi
. "$DIR/require.sh"
if [ ! -f "$REQUIRE_FILE" ]; then
echo "Cannot find $REQUIRE_FILE"
exit 1
fi
. "$REQUIRE_FILE"
rm -rf var/cache/*
git fetch origin

View File

@ -5,19 +5,38 @@ namespace Wallabag\CoreBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Wallabag\CoreBundle\Entity\SiteCredential;
class LoadSiteCredentialData extends AbstractFixture implements OrderedFixtureInterface
class LoadSiteCredentialData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
/**
* @var ContainerInterface
*/
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$credential = new SiteCredential($this->getReference('admin-user'));
$credential->setHost('example.com');
$credential->setUsername('foo');
$credential->setPassword('bar');
$credential->setHost('.super.com');
$credential->setUsername($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('.super'));
$credential->setPassword($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
$manager->persist($credential);
$credential = new SiteCredential($this->getReference('admin-user'));
$credential->setHost('paywall.example.com');
$credential->setUsername($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('paywall.example'));
$credential->setPassword($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
$manager->persist($credential);

View File

@ -62,11 +62,24 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
$host = substr($host, 4);
}
$credentials = null;
if ($this->currentUser) {
$credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId());
if (!$this->currentUser) {
$this->logger->debug('Auth: no current user defined.');
return false;
}
$hosts = [$host];
// will try to see for a host without the first subdomain (fr.example.org & .example.org)
$split = explode('.', $host);
if (\count($split) > 1) {
// remove first subdomain
array_shift($split);
$hosts[] = '.' . implode('.', $split);
}
$credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId());
if (null === $credentials) {
$this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);

View File

@ -47,6 +47,7 @@ class ContentProxy
*/
public function updateEntry(Entry $entry, $url, array $content = [], $disableContentUpdate = false)
{
$this->graby->toggleImgNoReferrer(true);
if (!empty($content['html'])) {
$content['html'] = $this->graby->cleanupHtml($content['html'], $url);
}
@ -256,18 +257,17 @@ class ContentProxy
$entry->setTitle($content['open_graph']['og_title']);
}
$html = $content['html'];
if (false === $html) {
$html = $this->fetchingErrorMessage;
if (empty($content['html'])) {
$content['html'] = $this->fetchingErrorMessage;
if (!empty($content['open_graph']['og_description'])) {
$html .= '<p><i>But we found a short description: </i></p>';
$html .= $content['open_graph']['og_description'];
$content['html'] .= '<p><i>But we found a short description: </i></p>';
$content['html'] .= $content['open_graph']['og_description'];
}
}
$entry->setContent($html);
$entry->setReadingTime(Utils::getReadingTime($html));
$entry->setContent($content['html']);
$entry->setReadingTime(Utils::getReadingTime($content['html']));
if (!empty($content['status'])) {
$entry->setHttpStatus($content['status']);

View File

@ -188,7 +188,7 @@ class EntriesExport
foreach ($entry->getTags() as $tag) {
$book->setSubject($tag->getLabel());
}
$filename = sha1($entry->getTitle());
$filename = sha1(sprintf('%s:%s', $entry->getUrl(), $entry->getTitle()));
$publishedBy = $entry->getPublishedBy();
$authors = $this->translator->trans('export.unknown');

View File

@ -19,16 +19,16 @@ class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
/**
* Retrieve one username/password for the given host and userId.
*
* @param string $host
* @param int $userId
* @param array $hosts An array of host to look for
* @param int $userId
*
* @return array|null
*/
public function findOneByHostAndUser($host, $userId)
public function findOneByHostsAndUser($hosts, $userId)
{
$res = $this->createQueryBuilder('s')
->select('s.username', 's.password')
->where('s.host = :hostname')->setParameter('hostname', $host)
->where('s.host IN (:hosts)')->setParameter('hosts', $hosts)
->andWhere('s.user = :userId')->setParameter('userId', $userId)
->setMaxResults(1)
->getQuery()

View File

@ -550,7 +550,7 @@ site_credential:
# create_new_one: Create a new credential
# form:
# username_label: 'Username'
# host_label: 'Host'
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
# password_label: 'Password'
# save: Save
# delete: Delete

View File

@ -550,7 +550,7 @@ site_credential:
create_new_one: 'Einen neuen Seitenzugang anlegen'
form:
username_label: 'Benutzername'
host_label: 'Host'
host_label: 'Host (subdomain.example.org, .example.org, etc.)'
password_label: 'Passwort'
save: 'Speichern'
delete: 'Löschen'

View File

@ -550,7 +550,7 @@ site_credential:
create_new_one: Create a new credential
form:
username_label: 'Username'
host_label: 'Host'
host_label: 'Host (subdomain.example.org, .example.org, etc.)'
password_label: 'Password'
save: Save
delete: Delete

View File

@ -550,7 +550,7 @@ site_credential:
# create_new_one: Create a new credential
# form:
# username_label: 'Username'
# host_label: 'Host'
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
# password_label: 'Password'
# save: Save
# delete: Delete

View File

@ -550,7 +550,7 @@ site_credential:
# create_new_one: Create a new credential
# form:
# username_label: 'Username'
# host_label: 'Host'
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
# password_label: 'Password'
# save: Save
# delete: Delete

View File

@ -550,7 +550,7 @@ site_credential:
create_new_one: Créer un nouvel accès à un site
form:
username_label: 'Identifiant'
host_label: 'Domaine'
host_label: 'Domaine (subdomain.example.org, .example.org, etc.)'
password_label: 'Mot de passe'
save: "Sauvegarder"
delete: "Supprimer"

View File

@ -550,7 +550,7 @@ site_credential:
# create_new_one: Create a new credential
# form:
# username_label: 'Username'
# host_label: 'Host'
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
# password_label: 'Password'
# save: Save
# delete: Delete

View File

@ -550,7 +550,7 @@ site_credential:
create_new_one: Crear un novèl identificant
form:
username_label: "Nom d'utilizaire"
host_label: 'Òste'
host_label: 'Òste (subdomain.example.org, .example.org, etc.)'
password_label: 'Senhal'
save: 'Enregistrar'
delete: 'Suprimir'

View File

@ -550,7 +550,7 @@ site_credential:
create_new_one: Stwórz nowe poświadczenie
form:
username_label: 'Nazwa użytkownika'
host_label: 'Host'
host_label: 'Host (subdomain.example.org, .example.org, etc.)'
password_label: 'Hasło'
save: Zapisz
delete: Usuń

View File

@ -550,7 +550,7 @@ site_credential:
# create_new_one: Create a new credential
form:
# username_label: 'Username'
# host_label: 'Host'
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
# password_label: 'Password'
save: 'Salvar'
delete: 'Apagar'

View File

@ -550,7 +550,7 @@ site_credential:
# create_new_one: Create a new credential
# form:
# username_label: 'Username'
# host_label: 'Host'
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
# password_label: 'Password'
# save: Save
# delete: Delete

View File

@ -548,7 +548,7 @@ site_credential:
create_new_one: สร้างข้อมูลส่วนตัวใหม่
form:
username_label: 'ชื่อผู้ใช้'
host_label: 'โฮส'
host_label: 'โฮส (subdomain.example.org, .example.org, etc.)'
password_label: 'รหัสผ่าน'
save: บันทึก
delete: ลบ

View File

@ -8,6 +8,7 @@
{% block head %}
<meta name="viewport" content="initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="referrer" content="strict-origin-when-cross-origin">
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=10">
<![endif]-->

View File

@ -29,9 +29,6 @@
<h1>{{ entry.title|e|raw }}</h1>
<a href="{{ entry.url|e }}" target="_blank" rel="noopener" title="{{ 'entry.view.original_article'|trans }} : {{ entry.title|e|raw }}" class="tool">{{ entry.domainName|removeWww }}</a>
<p class="shared-by">{{ "entry.public.shared_by_wallabag"|trans({'%wallabag_instance%': url('homepage'), '%username%': entry.user.username})|raw }}.</p>
{% if entry.previewPicture is not null %}
<img class="preview" src="{{ entry.previewPicture }}" alt="{{ entry.title|striptags|e('html_attr') }}" />
{% endif %}
</header>
<article class="block">
{{ entry.content | raw }}

View File

@ -8,8 +8,11 @@
<div class="{{ subClass|default('original grey-text') }}">
<a href="{{ entry.url|e }}" target="_blank" title="{{ entry.domainName|removeWww }}" class="tool grey-text">{{ entry.domainName|removeWww }}</a>
{% if withTags is defined %}
{% if withMetadata is defined %}
{% include "@WallabagCore/themes/material/Entry/_tags.html.twig" with {'tags': entry.tags | slice(0, 3), 'entryId': entry.id, 'listClass': ' hide-on-med-and-down'} only %}
<div class="reading-time grey-text">
<div class="card-reading-time">{% include "@WallabagCore/themes/material/Entry/_reading_time.html.twig" with {'entry': entry} only %}</div>
</div>
{% endif %}
</div>
</div>

View File

@ -5,7 +5,7 @@
<span class="preview{{ previewClassModifier }}" style="background-image: url({{ entry.previewPicture | default(asset('wallassets/themes/_global/img/logo-square.svg')) }})"></span>
</a>
</div>
{% include "@WallabagCore/themes/material/Entry/Card/_content.html.twig" with {'entry': entry, 'withTags': true, 'subClass': 'metadata'} only %}
{% include "@WallabagCore/themes/material/Entry/Card/_content.html.twig" with {'entry': entry, 'withMetadata': true, 'subClass': 'metadata'} only %}
<ul class="tools-list hide-on-small-only">
<li>
<a title="{{ 'entry.list.toogle_as_read'|trans }}" class="tool grey-text" href="{{ path('archive_entry', { 'id': entry.id }) }}"><i class="material-icons">{% if entry.isArchived == 0 %}done{% else %}unarchive{% endif %}</i></a>

View File

@ -166,7 +166,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->assertSame($this->url, $content->getUrl());
$this->assertContains('Google', $content->getTitle());
$this->assertSame('fr', $content->getLanguage());
$this->assertSame('2016-04-07 19:01:35', $content->getPublishedAt()->format('Y-m-d H:i:s'));
$this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
$this->assertArrayHasKey('x-frame-options', $content->getHeaders());
$client->getContainer()->get('craue_config')->set('store_article_headers', 0);
}

View File

@ -5,26 +5,22 @@ namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator;
use Graby\SiteConfig\SiteConfig as GrabySiteConfig;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder;
class GrabySiteConfigBuilderTest extends TestCase
class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
{
/** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */
protected $builder;
public function testBuildConfigExists()
{
/* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
$grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder')
->disableOriginalConstructor()
->getMock();
$grabySiteConfig = new GrabySiteConfig();
$grabySiteConfig->requires_login = true;
$grabySiteConfig->login_uri = 'http://www.example.com/login';
$grabySiteConfig->login_uri = 'http://api.example.com/login';
$grabySiteConfig->login_username_field = 'login';
$grabySiteConfig->login_password_field = 'password';
$grabySiteConfig->login_extra_fields = ['field=value'];
@ -32,7 +28,7 @@ class GrabySiteConfigBuilderTest extends TestCase
$grabyConfigBuilderMock
->method('buildForHost')
->with('example.com')
->with('api.example.com')
->will($this->returnValue($grabySiteConfig));
$logger = new Logger('foo');
@ -43,8 +39,8 @@ class GrabySiteConfigBuilderTest extends TestCase
->disableOriginalConstructor()
->getMock();
$siteCrentialRepo->expects($this->once())
->method('findOneByHostAndUser')
->with('example.com', 1)
->method('findOneByHostsAndUser')
->with(['api.example.com', '.example.com'], 1)
->willReturn(['username' => 'foo', 'password' => 'bar']);
$user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
@ -59,18 +55,18 @@ class GrabySiteConfigBuilderTest extends TestCase
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
$this->builder = new GrabySiteConfigBuilder(
$builder = new GrabySiteConfigBuilder(
$grabyConfigBuilderMock,
$tokenStorage,
$siteCrentialRepo,
$logger
);
$config = $this->builder->buildForHost('www.example.com');
$config = $builder->buildForHost('api.example.com');
$this->assertSame('example.com', $config->getHost());
$this->assertSame('api.example.com', $config->getHost());
$this->assertTrue($config->requiresLogin());
$this->assertSame('http://www.example.com/login', $config->getLoginUri());
$this->assertSame('http://api.example.com/login', $config->getLoginUri());
$this->assertSame('login', $config->getUsernameField());
$this->assertSame('password', $config->getPasswordField());
$this->assertSame(['field' => 'value'], $config->getExtraFields());
@ -85,7 +81,6 @@ class GrabySiteConfigBuilderTest extends TestCase
public function testBuildConfigDoesntExist()
{
/* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
$grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
->disableOriginalConstructor()
->getMock();
@ -103,8 +98,8 @@ class GrabySiteConfigBuilderTest extends TestCase
->disableOriginalConstructor()
->getMock();
$siteCrentialRepo->expects($this->once())
->method('findOneByHostAndUser')
->with('unknown.com', 1)
->method('findOneByHostsAndUser')
->with(['unknown.com', '.com'], 1)
->willReturn(null);
$user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
@ -119,14 +114,14 @@ class GrabySiteConfigBuilderTest extends TestCase
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
$this->builder = new GrabySiteConfigBuilder(
$builder = new GrabySiteConfigBuilder(
$grabyConfigBuilderMock,
$tokenStorage,
$siteCrentialRepo,
$logger
);
$config = $this->builder->buildForHost('unknown.com');
$config = $builder->buildForHost('unknown.com');
$this->assertFalse($config);
@ -134,4 +129,121 @@ class GrabySiteConfigBuilderTest extends TestCase
$this->assertCount(1, $records, 'One log was recorded');
}
public function testBuildConfigUserNotDefined()
{
$grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
->disableOriginalConstructor()
->getMock();
$grabyConfigBuilderMock
->method('buildForHost')
->with('unknown.com')
->will($this->returnValue(new GrabySiteConfig()));
$logger = new Logger('foo');
$handler = new TestHandler();
$logger->pushHandler($handler);
$siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository')
->disableOriginalConstructor()
->getMock();
$tokenStorage = new TokenStorage();
$builder = new GrabySiteConfigBuilder(
$grabyConfigBuilderMock,
$tokenStorage,
$siteCrentialRepo,
$logger
);
$config = $builder->buildForHost('unknown.com');
$this->assertFalse($config);
}
public function dataProviderCredentials()
{
return [
[
'host' => 'example.com',
],
[
'host' => 'other.example.com',
],
[
'host' => 'paywall.example.com',
'expectedUsername' => 'paywall.example',
'expectedPassword' => 'bar',
],
[
'host' => 'api.super.com',
'expectedUsername' => '.super',
'expectedPassword' => 'bar',
],
[
'host' => '.super.com',
'expectedUsername' => '.super',
'expectedPassword' => 'bar',
],
];
}
/**
* @dataProvider dataProviderCredentials
*/
public function testBuildConfigWithDbAccess($host, $expectedUsername = null, $expectedPassword = null)
{
$grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder')
->disableOriginalConstructor()
->getMock();
$grabySiteConfig = new GrabySiteConfig();
$grabySiteConfig->requires_login = true;
$grabySiteConfig->login_uri = 'http://api.example.com/login';
$grabySiteConfig->login_username_field = 'login';
$grabySiteConfig->login_password_field = 'password';
$grabySiteConfig->login_extra_fields = ['field=value'];
$grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
$grabyConfigBuilderMock
->method('buildForHost')
->with($host)
->will($this->returnValue($grabySiteConfig));
$user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
->disableOriginalConstructor()
->getMock();
$user->expects($this->once())
->method('getId')
->willReturn(1);
$token = new UsernamePasswordToken($user, 'pass', 'provider');
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
$logger = new Logger('foo');
$handler = new TestHandler();
$logger->pushHandler($handler);
$builder = new GrabySiteConfigBuilder(
$grabyConfigBuilderMock,
$tokenStorage,
$this->getClient()->getContainer()->get('wallabag_core.site_credential_repository'),
$logger
);
$config = $builder->buildForHost($host);
if (null === $expectedUsername && null === $expectedPassword) {
$this->assertFalse($config);
return;
}
$this->assertSame($expectedUsername, $config->getUsername());
$this->assertSame($expectedPassword, $config->getPassword());
}
}

File diff suppressed because one or more lines are too long