wallabag/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
Jeremy Benoist 6aca334d53
Move to controller as a service
Mostly using autowiring to inject deps.
The only tricky part was for import because all producer use the same class and have a different alias. So we must write them down in the service definition, autowiring doesn't work in that case.

Usually:
- if a controller has a constructor, it means injected services are at least re-used once in actions
- otherwise, service are injected per action
2022-12-19 10:38:08 +01:00

91 lines
3.6 KiB
PHP

<?php
namespace Tests\Wallabag\CoreBundle\Twig;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\CoreBundle\Repository\TagRepository;
use Wallabag\CoreBundle\Twig\WallabagExtension;
class WallabagExtensionTest extends TestCase
{
public function testRemoveWww()
{
$entryRepository = $this->getMockBuilder(EntryRepository::class)
->disableOriginalConstructor()
->getMock();
$tagRepository = $this->getMockBuilder(TagRepository::class)
->disableOriginalConstructor()
->getMock();
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)
->disableOriginalConstructor()
->getMock();
$translator = $this->getMockBuilder(TranslatorInterface::class)
->disableOriginalConstructor()
->getMock();
$extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, '');
$this->assertSame('lemonde.fr', $extension->removeWww('www.lemonde.fr'));
$this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr'));
$this->assertSame('gist.github.com', $extension->removeWww('gist.github.com'));
}
public function testRemoveScheme()
{
$entryRepository = $this->getMockBuilder(EntryRepository::class)
->disableOriginalConstructor()
->getMock();
$tagRepository = $this->getMockBuilder(TagRepository::class)
->disableOriginalConstructor()
->getMock();
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)
->disableOriginalConstructor()
->getMock();
$translator = $this->getMockBuilder(TranslatorInterface::class)
->disableOriginalConstructor()
->getMock();
$extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, '');
$this->assertSame('lemonde.fr', $extension->removeScheme('lemonde.fr'));
$this->assertSame('gist.github.com', $extension->removeScheme('gist.github.com'));
$this->assertSame('gist.github.com', $extension->removeScheme('https://gist.github.com'));
}
public function testRemoveSchemeAndWww()
{
$entryRepository = $this->getMockBuilder(EntryRepository::class)
->disableOriginalConstructor()
->getMock();
$tagRepository = $this->getMockBuilder(TagRepository::class)
->disableOriginalConstructor()
->getMock();
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)
->disableOriginalConstructor()
->getMock();
$translator = $this->getMockBuilder(TranslatorInterface::class)
->disableOriginalConstructor()
->getMock();
$extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, '');
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr'));
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr'));
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://www.lemonde.fr'));
$this->assertSame('gist.github.com', $extension->removeSchemeAndWww('https://gist.github.com'));
$this->assertSame('ftp://gist.github.com', $extension->removeSchemeAndWww('ftp://gist.github.com'));
}
}