mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-27 16:36:00 +00:00
Add tests
This commit is contained in:
parent
0d1748c8a8
commit
049d87e180
2 changed files with 100 additions and 1 deletions
|
@ -101,7 +101,7 @@ class UrlCommand extends Command
|
|||
$this->entityManager->persist($entry);
|
||||
|
||||
$tags = explode(',', $input->getArgument('tags'));
|
||||
if (count($tags) > 0) {
|
||||
if (\count($tags) > 1) {
|
||||
$this->tagsAssigner->assignTagsToEntry(
|
||||
$entry,
|
||||
$tags,
|
||||
|
|
99
tests/Command/Import/UrlCommandTest.php
Normal file
99
tests/Command/Import/UrlCommandTest.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Wallabag\Command\Import;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Tests\Wallabag\WallabagTestCase;
|
||||
use Wallabag\Entity\Entry;
|
||||
|
||||
class UrlCommandTest extends WallabagTestCase
|
||||
{
|
||||
private $url = 'https://www.20minutes.fr/sport/football/4158082-20250612-euro-espoirs-su-souffrir-ensemble-decimes-bleuets-retiennent-positif-apres-nul-face-portugal';
|
||||
|
||||
public function testRunUrlCommandWithoutArguments()
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('Not enough arguments');
|
||||
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
$command = $application->find('wallabag:import:url');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([]);
|
||||
}
|
||||
|
||||
public function testRunUrlCommandWithWrongUsername()
|
||||
{
|
||||
$this->expectException(NoResultException::class);
|
||||
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
$command = $application->find('wallabag:import:url');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'username' => 'random',
|
||||
'url' => $this->url,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testRunUrlCommand()
|
||||
{
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
$command = $application->find('wallabag:import:url');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'username' => 'admin',
|
||||
'url' => $this->url,
|
||||
]);
|
||||
|
||||
$this->assertStringContainsString('successfully imported', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testRunUrlCommandWithTags()
|
||||
{
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
$command = $application->find('wallabag:import:url');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'username' => 'admin',
|
||||
'url' => $this->url,
|
||||
'tags' => 'sport, football',
|
||||
]);
|
||||
|
||||
$this->assertStringContainsString('successfully imported', $tester->getDisplay());
|
||||
|
||||
$client = $this->getTestClient();
|
||||
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
||||
$entry = $em->getRepository(Entry::class)->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
|
||||
$this->assertContains('football', $entry->getTagsLabel());
|
||||
$this->assertNotContains('basketball', $entry->getTagsLabel());
|
||||
}
|
||||
|
||||
public function testRunUrlCommandWithUserId()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
|
||||
$application = new Application($this->getTestClient()->getKernel());
|
||||
|
||||
$command = $application->find('wallabag:import:url');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'username' => $this->getLoggedInUserId(),
|
||||
'url' => $this->url,
|
||||
'--useUserId' => true,
|
||||
]);
|
||||
|
||||
$this->assertStringContainsString('successfully imported', $tester->getDisplay());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue