1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Christian Gripp <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Core23\SetlistFm\Tests\Builder; |
11
|
|
|
|
12
|
|
|
use Core23\SetlistFm\Builder\ArtistSearchBuilder; |
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
class ArtistSearchBuilderTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testCreate(): void |
19
|
|
|
{ |
20
|
|
|
$builder = ArtistSearchBuilder::create(); |
21
|
|
|
|
22
|
|
|
$expected = [ |
23
|
|
|
'p' => 1, |
24
|
|
|
]; |
25
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testWithTmbid(): void |
29
|
|
|
{ |
30
|
|
|
$builder = ArtistSearchBuilder::create() |
31
|
|
|
->withTmbid(123) |
32
|
|
|
; |
33
|
|
|
|
34
|
|
|
$expected = [ |
35
|
|
|
'p' => 1, |
36
|
|
|
'artistTmid' => 123, |
37
|
|
|
]; |
38
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testWithMbid(): void |
42
|
|
|
{ |
43
|
|
|
$builder = ArtistSearchBuilder::create() |
44
|
|
|
->withMbid('a466c2a2-6517-42fb-a160-1087c3bafd9f') |
45
|
|
|
; |
46
|
|
|
|
47
|
|
|
$expected = [ |
48
|
|
|
'p' => 1, |
49
|
|
|
'artistMbid' => 'a466c2a2-6517-42fb-a160-1087c3bafd9f', |
50
|
|
|
]; |
51
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testWithName(): void |
55
|
|
|
{ |
56
|
|
|
$builder = ArtistSearchBuilder::create() |
57
|
|
|
->withName('FooBar') |
58
|
|
|
; |
59
|
|
|
|
60
|
|
|
$expected = [ |
61
|
|
|
'p' => 1, |
62
|
|
|
'artistName' => 'FooBar', |
63
|
|
|
]; |
64
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testWithNameOverride(): void |
68
|
|
|
{ |
69
|
|
|
$builder = ArtistSearchBuilder::create() |
70
|
|
|
->withName('FooBar') |
71
|
|
|
->withName('BarBaz') |
72
|
|
|
; |
73
|
|
|
|
74
|
|
|
$expected = [ |
75
|
|
|
'p' => 1, |
76
|
|
|
'artistName' => 'BarBaz', |
77
|
|
|
]; |
78
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testSortByRelevance(): void |
82
|
|
|
{ |
83
|
|
|
$builder = ArtistSearchBuilder::create() |
84
|
|
|
->sort('relevance') |
85
|
|
|
; |
86
|
|
|
|
87
|
|
|
$expected = [ |
88
|
|
|
'p' => 1, |
89
|
|
|
'sort' => 'relevance', |
90
|
|
|
]; |
91
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testSortWithInvalidType(): void |
95
|
|
|
{ |
96
|
|
|
$this->expectException(InvalidArgumentException::class); |
97
|
|
|
$this->expectExceptionMessage('Invalid sort mode given: foo'); |
98
|
|
|
|
99
|
|
|
ArtistSearchBuilder::create() |
100
|
|
|
->sort('foo') |
101
|
|
|
; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testSortByName(): void |
105
|
|
|
{ |
106
|
|
|
$builder = ArtistSearchBuilder::create() |
107
|
|
|
->sort('sortName') |
108
|
|
|
; |
109
|
|
|
|
110
|
|
|
$expected = [ |
111
|
|
|
'p' => 1, |
112
|
|
|
'sort' => 'sortName', |
113
|
|
|
]; |
114
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testPage(): void |
118
|
|
|
{ |
119
|
|
|
$builder = ArtistSearchBuilder::create() |
120
|
|
|
->page(42) |
121
|
|
|
; |
122
|
|
|
|
123
|
|
|
$expected = [ |
124
|
|
|
'p' => 42, |
125
|
|
|
]; |
126
|
|
|
$this->assertSame($expected, $builder->getQuery()); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|