mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-21 21:04:25 +02:00
parent
e8ed7c7166
commit
87863d3212
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
namespace Icinga\File;
|
namespace Icinga\File;
|
||||||
|
|
||||||
@ -10,6 +12,7 @@ class Csv
|
|||||||
|
|
||||||
protected function __construct()
|
protected function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromQuery(BaseQuery $query)
|
public static function fromQuery(BaseQuery $query)
|
||||||
@ -40,6 +43,7 @@ class Csv
|
|||||||
}
|
}
|
||||||
$csv .= implode(',', $out) . "\r\n";
|
$csv .= implode(',', $out) . "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $csv;
|
return $csv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
test/php/library/Icinga/File/CsvTest.php
Normal file
39
test/php/library/Icinga/File/CsvTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Tests\Icinga\File;
|
||||||
|
|
||||||
|
use Mockery;
|
||||||
|
use Icinga\File\Csv;
|
||||||
|
use Icinga\Test\BaseTestCase;
|
||||||
|
|
||||||
|
class CsvTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
public function testWhetherValidCsvIsRendered()
|
||||||
|
{
|
||||||
|
$queryMock = Mockery::mock(
|
||||||
|
'Icinga\Data\BaseQuery',
|
||||||
|
array(
|
||||||
|
'fetchAll' => array(
|
||||||
|
array('col1' => 'val1', 'col2' => 'val2', 'col3' => 'val3', 'col4' => 'val4'),
|
||||||
|
array('col1' => 'val5', 'col2' => 'val6', 'col3' => 'val7', 'col4' => 'val8')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$csv = Csv::fromQuery($queryMock);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
join(
|
||||||
|
"\r\n",
|
||||||
|
array(
|
||||||
|
'col1,col2,col3,col4',
|
||||||
|
'"val1","val2","val3","val4"',
|
||||||
|
'"val5","val6","val7","val8"'
|
||||||
|
)
|
||||||
|
) . "\r\n",
|
||||||
|
(string) $csv,
|
||||||
|
'Csv does not render valid/correct csv structured data'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user