Passed
Pull Request — master (#4313)
by Owen
15:26
created

FormulaTranslatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 29
c 1
b 0
f 0
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFormulas() 0 4 1
A formulaProvider() 0 18 1
A testAddresses() 0 4 1
A addressesProvider() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
6
7
use PhpOffice\PhpSpreadsheet\Reader\Ods\FormulaTranslator;
8
use PHPUnit\Framework\Attributes\DataProvider;
9
use PHPUnit\Framework\TestCase;
10
11
class FormulaTranslatorTest extends TestCase
12
{
13
    #[DataProvider('addressesProvider')]
14
    public function testAddresses(string $result, string $address): void
15
    {
16
        self::assertSame($result, FormulaTranslator::convertToExcelAddressValue($address));
17
    }
18
19
    public static function addressesProvider(): array
20
    {
21
        return [
22
            'range period in sheet name' => ["'sheet1.bug'!a1:a5", "'sheet1.bug'.a1:'sheet1.bug'.a5"],
23
            'range special chars and period in sheet name' => ["'#sheet1.x'!a1:a5", "'#sheet1.x'.a1:'#sheet1.x'.a5"],
24
            'cell period in sheet name' => ["'sheet1.bug'!b9", "'sheet1.bug'.b9"],
25
            'range unquoted sheet name' => ['sheet1!b9:c12', 'sheet1.b9:sheet1.c12'],
26
            'range unquoted sheet name with $' => ['sheet1!$b9:c$12', 'sheet1.$b9:sheet1.c$12'],
27
            'range quoted sheet name with $' => ["'sheet1'!\$b9:c\$12", '\'sheet1\'.$b9:\'sheet1\'.c$12'],
28
            'cell unquoted sheet name' => ['sheet1!B$9', 'sheet1.B$9'],
29
            'range no sheet name all dollars' => ['$B$9:$C$12', '$B$9:$C$12'],
30
            'range no sheet name some dollars' => ['B$9:$C12', 'B$9:$C12'],
31
            'range no sheet name no dollars' => ['B9:C12', 'B9:C12'],
32
        ];
33
    }
34
35
    #[DataProvider('formulaProvider')]
36
    public function testFormulas(string $result, string $formula): void
37
    {
38
        self::assertSame($result, FormulaTranslator::convertToExcelFormulaValue($formula));
39
    }
40
41
    public static function formulaProvider(): array
42
    {
43
        return [
44
            'ranges no sheet name' => [
45
                'SUM(A5:A7,B$5:$B7)',
46
                'SUM([.A5:.A7];[.B$5:.$B7])',
47
            ],
48
            'ranges sheet name with period' => [
49
                'SUM(\'test.bug\'!A5:A7,\'test.bug\'!B5:B7)',
50
                'SUM([\'test.bug\'.A5:.A7];[\'test.bug\'.B5:.B7])',
51
            ],
52
            'ranges unquoted sheet name' => [
53
                'SUM(testbug!A5:A7,testbug!B5:B7)',
54
                'SUM([testbug.A5:.A7];[testbug.B5:.B7])',
55
            ],
56
            'ranges quoted sheet name without period' => [
57
                'SUM(\'testbug\'!A5:A7,\'testbug\'!B5:B7)',
58
                'SUM([\'testbug\'.A5:.A7];[\'testbug\'.B5:.B7])',
59
            ],
60
        ];
61
    }
62
}
63