91 lines
3.0 KiB
PHP
91 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class Dec2OctTest extends TestCase
|
|
{
|
|
private $compatibilityMode;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDEC2OCT
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $formula
|
|
*/
|
|
public function testDEC2OCT($expectedResult, $formula): void
|
|
{
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcExp::class);
|
|
}
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setCellValue('A2', 17);
|
|
$sheet->getCell('A1')->setValue("=DEC2OCT($formula)");
|
|
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function providerDEC2OCT()
|
|
{
|
|
return require 'tests/data/Calculation/Engineering/DEC2OCT.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDEC2OCT
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $formula
|
|
*/
|
|
public function testDEC2OCTOds($expectedResult, $formula): void
|
|
{
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcExp::class);
|
|
}
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
if ($formula === 'true') {
|
|
$expectedResult = 1;
|
|
} elseif ($formula === 'false') {
|
|
$expectedResult = 0;
|
|
}
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setCellValue('A2', 17);
|
|
$sheet->getCell('A1')->setValue("=DEC2OCT($formula)");
|
|
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function testDEC2OCTFrac(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
|
|
$cell = 'G1';
|
|
$sheet->setCellValue($cell, '=DEC2OCT(17.1)');
|
|
self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Gnumeric');
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
$cell = 'O1';
|
|
$sheet->setCellValue($cell, '=DEC2OCT(17.1)');
|
|
self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Ods');
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
$cell = 'E1';
|
|
$sheet->setCellValue($cell, '=DEC2OCT(17.1)');
|
|
self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
|
|
}
|
|
}
|