Completed
Push — develop ( 2e4d8c...9c047b )
by Schlaefer
08:33
created

SearchesControllerTest::testSimpleSortByRank()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace SaitoSearch\Test\Controller;
14
15
use Saito\Exception\SaitoForbiddenException;
16
use Saito\Test\IntegrationTestCase;
17
18
/*
19
class SearchesMockController extends SearchesController
20
{
21
22
    public function sanitize($string)
23
    {
24
        return $this->_sanitize($string);
25
    }
26
}
27
*/
28
29
/**
30
 * SearchesController Test Case
31
 *
32
 */
33
class SearchesControllerTest extends IntegrationTestCase
34
{
35
36
    /** @var array Fixtures */
37
    public $fixtures = [
38
        'app.Category',
39
        'app.Entry',
40
        'app.Setting',
41
        'app.User',
42
        'app.UserBlock',
43
        'app.UserIgnore',
44
        'app.UserRead',
45
        'app.UserOnline',
46
    ];
47
48
    /**
49
     * Sorting search results by rank
50
     */
51
    public function testSimpleSortByRank()
52
    {
53
        $this->skipOnDataSource('Postgres');
54
        $this->_loginUser(1);
55
56
        $this->get('/searches/simple?searchTerm="Second_Subject"&order=rank');
57
58
        $this->assertResponseCode(200);
59
60
        $result = $this->viewVariable('results');
61
        $this->assertEquals(2, $result->first()->get('id'));
62
        $this->assertEquals(5, $result->skip(1)->first()->get('id'));
63
    }
64
65
    /**
66
     * Admin Category results should be in search results for admin
67
     */
68
    public function testSimpleAccession()
69
    {
70
        $this->skipOnDataSource('Postgres');
71
        $this->_loginUser(1);
72
73
        $this->get('/searches/simple?searchTerm="Third+Thread+First_Subject"');
74
        $result = $this->viewVariable('results');
75
76
        $this->assertCount(1, $result);
77
    }
78
79
    /**
80
     * Admin Category results shouldn't be in search results for user
81
     */
82
    public function testSimpleNoAccession()
83
    {
84
        $this->skipOnDataSource('Postgres');
85
        $this->_loginUser(3);
86
87
        $this->get('/searches/simple?searchTerm="Third+Thread+First_Subject"');
88
        $result = $this->viewVariable('results');
89
90
        $this->assertCount(0, $result);
91
    }
92
93
    /**
94
     * Admin Category results should be in search results for admin
95
     */
96
    public function testAdvancedAccession()
97
    {
98
        $this->_loginUser(1);
99
100
        $this->get('/searches/advanced?subject=Third+Thread+First_Subject');
101
        $result = $this->viewVariable('results');
102
103
        $this->assertCount(1, $result);
104
    }
105
106
    /**
107
     * Admin Category results shouldn't be in search results for user
108
     */
109
    public function testAdvancedNoAccessionPassive()
110
    {
111
        $this->_loginUser(3);
112
113
        $this->get('/searches/advanced?subject=Third+Thread+First_Subject');
114
        $result = $this->viewVariable('results');
115
116
        $this->assertCount(0, $result);
117
    }
118
119
    public function testSearchAdvancedCategoryNoAccession()
120
    {
121
        $this->_loginUser(3);
122
123
        $this->expectException(SaitoForbiddenException::class);
124
        $this->get('/searches/advanced?subject=Third+Thread+First_Subject&category_id=1');
125
    }
126
127
    public function testSearchAdvancedUserPostings()
128
    {
129
        $this->_loginUser(1);
130
131
        $this->get('/searches/advanced?name=Alice');
132
133
        $results = $this->viewVariable('results');
134
        $this->assertNotEmpty($results);
135
    }
136
}
137