<?php
-namespace tests\Wallabag\CoreBundle\Controller;
+namespace Tests\Wallabag\CoreBundle\Controller;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\AnnotationBundle\Entity\Annotation;
use Wallabag\CoreBundle\Entity\Config;
$this->assertCount(1, $crawler->filter('button[id=config_save]'));
$this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
$this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
- $this->assertCount(1, $crawler->filter('button[id=rss_config_save]'));
+ $this->assertCount(1, $crawler->filter('button[id=feed_config_save]'));
}
public function testUpdate()
$data = [
'config[theme]' => 'baggy',
'config[items_per_page]' => '30',
- 'config[reading_speed]' => '0.5',
+ 'config[reading_speed]' => '100',
'config[action_mark_as_read]' => '0',
'config[language]' => 'en',
];
$crawler = $client->request('GET', '/config');
$form = $crawler->filter('button[id=config_save]')->form();
$data = [
- 'config[reading_speed]' => '2',
+ 'config[reading_speed]' => '400',
];
$client->submit($form, $data);
$crawler = $client->request('GET', '/config');
$form = $crawler->filter('button[id=config_save]')->form();
$data = [
- 'config[reading_speed]' => '0.5',
+ 'config[reading_speed]' => '100',
];
$client->submit($form, $data);
}
$this->assertContains('flashes.config.notice.user_updated', $alert[0]);
}
- public function testRssUpdateResetToken()
+ public function testFeedUpdateResetToken()
{
$this->logInAs('admin');
$client = $this->getClient();
}
$config = $user->getConfig();
- $config->setRssToken(null);
+ $config->setFeedToken(null);
$em->persist($config);
$em->flush();
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
- $this->assertContains('config.form_rss.no_token', $body[0]);
+ $this->assertContains('config.form_feed.no_token', $body[0]);
$client->request('GET', '/generate-token');
$this->assertSame(302, $client->getResponse()->getStatusCode());
$crawler = $client->followRedirect();
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
- $this->assertNotContains('config.form_rss.no_token', $body[0]);
+ $this->assertContains('config.form_feed.token_reset', $body[0]);
}
public function testGenerateTokenAjax()
$this->assertArrayHasKey('token', $content);
}
- public function testRssUpdate()
+ public function testRevokeTokenAjax()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $client->request(
+ 'GET',
+ '/revoke-token',
+ [],
+ [],
+ ['HTTP_X-Requested-With' => 'XMLHttpRequest']
+ );
+
+ $this->assertSame(200, $client->getResponse()->getStatusCode());
+ }
+
+ public function testFeedUpdate()
{
$this->logInAs('admin');
$client = $this->getClient();
$this->assertSame(200, $client->getResponse()->getStatusCode());
- $form = $crawler->filter('button[id=rss_config_save]')->form();
+ $form = $crawler->filter('button[id=feed_config_save]')->form();
$data = [
- 'rss_config[rss_limit]' => 12,
+ 'feed_config[feed_limit]' => 12,
];
$client->submit($form, $data);
$crawler = $client->followRedirect();
- $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
+ $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]);
}
- public function dataForRssFailed()
+ public function dataForFeedFailed()
{
return [
[
[
- 'rss_config[rss_limit]' => 0,
+ 'feed_config[feed_limit]' => 0,
],
'This value should be 1 or more.',
],
[
[
- 'rss_config[rss_limit]' => 1000000000000,
+ 'feed_config[feed_limit]' => 1000000000000,
],
- 'validator.rss_limit_too_high',
+ 'validator.feed_limit_too_high',
],
];
}
/**
- * @dataProvider dataForRssFailed
+ * @dataProvider dataForFeedFailed
*/
- public function testRssFailed($data, $expectedMessage)
+ public function testFeedFailed($data, $expectedMessage)
{
$this->logInAs('admin');
$client = $this->getClient();
$this->assertSame(200, $client->getResponse()->getStatusCode());
- $form = $crawler->filter('button[id=rss_config_save]')->form();
+ $form = $crawler->filter('button[id=feed_config_save]')->form();
$crawler = $client->submit($form, $data);
$config->setTheme('material');
$config->setItemsPerPage(30);
- $config->setReadingSpeed(1);
+ $config->setReadingSpeed(200);
$config->setLanguage('en');
$config->setPocketConsumerKey('xxxxx');
$em->persist($tag);
$entry = new Entry($user);
- $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+ $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
$entry->setContent('Youhou');
$entry->setTitle('Youhou');
$entry->addTag($tag);
$em->persist($tag);
$entry = new Entry($user);
- $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+ $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
$entry->setContent('Youhou');
$entry->setTitle('Youhou');
$entry->addTag($tag);
$em->persist($tagArchived);
$entryArchived = new Entry($user);
- $entryArchived->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+ $entryArchived->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
$entryArchived->setContent('Youhou');
$entryArchived->setTitle('Youhou');
$entryArchived->addTag($tagArchived);
- $entryArchived->setArchived(true);
+ $entryArchived->updateArchived(true);
$em->persist($entryArchived);
$annotationArchived = new Annotation($user);
$em->persist($tag);
$entry = new Entry($user);
- $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+ $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
$entry->setContent('Youhou');
$entry->setTitle('Youhou');
$entry->addTag($tag);
$client->request('GET', '/config/view-mode');
}
+
+ public function testChangeLocaleWithoutReferer()
+ {
+ $client = $this->getClient();
+
+ $client->request('GET', '/locale/de');
+ $client->followRedirect();
+
+ $this->assertSame('de', $client->getRequest()->getLocale());
+ $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
+ }
+
+ public function testChangeLocaleWithReferer()
+ {
+ $client = $this->getClient();
+
+ $client->request('GET', '/login');
+ $client->request('GET', '/locale/de');
+ $client->followRedirect();
+
+ $this->assertSame('de', $client->getRequest()->getLocale());
+ $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
+ }
+
+ public function testChangeLocaleToBadLocale()
+ {
+ $client = $this->getClient();
+
+ $client->request('GET', '/login');
+ $client->request('GET', '/locale/yuyuyuyu');
+ $client->followRedirect();
+
+ $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
+ $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
+ }
+
+ public function testUserEnable2faEmail()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $crawler = $client->request('GET', '/config/otp/email');
+
+ $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+ $crawler = $client->followRedirect();
+
+ $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
+ $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
+
+ // restore user
+ $em = $this->getEntityManager();
+ $user = $em
+ ->getRepository('WallabagUserBundle:User')
+ ->findOneByUsername('admin');
+
+ $this->assertTrue($user->isEmailTwoFactor());
+
+ $user->setEmailTwoFactor(false);
+ $em->persist($user);
+ $em->flush();
+ }
+
+ public function testUserEnable2faGoogle()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $crawler = $client->request('GET', '/config/otp/app');
+
+ $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+ // restore user
+ $em = $this->getEntityManager();
+ $user = $em
+ ->getRepository('WallabagUserBundle:User')
+ ->findOneByUsername('admin');
+
+ $this->assertTrue($user->isGoogleTwoFactor());
+ $this->assertGreaterThan(0, $user->getBackupCodes());
+
+ $user->setGoogleAuthenticatorSecret(false);
+ $user->setBackupCodes(null);
+ $em->persist($user);
+ $em->flush();
+ }
+
+ public function testUserEnable2faGoogleCancel()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $crawler = $client->request('GET', '/config/otp/app');
+
+ $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+ // restore user
+ $em = $this->getEntityManager();
+ $user = $em
+ ->getRepository('WallabagUserBundle:User')
+ ->findOneByUsername('admin');
+
+ $this->assertTrue($user->isGoogleTwoFactor());
+ $this->assertGreaterThan(0, $user->getBackupCodes());
+
+ $crawler = $client->request('GET', '/config/otp/app/cancel');
+
+ $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+ $user = $em
+ ->getRepository('WallabagUserBundle:User')
+ ->findOneByUsername('admin');
+
+ $this->assertFalse($user->isGoogleTwoFactor());
+ $this->assertEmpty($user->getBackupCodes());
+ }
+
+ public function testExportTaggingRule()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ ob_start();
+ $crawler = $client->request('GET', '/tagging-rule/export');
+ 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="tagging_rules_admin.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);
+ $this->assertSame('content matches "spurs"', $content[0]['rule']);
+ $this->assertSame('sport', $content[0]['tags'][0]);
+ }
+
+ public function testImportTagginfRuleBadFile()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $crawler = $client->request('GET', '/config');
+ $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form();
+
+ $data = [
+ 'upload_tagging_rule_file[file]' => '',
+ ];
+
+ $client->submit($form, $data);
+
+ $this->assertSame(302, $client->getResponse()->getStatusCode());
+ }
+
+ public function testImportTagginfRuleFile()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $crawler = $client->request('GET', '/config');
+ $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form();
+
+ $file = new UploadedFile(__DIR__ . '/../fixtures/tagging_rules_admin.json', 'tagging_rules_admin.json');
+
+ $data = [
+ 'upload_tagging_rule_file[file]' => $file,
+ ];
+
+ $client->submit($form, $data);
+ $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+ $user = $client->getContainer()->get('fos_user.user_manager.test')->findUserBy(['username' => 'admin']);
+ $taggingRules = $user->getConfig()->getTaggingRules()->toArray();
+ $this->assertCount(5, $taggingRules);
+ $this->assertSame('title matches "football"', $taggingRules[4]->getRule());
+ }
}