1 | <?php declare(strict_types = 1); |
||
2 | |||
3 | namespace Suilven\Sluggable\Tests; |
||
4 | |||
5 | use SilverStripe\Dev\SapphireTest; |
||
6 | use Suilven\Sluggable\Tests\Model\SluggestTestObject; |
||
7 | |||
8 | class SluggableObjectTest extends SapphireTest |
||
9 | { |
||
10 | protected static $extra_dataobjects = [ |
||
11 | SluggestTestObject::class, |
||
12 | ]; |
||
13 | |||
14 | public function testLowerCase(): void |
||
15 | { |
||
16 | $this->assertEquals('this-is-lower-case', $this->getSlugFromDataObject('this is lower case')); |
||
17 | } |
||
18 | |||
19 | |||
20 | public function testUpperCase(): void |
||
21 | { |
||
22 | $this->assertEquals('this-is-upper-case', $this->getSlugFromDataObject('THIS IS UPPER CASE')); |
||
23 | } |
||
24 | |||
25 | |||
26 | public function testMixedCase(): void |
||
27 | { |
||
28 | $this->assertEquals('this-is-mixed-case', $this->getSlugFromDataObject('THIs-Is-Mixed-case')); |
||
29 | } |
||
30 | |||
31 | |||
32 | public function testEmptyString(): void |
||
33 | { |
||
34 | $this->assertEquals('', $this->getSlugFromDataObject('')); |
||
35 | } |
||
36 | |||
37 | |||
38 | public function testDupicateString(): void |
||
39 | { |
||
40 | $this->assertEquals('duplicate', $this->getSlugFromDataObject('Duplicate')); |
||
41 | $this->assertEquals('duplicate-1', $this->getSlugFromDataObject('Duplicate')); |
||
42 | $this->assertEquals('duplicate-2', $this->getSlugFromDataObject('Duplicate')); |
||
43 | } |
||
44 | |||
45 | |||
46 | /** @throws \SilverStripe\ORM\ValidationException */ |
||
47 | private function getSlugFromDataObject(string $title): string |
||
48 | { |
||
49 | $object = new SluggestTestObject(); |
||
50 | $object->DisplayName = $title; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
51 | $object->write(); |
||
52 | |||
53 | return $object->Slug; |
||
0 ignored issues
–
show
The property
Slug does not exist on Suilven\Sluggable\Tests\Model\SluggestTestObject . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
54 | } |
||
55 | } |
||
56 |