aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/lib/classes/StringManipulationTest.php
blob: cce5513f4db6298e9e6c79a4706923d3d37c9d00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

class StringManipulationTest extends \Codeception\Test\Unit
{
    public function setUp(): void
    {
        require_once 'lib/functions.php';
    }

    /**
     * @dataProvider camelCaseProvider
     */
    public function testCamelCase($input, $expected, $ucfirst = false)
    {
        $camel_cased = strtocamelcase($input, $ucfirst);
        $this->assertEquals($camel_cased, $expected);
    }

    public function camelCaseProvider()
    {
        return [
            ['foo bar', 'fooBar'],
            ['lorem (ipsum) dolor', 'loremIpsumDolor'],
            ['test with numbers 1 2 3 4', 'testWithNumbers1234'],
            ['path/definitions/converted', 'pathDefinitionsConverted'],

            ['foo bar', 'FooBar', true],
        ];
    }

    /**
     * @dataProvider snake_case_provider
     */
    public function test_snake_case($input, $expected)
    {
        $snake_cased = strtosnakecase($input);
        $this->assertEquals($snake_cased, $expected);
    }

    public function snake_case_provider()
    {
        return [
            ['foo bar', 'foo_bar'],
            ['lorem (ipsum) dolor', 'lorem_ipsum_dolor'],
            ['test with numbers 1 2 3 4', 'test_with_numbers_1_2_3_4'],
            ['path/definitions/converted', 'path_definitions_converted'],
        ];
    }
}