Adding more tests

This commit is contained in:
Jeremy Benoist 2019-02-27 14:59:50 +01:00
parent ea925bb112
commit 8c0ba95307
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
8 changed files with 77 additions and 9 deletions

View file

@ -114,7 +114,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
$extraFields = [];
foreach ($extraFieldsStrings as $extraField) {
if (false === strpos($extraField, '=')) {
break;
continue;
}
list($fieldName, $fieldValue) = explode('=', $extraField, 2);

View file

@ -56,7 +56,7 @@ class DownloadImages
$imagePath = $this->processSingleImage($entryId, $image, $url, $relativePath);
if (false === $imagePath) {
break;
continue;
}
// if image contains "&" and we can't find it in the html it might be because it's encoded as &

View file

@ -37,7 +37,7 @@ class RuleBasedTagger
foreach ($rules as $rule) {
if (!$this->rulerz->satisfies($entry, $rule->getRule())) {
break;
continue;
}
$this->logger->info('Matching rule.', [

View file

@ -49,7 +49,7 @@ class TagsAssigner
// avoid empty tag
if (0 === \strlen($label)) {
break;
continue;
}
if (isset($tagsNotYetFlushed[$label])) {

View file

@ -169,7 +169,7 @@ abstract class AbstractImport implements ImportInterface
$entry = $this->parseEntry($importedEntry);
if (null === $entry) {
break;
continue;
}
// store each entry to be flushed so we can trigger the entry.saved event for each of them

View file

@ -158,13 +158,13 @@ abstract class BrowserImport extends AbstractImport
foreach ($entries as $importedEntry) {
if ((array) $importedEntry !== $importedEntry) {
break;
continue;
}
$entry = $this->parseEntry($importedEntry);
if (null === $entry) {
break;
continue;
}
// @see AbstractImport
@ -206,7 +206,7 @@ abstract class BrowserImport extends AbstractImport
{
foreach ($entries as $importedEntry) {
if ((array) $importedEntry !== $importedEntry) {
break;
continue;
}
// set userId for the producer (it won't know which user is connected)

View file

@ -65,7 +65,7 @@ class InstapaperImport extends AbstractImport
$handle = fopen($this->filepath, 'r');
while (false !== ($data = fgetcsv($handle, 10240))) {
if ('URL' === $data[0]) {
break;
continue;
}
// last element in the csv is the folder where the content belong

View file

@ -134,4 +134,72 @@ class GrabySiteConfigBuilderTest extends TestCase
$this->assertCount(1, $records, 'One log was recorded');
}
public function testBuildConfigWithBadExtraFields()
{
/* @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_username_field = 'login';
$grabySiteConfig->login_password_field = 'password';
$grabySiteConfig->login_extra_fields = ['field'];
$grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
$grabyConfigBuilderMock
->method('buildForHost')
->with('example.com')
->will($this->returnValue($grabySiteConfig));
$logger = new Logger('foo');
$handler = new TestHandler();
$logger->pushHandler($handler);
$siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository')
->disableOriginalConstructor()
->getMock();
$siteCrentialRepo->expects($this->once())
->method('findOneByHostAndUser')
->with('example.com', 1)
->willReturn(['username' => 'foo', 'password' => 'bar']);
$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);
$this->builder = new GrabySiteConfigBuilder(
$grabyConfigBuilderMock,
$tokenStorage,
$siteCrentialRepo,
$logger
);
$config = $this->builder->buildForHost('www.example.com');
$this->assertSame('example.com', $config->getHost());
$this->assertTrue($config->requiresLogin());
$this->assertSame('http://www.example.com/login', $config->getLoginUri());
$this->assertSame('login', $config->getUsernameField());
$this->assertSame('password', $config->getPasswordField());
$this->assertSame([], $config->getExtraFields());
$this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath());
$this->assertSame('foo', $config->getUsername());
$this->assertSame('bar', $config->getPassword());
$records = $handler->getRecords();
$this->assertCount(1, $records, 'One log was recorded');
}
}