SimpleSearchStringTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 51
c 1
b 0
f 0
dl 0
loc 70
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testReplaceOperators() 0 14 1
A testValidateMinWordLength() 0 51 1
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\Lib;
14
15
use SaitoSearch\Lib\SimpleSearchString;
16
use Saito\Test\SaitoTestCase;
17
18
class SimpleSearchStringTest extends SaitoTestCase
19
{
20
21
    public function testReplaceOperators()
22
    {
23
        $in = '  zap  -foo-bar   baz  ';
24
        $S = new SimpleSearchString($in);
25
26
        $result = $S->replaceOperators();
27
        $expected = '+zap -"foo-bar" +baz';
28
        $this->assertEquals($expected, $result);
29
30
        $in = 'zap "foo-bar" baz';
31
        $S = new SimpleSearchString($in);
32
        $result = $S->replaceOperators();
33
        $expected = '+zap +"foo-bar" +baz';
34
        $this->assertEquals($expected, $result);
35
    }
36
37
    public function testValidateMinWordLength()
38
    {
39
        $in = '+test -fooo';
40
        $S = new SimpleSearchString($in);
41
        $result = $S->validateLength();
42
        $this->assertTrue($result);
43
44
        $in = '+tes -foo';
45
        $S = new SimpleSearchString($in);
46
        $result = $S->validateLength();
47
        $this->assertFalse($result);
48
49
        $in = 'test +foo';
50
        $S = new SimpleSearchString($in);
51
        $result = $S->validateLength();
52
        $this->assertFalse($result);
53
54
        $in = 'wm-foo';
55
        $S = new SimpleSearchString($in);
56
        $result = $S->validateLength();
57
        $this->assertTrue($result);
58
59
        $in = 'w-m';
60
        $S = new SimpleSearchString($in);
61
        $result = $S->validateLength();
62
        $this->assertFalse($result);
63
64
        $in = 'wmf';
65
        $S = new SimpleSearchString($in);
66
        $result = $S->validateLength();
67
        $this->assertFalse($result);
68
69
        $in = '';
70
        $S = new SimpleSearchString($in);
71
        $result = $S->validateLength();
72
        $this->assertFalse($result);
73
74
        $in = 'wm foo';
75
        $S = new SimpleSearchString($in);
76
        $result = $S->validateLength();
77
        $this->assertFalse($result);
78
79
        $in = '"wm foo';
80
        $S = new SimpleSearchString($in);
81
        $result = $S->validateLength();
82
        $this->assertFalse($result);
83
84
        $in = '"wm foo"';
85
        $S = new SimpleSearchString($in);
86
        $result = $S->validateLength();
87
        $this->assertTrue($result);
88
    }
89
}
90