summaryrefslogtreecommitdiffstats
path: root/tests/Unit/Search/FolderSearchProviderTest.php
blob: e06bf45f7acb06089325202f0c6f8005cf19cdcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php

namespace OCA\News\Search;

use OCA\News\Db\Folder;
use OCA\News\Service\FeedServiceV2;
use OCA\News\Service\FolderServiceV2;
use OCA\News\Service\OpmlService;
use OCA\News\Utility\OPMLExporter;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\ISearchQuery;
use PHPUnit\Framework\TestCase;

class FolderSearchProviderTest extends TestCase
{

    /**
     * @var \PHPUnit\Framework\MockObject\MockObject|FolderServiceV2
     */
    private $folderService;

    /**
     * @var \PHPUnit\Framework\MockObject\MockObject|IL10N
     */
    private $l10n;

    /**
     * @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator
     */
    private $generator;

    /**
     * @var FolderSearchProvider
     */
    private $class;

    protected function setUp(): void
    {
        $this->l10n = $this->getMockBuilder(IL10N::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->generator = $this->getMockBuilder(IURLGenerator::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->folderService = $this->getMockBuilder(FolderServiceV2::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->class = new FolderSearchProvider(
            $this->l10n,
            $this->generator,
            $this->folderService
        );
    }

    public function testGetId()
    {
        $this->assertSame('news_folder', $this->class->getId());
    }

    public function testGetName()
    {
        $this->l10n->expects($this->once())
                   ->method('t')
                   ->with('News folders')
                   ->willReturnArgument(0);

        $this->assertSame('News folders', $this->class->getName());
    }

    public function testGetOrderExternal()
    {
        $this->assertSame(55, $this->class->getOrder('contacts.Page.index', []));
    }

    public function testGetOrderInternal()
    {
        $this->assertSame(0, $this->class->getOrder('news.page.index', []));
    }

    public function testSearch()
    {
        $user = $this->getMockBuilder(IUser::class)
                     ->getMock();
        $query = $this->getMockBuilder(ISearchQuery::class)
                     ->getMock();

        $user->expects($this->once())
              ->method('getUID')
              ->willReturn('user');

        $query->expects($this->once())
              ->method('getTerm')
              ->willReturn('Term');

        $folders = [
            Folder::fromRow(['id' => 1,'name' => 'some_tErm']),
            Folder::fromRow(['id' => 2,'name' => 'nothing'])
        ];

        $this->folderService->expects($this->once())
                            ->method('findAllForUser')
                            ->with('user')
                            ->willReturn($folders);

        $this->l10n->expects($this->once())
            ->method('t')
            ->with('News')
            ->willReturnArgument(0);

        $this->generator->expects($this->once())
                        ->method('imagePath')
                        ->with('core', 'filetypes/folder.svg')
                        ->willReturn('folderpath.svg');

        $this->generator->expects($this->once())
                        ->method('linkToRoute')
                        ->with('news.page.index')
                        ->willReturn('/news');


        $result = $this->class->search($user, $query)->jsonSerialize();
        $entry = $result['entries'][0]->jsonSerialize();
        $this->assertSame('News', $result['name']);
        $this->assertSame('some_tErm', $entry['title']);
        $this->assertSame('folderpath.svg', $entry['thumbnailUrl']);
        $this->assertSame('', $entry['subline']);
        $this->assertSame('/news#/items/folders/1', $entry['resourceUrl']);
    }
}
) b;`) - Allow max line length of 120 chars - Allow opening brace at the end of a function declaration: `function() {`. - Allow trailing comments ### Your first pull request There are several guides for pull requests, such as the following: - <https://thenewstack.io/getting-legit-with-git-and-github-your-first-pull-request/> - <https://github.com/firstcontributions/first-contributions#first-contributions> However, it's not always that simple. Our [PR approval process](#pr-approval-process) and the several merges we do every day may cause your fork to get behind the Netdata master. If you worked on something that has changed in the meantime, you will be required to do a git rebase, to bring your fork to the correct state. A very easy to follow guide on how to do it without learning all the intricacies of GitHub can be found [here](https://medium.com/@ruthmpardee/git-fork-workflow-using-rebase-587a144be470) One thing you will need to do only for your first pull request in Netdata is to accept the CLA. Until you do, the automated check for the CLA acceptance will be showing as failed. #### PR Guidelines PR Titles: - Must follow the [Imperative Mood](https://en.wikipedia.org/wiki/Imperative_mood) - Must be no more than ~50 characters (_longer description in the PR_) PR Descriptions: - Must clearly contain sufficient information regarding the content of the PR, including area/component, test plan, etc. - Must reference an existing issue. Some PR title examples: - Fix bug in Netdata installer for FreeBSD 11.2 - Update docs for other installation methods - Add new collector for Prometheus endpoints - Add 4.19 Kernel variant for eBPF - Fix typo in README - Refactor code for better maintainability - etc The key idea here is to start with a "verb" of what you are doing in the PR. For good examples have a look at other projects like: - https://github.com/facebook/react/commits/master - https://github.com/tensorflow/tensorflow/commits/master - https://github.com/vuejs/vue/commits/dev - https://github.com/microsoft/vscode/commits/master - Also see the Linux Kernel and Git projects as well as good examples. #### Commit messages when PRs are merged When a PR gets squashed and merged into master, the title of the commit message (first line) must be the PR title followed by the PR number. The body of the commit message should be a short description of the work, preferably taken from the connected issue. ### PR approval process Each PR automatically [requires a review](https://help.github.com/articles/about-required-reviews-for-pull-requests/) from the code owners specified in `.github/CODEOWNERS`. Depending on the files contained in your PR, several people may be needed to approve it. We also have a series of automated checks running, such as linters to check code quality and QA tests. If you get an error or warning in any of those checks, you will need to click on the link included in the check to identify the root cause, so you can fix it. If you wish to open a PR but are not quite ready for the code to be reviewed, you can open it as a Draft PR (click the dropdown on the **Create PR** button and select **Draft PR**). This will prevent reviewers from being notified initially so that you can keep working on the PR. Once you're ready, you can click the **Ready for Review** button near the bottom of the PR to mark it ready and notify the relevant reviewers. [![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2FCONTRIBUTING&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)