SluggableObjectTest::testMixedCase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
The property DisplayName does not exist on Suilven\Sluggable\Tests\Model\SluggestTestObject. Since you implemented __set, consider adding a @property annotation.
Loading history...
51
        $object->write();
52
53
        return $object->Slug;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $object->Slug could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
Bug Best Practice introduced by
The property Slug does not exist on Suilven\Sluggable\Tests\Model\SluggestTestObject. Since you implemented __get, consider adding a @property annotation.
Loading history...
54
    }
55
}
56