This commit is contained in:
steven 2025-08-11 22:23:30 +02:00
commit 72a26edcff
22092 changed files with 2101903 additions and 0 deletions

View file

@ -0,0 +1,47 @@
<?php
use SimpleExcel\SimpleExcel;
require_once('src/SimpleExcel/SimpleExcel.php');
class CSVTest extends PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$excel = new SimpleExcel('CSV');
$excel2 = new SimpleExcel();
$excel2->constructParser('CSV');
$this->assertEquals($excel->parser, $excel2->parser);
return $excel;
}
/**
* @depends testConstruct
*/
public function testParser(SimpleExcel $excel)
{
$excel->parser->loadFile('test/CSV/test.csv');
$this->assertEquals('ID', $excel->parser->getCell(1, 1));
$this->assertEquals('Kab. Cianjur', $excel->parser->getCell(3, 2));
$this->assertEquals(array('5', 'Comma, inside, double-quotes', '3'), $excel->parser->getRow(6));
$this->assertEquals(array('Kode Wilayah', '1', '1', '1', '2', '3'), $excel->parser->getColumn(3));
}
/**
* @depends testConstruct
*/
public function testWriter(SimpleExcel $excel)
{
$excel->writer->setData(
array(
array('ID', 'Nama', 'Kode Wilayah'),
array('1', 'Kab. Bogor', '1')
)
);
$this->assertEquals("ID,Nama,\"Kode Wilayah\"\n1,\"Kab. Bogor\",1\n", $excel->writer->saveString());
$excel->writer->addRow(array('2', 'Kab. Cianjur', '1'));
$this->assertEquals("ID,Nama,\"Kode Wilayah\"\n1,\"Kab. Bogor\",1\n2,\"Kab. Cianjur\",1\n", $excel->writer->saveString());
}
}
?>

6
setup/test/CSV/test.csv Normal file
View file

@ -0,0 +1,6 @@
ID,Nama,Kode Wilayah
1,Kab. Bogor,1
2,"Kab. Cianjur",1
3,Kab. Sukabumi,1
4,Kab. Tasikmalaya,2
5,"Comma, inside, double-quotes",3
1 ID Nama Kode Wilayah
2 1 Kab. Bogor 1
3 2 Kab. Cianjur 1
4 3 Kab. Sukabumi 1
5 4 Kab. Tasikmalaya 2
6 5 Comma, inside, double-quotes 3

6
setup/test/CSV/test2.csv Normal file
View file

@ -0,0 +1,6 @@
ID;Nama;Kode Wilayah
1;Kab. Bogor;1
2;"Kab. Cianjur";1
3;Kab. Sukabumi;1
4;Kab. Tasikmalaya;2
5;"Semicolon; inside; double-quotes";3
1 ID Nama Kode Wilayah
2 1 Kab. Bogor 1
3 2 Kab. Cianjur 1
4 3 Kab. Sukabumi 1
5 4 Kab. Tasikmalaya 2
6 5 Semicolon; inside; double-quotes 3

View file

@ -0,0 +1,35 @@
<?php
use SimpleExcel\SimpleExcel;
require_once('src/SimpleExcel/SimpleExcel.php');
class HTMLTest extends PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$excel = new SimpleExcel('HTML');
return $excel;
}
/**
* @depends testConstruct
*/
public function testParser(SimpleExcel $excel)
{
$excel->parser->loadFile('test/HTML/test.html');
$this->assertEquals(array('ID', 'Nama', 'Kode Wilayah'), $excel->parser->getRow(1));
$this->assertEquals(array('1', 'Kab. Bogor', '1'), $excel->parser->getRow(2));
}
/**
* @depends testConstruct
*/
public function testWriter(SimpleExcel $excel)
{
$excel->writer->addRow(array('ID', 'Nama', 'Kode Wilayah'));
$this->assertEquals('<table><tr><td>ID</td><td>Nama</td><td>Kode Wilayah</td></tr></table>', $excel->writer->saveString());
}
}
?>

37
setup/test/HTML/test.html Normal file
View file

@ -0,0 +1,37 @@
<!doctype html>
<html>
<head>
<style>
td { border: 1px solid #000 }
</style>
</head>
<body>
<table>
<tr>
<td>ID</td>
<td>Nama</td>
<td>Kode Wilayah</td>
</tr>
<tr>
<td>1</td>
<td>Kab. Bogor</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>Kab. Cianjur</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>Kab. Sukabumi</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>Kab. Tasikmalaya</td>
<td>2</td>
</tr>
</table>
</body>
</html>

View file

@ -0,0 +1,35 @@
<?php
use SimpleExcel\SimpleExcel;
require_once('src/SimpleExcel/SimpleExcel.php');
class JSONTest extends PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$excel = new SimpleExcel('JSON');
return $excel;
}
/**
* @depends testConstruct
*/
public function testParser(SimpleExcel $excel)
{
$excel->parser->loadFile('test/JSON/test.json');
$this->assertEquals(array('ID', 'Nama', 'Kode Wilayah'), $excel->parser->getRow(1));
$this->assertEquals(array('1', 'Kab. Bogor', '1'), $excel->parser->getRow(2));
}
/**
* @depends testConstruct
*/
public function testWriter(SimpleExcel $excel)
{
$excel->writer->addRow(array('ID', 'Nama', 'Kode Wilayah'));
$this->assertEquals('[{"0":"ID","1":"Nama","2":"Kode Wilayah"}]', $excel->writer->saveString());
}
}
?>

12
setup/test/JSON/test.json Normal file
View file

@ -0,0 +1,12 @@
[
{
"1" : "ID",
"2" : "Nama",
"3" : "Kode Wilayah"
},
{
"3" : "1",
"1" : "Kab. Bogor",
"2" : "1"
}
]

View file

6
setup/test/TSV/test.tsv Normal file
View file

@ -0,0 +1,6 @@
ID Nama Kode Wilayah
1 Kab. Bogor 1
2 "Kab. Cianjur" 1
3 Kab. Sukabumi 1
4 Kab. Tasikmalaya 2
5 "Tab inside double-quotes" 3
1 ID Nama Kode Wilayah
2 1 Kab. Bogor 1
3 2 Kab. Cianjur 1
4 3 Kab. Sukabumi 1
5 4 Kab. Tasikmalaya 2
6 5 Tab inside double-quotes 3

View file

View file

View file

0
setup/test/XML/test.xml Normal file
View file

15
setup/test/phpunit.xml Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
<testsuites>
<testsuite name="CSV">
<directory>./CSV/</directory>
</testsuite>
<testsuite name="JSON">
<directory>./JSON/</directory>
</testsuite>
<testsuite name="HTML">
<directory>./HTML/</directory>
</testsuite>
</testsuites>
</phpunit>