| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
- use PhpOffice\PhpSpreadsheet\Cell\DataType;
- use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use PhpOffice\PhpSpreadsheet\Style\Border;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Font;
- use PHPUnit\Framework\TestCase;
- class GnumericStylesTest extends TestCase
- {
- /**
- * @dataProvider providerBorderStyle
- */
- public function testBorderStyle(string $style, string $expectedResult): void
- {
- $styles = Gnumeric::gnumericMappings();
- $borders = $styles['borderStyle'];
- self::assertEquals($expectedResult, $borders[$style]);
- }
- public function testBorderStyleCoverage(): void
- {
- $styles = Gnumeric::gnumericMappings();
- $expected = $styles['borderStyle'];
- $covered = [];
- foreach ($expected as $key => $val) {
- $covered[$key] = 0;
- }
- $tests = $this->providerBorderStyle();
- foreach ($tests as $test) {
- $covered[$test[0]] = 1;
- }
- foreach ($covered as $key => $val) {
- self::assertEquals(1, $val, "Borderstyle $key not tested");
- }
- }
- /**
- * @dataProvider providerfillType
- */
- public function testFillType(string $style, string $expectedResult): void
- {
- $styles = Gnumeric::gnumericMappings();
- $borders = $styles['fillType'];
- self::assertEquals($expectedResult, $borders[$style]);
- }
- public function testFillTypeCoverage(): void
- {
- $styles = Gnumeric::gnumericMappings();
- $expected = $styles['fillType'];
- $covered = [];
- foreach ($expected as $key => $val) {
- $covered[$key] = 0;
- }
- $tests = $this->providerfillType();
- foreach ($tests as $test) {
- $covered[$test[0]] = 1;
- }
- foreach ($covered as $key => $val) {
- self::assertEquals(1, $val, "fillType $key not tested");
- }
- }
- /**
- * @dataProvider providerHorizontal
- */
- public function testHorizontal(string $style, string $expectedResult): void
- {
- $styles = Gnumeric::gnumericMappings();
- $borders = $styles['horizontal'];
- self::assertEquals($expectedResult, $borders[$style]);
- }
- public function testHorizontalCoverage(): void
- {
- $styles = Gnumeric::gnumericMappings();
- $expected = $styles['horizontal'];
- $covered = [];
- foreach ($expected as $key => $val) {
- $covered[$key] = 0;
- }
- $tests = $this->providerHorizontal();
- foreach ($tests as $test) {
- $covered[$test[0]] = 1;
- }
- foreach ($covered as $key => $val) {
- self::assertEquals(1, $val, "horizontal $key not tested");
- }
- }
- /**
- * @dataProvider providerunderline
- */
- public function testUnderline(string $style, string $expectedResult): void
- {
- $styles = Gnumeric::gnumericMappings();
- $borders = $styles['underline'];
- self::assertEquals($expectedResult, $borders[$style]);
- }
- public function testUnderlineCoverage(): void
- {
- $styles = Gnumeric::gnumericMappings();
- $expected = $styles['underline'];
- $covered = [];
- foreach ($expected as $key => $val) {
- $covered[$key] = 0;
- }
- $tests = $this->providerUnderline();
- foreach ($tests as $test) {
- $covered[$test[0]] = 1;
- }
- foreach ($covered as $key => $val) {
- self::assertEquals(1, $val, "underline $key not tested");
- }
- }
- /**
- * @dataProvider providerVertical
- */
- public function testVertical(string $style, string $expectedResult): void
- {
- $styles = Gnumeric::gnumericMappings();
- $borders = $styles['vertical'];
- self::assertEquals($expectedResult, $borders[$style]);
- }
- public function testVerticalCoverage(): void
- {
- $styles = Gnumeric::gnumericMappings();
- $expected = $styles['vertical'];
- $covered = [];
- foreach ($expected as $key => $val) {
- $covered[$key] = 0;
- }
- $tests = $this->providerVertical();
- foreach ($tests as $test) {
- $covered[$test[0]] = 1;
- }
- foreach ($covered as $key => $val) {
- self::assertEquals(1, $val, "vertical $key not tested");
- }
- }
- /**
- * @dataProvider providerDataType
- */
- public function testDataType(string $style, string $expectedResult): void
- {
- $styles = Gnumeric::gnumericMappings();
- $borders = $styles['dataType'];
- self::assertEquals($expectedResult, $borders[$style]);
- }
- public function testDataTypeCoverage(): void
- {
- $styles = Gnumeric::gnumericMappings();
- $expected = $styles['dataType'];
- self::assertArrayNotHasKey('70', $expected);
- self::assertArrayNotHasKey('80', $expected);
- $covered = [];
- foreach ($expected as $key => $val) {
- $covered[$key] = 0;
- }
- $tests = $this->providerDataType();
- foreach ($tests as $test) {
- $covered[$test[0]] = 1;
- }
- foreach ($covered as $key => $val) {
- self::assertEquals(1, $val, "dataType $key not tested");
- }
- }
- public function providerBorderStyle(): array
- {
- return [
- ['0', Border::BORDER_NONE],
- ['1', Border::BORDER_THIN],
- ['2', Border::BORDER_MEDIUM],
- ['3', Border::BORDER_SLANTDASHDOT],
- ['4', Border::BORDER_DASHED],
- ['5', Border::BORDER_THICK],
- ['6', Border::BORDER_DOUBLE],
- ['7', Border::BORDER_DOTTED],
- ['8', Border::BORDER_MEDIUMDASHED],
- ['9', Border::BORDER_DASHDOT],
- ['10', Border::BORDER_MEDIUMDASHDOT],
- ['11', Border::BORDER_DASHDOTDOT],
- ['12', Border::BORDER_MEDIUMDASHDOTDOT],
- ['13', Border::BORDER_MEDIUMDASHDOTDOT],
- ];
- }
- public function providerFillType(): array
- {
- return [
- ['1', Fill::FILL_SOLID],
- ['2', Fill::FILL_PATTERN_DARKGRAY],
- ['3', Fill::FILL_PATTERN_MEDIUMGRAY],
- ['4', Fill::FILL_PATTERN_LIGHTGRAY],
- ['5', Fill::FILL_PATTERN_GRAY125],
- ['6', Fill::FILL_PATTERN_GRAY0625],
- ['7', Fill::FILL_PATTERN_DARKHORIZONTAL],
- ['8', Fill::FILL_PATTERN_DARKVERTICAL],
- ['9', Fill::FILL_PATTERN_DARKDOWN],
- ['10', Fill::FILL_PATTERN_DARKUP],
- ['11', Fill::FILL_PATTERN_DARKGRID],
- ['12', Fill::FILL_PATTERN_DARKTRELLIS],
- ['13', Fill::FILL_PATTERN_LIGHTHORIZONTAL],
- ['14', Fill::FILL_PATTERN_LIGHTVERTICAL],
- ['15', Fill::FILL_PATTERN_LIGHTUP],
- ['16', Fill::FILL_PATTERN_LIGHTDOWN],
- ['17', Fill::FILL_PATTERN_LIGHTGRID],
- ['18', Fill::FILL_PATTERN_LIGHTTRELLIS],
- ];
- }
- public function providerHorizontal(): array
- {
- return [
- ['1', Alignment::HORIZONTAL_GENERAL],
- ['2', Alignment::HORIZONTAL_LEFT],
- ['4', Alignment::HORIZONTAL_RIGHT],
- ['8', Alignment::HORIZONTAL_CENTER],
- ['16', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
- ['32', Alignment::HORIZONTAL_JUSTIFY],
- ['64', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
- ];
- }
- public function providerUnderline(): array
- {
- return [
- ['1', Font::UNDERLINE_SINGLE],
- ['2', Font::UNDERLINE_DOUBLE],
- ['3', Font::UNDERLINE_SINGLEACCOUNTING],
- ['4', Font::UNDERLINE_DOUBLEACCOUNTING],
- ];
- }
- public function providerVertical(): array
- {
- return [
- ['1', Alignment::VERTICAL_TOP],
- ['2', Alignment::VERTICAL_BOTTOM],
- ['4', Alignment::VERTICAL_CENTER],
- ['8', Alignment::VERTICAL_JUSTIFY],
- ];
- }
- public function providerDataType(): array
- {
- return [
- ['10', DataType::TYPE_NULL],
- ['20', DataType::TYPE_BOOL],
- ['30', DataType::TYPE_NUMERIC], // Integer doesn't exist in Excel
- ['40', DataType::TYPE_NUMERIC], // Float
- ['50', DataType::TYPE_ERROR],
- ['60', DataType::TYPE_STRING],
- //'70': // Cell Range
- //'80': // Array
- ];
- }
- }
|