From: Jeremy Benoist Date: Mon, 3 Jul 2017 05:30:54 +0000 (+0200) Subject: Fix tests X-Git-Tag: 2.3.0~31^2~45^2 X-Git-Url: https://git.immae.eu/?p=github%2Fwallabag%2Fwallabag.git;a=commitdiff_plain;h=38520658addc217f127b0627ea28dcf8d6e6178c Fix tests --- diff --git a/.travis.yml b/.travis.yml index e6cf96cb..60e7dd1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -79,7 +79,7 @@ script: - echo "travis_fold:end:fixtures" - if [[ $VALIDATE_TRANSLATION_FILE = '' ]]; then ./bin/simple-phpunit -v ; fi; - - if [[ $CS_FIXER = run ]]; then php bin/php-cs-fixer fix src/ --verbose --dry-run ; fi; + - if [[ $CS_FIXER = run ]]; then php bin/php-cs-fixer fix --verbose --dry-run ; fi; - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml src/Wallabag/CoreBundle/Resources/translations -v ; fi; - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml app/Resources/CraueConfigBundle/translations -v ; fi; - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml src/Wallabag/UserBundle/Resources/translations -v ; fi; diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 445cfeeb..845ebef6 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -195,7 +195,7 @@ class EntryController extends Controller public function showUnreadAction(Request $request, $page) { // load the quickstart if no entry in database - if ($page === 1 && $this->get('wallabag_core.entry_repository')->countAllEntriesByUser($this->getUser()->getId()) === 0) { + if ((int) $page === 1 && $this->get('wallabag_core.entry_repository')->countAllEntriesByUser($this->getUser()->getId()) === 0) { return $this->redirect($this->generateUrl('quickstart')); } diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index a65bfe3b..c27ee90c 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -325,7 +325,7 @@ class EntryRepository extends EntityRepository ->where('e.user=:userId')->setParameter('userId', $userId) ; - return $qb->getQuery()->getSingleScalarResult(); + return (int) $qb->getQuery()->getSingleScalarResult(); } /** @@ -345,7 +345,7 @@ class EntryRepository extends EntityRepository ->andWhere('t.id=:tagId')->setParameter('tagId', $tagId) ; - return $qb->getQuery()->getSingleScalarResult(); + return (int) $qb->getQuery()->getSingleScalarResult(); } /** diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 2a333a0d..ae4af4cd 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -405,8 +405,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); - $this->assertSame(false, $content['is_archived']); - $this->assertSame(false, $content['is_starred']); + $this->assertSame(0, $content['is_archived']); + $this->assertSame(0, $content['is_starred']); $this->assertSame('New title for my article', $content['title']); $this->assertSame(1, $content['user_id']); $this->assertCount(2, $content['tags']); @@ -433,8 +433,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); - $this->assertSame(true, $content['is_archived']); - $this->assertSame(false, $content['is_starred']); + $this->assertSame(1, $content['is_archived']); + $this->assertSame(0, $content['is_starred']); $this->assertCount(3, $content['tags']); } @@ -485,8 +485,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); - $this->assertSame(true, $content['is_archived']); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(1, $content['is_archived']); + $this->assertSame(1, $content['is_starred']); $this->assertSame(1, $content['user_id']); } @@ -504,8 +504,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); - $this->assertSame(false, $content['is_archived']); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(0, $content['is_archived']); + $this->assertSame(1, $content['is_starred']); } public function testPatchEntry() @@ -691,7 +691,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_archived']); + $this->assertSame(1, $content['is_archived']); } public function testSaveIsStarredAfterPost() @@ -713,7 +713,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(1, $content['is_starred']); } public function testSaveIsArchivedAfterPatch() @@ -735,7 +735,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_archived']); + $this->assertSame(1, $content['is_archived']); } public function testSaveIsStarredAfterPatch() @@ -756,7 +756,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(1, $content['is_starred']); } public function dataForEntriesExistWithUrl() diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index b528bcdb..b1c6d53c 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -43,6 +43,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/unread/list'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); $this->assertSame(200, $client->getResponse()->getStatusCode()); @@ -505,7 +506,7 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertSame($res->isArchived(), true); + $this->assertSame(1, $res->isArchived()); } public function testToggleStar() @@ -528,7 +529,7 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findOneById($entry->getId()); - $this->assertSame($res->isStarred(), true); + $this->assertSame(1, $res->isStarred()); } public function testDelete() @@ -1004,7 +1005,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertSame($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); // instead of checking for the filename (which might change) check that the image is now local - $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); + $this->assertContains($client->getContainer()->getParameter('domain_name') . '/assets/images/', $entry->getContent()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } @@ -1296,7 +1297,7 @@ class EntryControllerTest extends WallabagCoreTestCase ], 'fucked_list_of_languages' => [ 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', - '', + null, ], 'es-ES' => [ 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index ba9296af..3e216381 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -230,8 +230,8 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('created_at', $content[0]); $this->assertArrayHasKey('updated_at', $content[0]); - $this->assertSame($contentInDB->isArchived(), $content[0]['is_archived']); - $this->assertSame($contentInDB->isStarred(), $content[0]['is_starred']); + $this->assertSame((int) $contentInDB->isArchived(), $content[0]['is_archived']); + $this->assertSame((int) $contentInDB->isStarred(), $content[0]['is_starred']); $this->assertSame($contentInDB->getTitle(), $content[0]['title']); $this->assertSame($contentInDB->getUrl(), $content[0]['url']); $this->assertSame([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index 91ce0102..5ffe1ca6 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php @@ -53,6 +53,6 @@ class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase $listener->onInteractiveLogin($event); - $this->assertSame('', $session->get('_locale')); + $this->assertNull($session->get('_locale')); } } diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 85036e35..5d6a29fe 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -2,7 +2,6 @@ namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; -use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use Graby\SiteConfig\SiteConfig as GrabySiteConfig; use Monolog\Handler\TestHandler; use Monolog\Logger; @@ -68,20 +67,15 @@ class GrabySiteConfigBuilderTest extends \PHPUnit_Framework_TestCase $config = $this->builder->buildForHost('www.example.com'); - $this->assertSame( - new SiteConfig([ - 'host' => 'example.com', - 'requiresLogin' => true, - 'loginUri' => 'http://www.example.com/login', - 'usernameField' => 'login', - 'passwordField' => 'password', - 'extraFields' => ['field' => 'value'], - 'notLoggedInXpath' => '//div[@class="need-login"]', - 'username' => 'foo', - 'password' => 'bar', - ]), - $config - ); + $this->assertSame('example.com', $config->getHost()); + $this->assertSame(true, $config->requiresLogin()); + $this->assertSame('http://www.example.com/login', $config->getLoginUri()); + $this->assertSame('login', $config->getUsernameField()); + $this->assertSame('password', $config->getPasswordField()); + $this->assertSame(['field' => 'value'], $config->getExtraFields()); + $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); + $this->assertSame('foo', $config->getUsername()); + $this->assertSame('bar', $config->getPassword()); $records = $handler->getRecords(); diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 7e19631b..c63671c4 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -51,7 +51,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEmpty($entry->getMimetype()); $this->assertEmpty($entry->getLanguage()); $this->assertSame(0.0, $entry->getReadingTime()); - $this->assertSame(false, $entry->getDomainName()); + $this->assertSame(null, $entry->getDomainName()); } public function testWithEmptyContent()