mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-18 00:52:07 +03:00
Added the ability to filter by tag in shotcodes:list command
This commit is contained in:
parent
52bb14bd66
commit
47a2c18c7e
3 changed files with 21 additions and 13 deletions
|
@ -67,6 +67,12 @@ class ListShortcodesCommand extends Command
|
||||||
->addOption(
|
->addOption(
|
||||||
'tags',
|
'tags',
|
||||||
't',
|
't',
|
||||||
|
InputOption::VALUE_OPTIONAL,
|
||||||
|
$this->translator->translate('A comma-separated list of tags to filter results')
|
||||||
|
)
|
||||||
|
->addOption(
|
||||||
|
'showTags',
|
||||||
|
null,
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
$this->translator->translate('Whether to display the tags or not')
|
$this->translator->translate('Whether to display the tags or not')
|
||||||
);
|
);
|
||||||
|
@ -76,13 +82,15 @@ class ListShortcodesCommand extends Command
|
||||||
{
|
{
|
||||||
$page = intval($input->getOption('page'));
|
$page = intval($input->getOption('page'));
|
||||||
$searchTerm = $input->getOption('searchTerm');
|
$searchTerm = $input->getOption('searchTerm');
|
||||||
$showTags = $input->getOption('tags');
|
$tags = $input->getOption('tags');
|
||||||
|
$tags = ! empty($tags) ? explode(',', $tags) : [];
|
||||||
|
$showTags = $input->getOption('showTags');
|
||||||
|
|
||||||
/** @var QuestionHelper $helper */
|
/** @var QuestionHelper $helper */
|
||||||
$helper = $this->getHelper('question');
|
$helper = $this->getHelper('question');
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$result = $this->shortUrlService->listShortUrls($page, $searchTerm);
|
$result = $this->shortUrlService->listShortUrls($page, $searchTerm, $tags);
|
||||||
$page++;
|
$page++;
|
||||||
$table = new Table($output);
|
$table = new Table($output);
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ class ListShortcodesCommandTest extends TestCase
|
||||||
public function noInputCallsListJustOnce()
|
public function noInputCallsListJustOnce()
|
||||||
{
|
{
|
||||||
$this->questionHelper->setInputStream($this->getInputStream('\n'));
|
$this->questionHelper->setInputStream($this->getInputStream('\n'));
|
||||||
$this->shortUrlService->listShortUrls(1, null)->willReturn(new Paginator(new ArrayAdapter()))
|
$this->shortUrlService->listShortUrls(1, null, [])->willReturn(new Paginator(new ArrayAdapter()))
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$this->commandTester->execute(['command' => 'shortcode:list']);
|
$this->commandTester->execute(['command' => 'shortcode:list']);
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,8 @@ class ListShortcodesCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
$page = 5;
|
$page = 5;
|
||||||
$this->questionHelper->setInputStream($this->getInputStream('\n'));
|
$this->questionHelper->setInputStream($this->getInputStream('\n'));
|
||||||
$this->shortUrlService->listShortUrls($page, null)->willReturn(new Paginator(new ArrayAdapter()))
|
$this->shortUrlService->listShortUrls($page, null, [])->willReturn(new Paginator(new ArrayAdapter()))
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$this->commandTester->execute([
|
$this->commandTester->execute([
|
||||||
'command' => 'shortcode:list',
|
'command' => 'shortcode:list',
|
||||||
|
@ -118,12 +118,12 @@ class ListShortcodesCommandTest extends TestCase
|
||||||
public function ifTagsFlagIsProvidedTagsColumnIsIncluded()
|
public function ifTagsFlagIsProvidedTagsColumnIsIncluded()
|
||||||
{
|
{
|
||||||
$this->questionHelper->setInputStream($this->getInputStream('\n'));
|
$this->questionHelper->setInputStream($this->getInputStream('\n'));
|
||||||
$this->shortUrlService->listShortUrls(1, null)->willReturn(new Paginator(new ArrayAdapter()))
|
$this->shortUrlService->listShortUrls(1, null, [])->willReturn(new Paginator(new ArrayAdapter()))
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$this->commandTester->execute([
|
$this->commandTester->execute([
|
||||||
'command' => 'shortcode:list',
|
'command' => 'shortcode:list',
|
||||||
'--tags' => true,
|
'--showTags' => true,
|
||||||
]);
|
]);
|
||||||
$output = $this->commandTester->getDisplay();
|
$output = $this->commandTester->getDisplay();
|
||||||
$this->assertTrue(strpos($output, 'Tags') > 0);
|
$this->assertTrue(strpos($output, 'Tags') > 0);
|
||||||
|
|
|
@ -34,8 +34,8 @@ class ListShortcodesActionTest extends TestCase
|
||||||
public function properListReturnsSuccessResponse()
|
public function properListReturnsSuccessResponse()
|
||||||
{
|
{
|
||||||
$page = 3;
|
$page = 3;
|
||||||
$this->service->listShortUrls($page, null)->willReturn(new Paginator(new ArrayAdapter()))
|
$this->service->listShortUrls($page, null, [])->willReturn(new Paginator(new ArrayAdapter()))
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$response = $this->action->__invoke(
|
$response = $this->action->__invoke(
|
||||||
ServerRequestFactory::fromGlobals()->withQueryParams([
|
ServerRequestFactory::fromGlobals()->withQueryParams([
|
||||||
|
@ -52,8 +52,8 @@ class ListShortcodesActionTest extends TestCase
|
||||||
public function anExceptionsReturnsErrorResponse()
|
public function anExceptionsReturnsErrorResponse()
|
||||||
{
|
{
|
||||||
$page = 3;
|
$page = 3;
|
||||||
$this->service->listShortUrls($page, null)->willThrow(\Exception::class)
|
$this->service->listShortUrls($page, null, [])->willThrow(\Exception::class)
|
||||||
->shouldBeCalledTimes(1);
|
->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
$response = $this->action->__invoke(
|
$response = $this->action->__invoke(
|
||||||
ServerRequestFactory::fromGlobals()->withQueryParams([
|
ServerRequestFactory::fromGlobals()->withQueryParams([
|
||||||
|
|
Loading…
Reference in a new issue