2024-07-22 14:17:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Http\Controllers\CsvController;
|
|
|
|
|
|
|
|
use App\Http\Controllers\CsvController\CsvDataInit;
|
2024-08-17 18:06:06 +02:00
|
|
|
use Tests\TestCase;
|
2024-07-22 14:17:00 +02:00
|
|
|
|
|
|
|
class CsvDataInitTest extends TestCase
|
|
|
|
{
|
|
|
|
|
2024-08-17 18:06:06 +02:00
|
|
|
protected function setUp(): void
|
|
|
|
{parent::setUp();
|
|
|
|
|
2024-08-14 12:46:25 +02:00
|
|
|
$this->csv_data_init = new CsvDataInit();
|
|
|
|
}
|
|
|
|
|
2024-07-22 14:17:00 +02:00
|
|
|
public function testInitialize_csv_data()
|
|
|
|
{
|
2024-08-14 12:46:25 +02:00
|
|
|
$issue = [
|
|
|
|
'repository' => ['name' => 'test'],
|
|
|
|
'number' => 0,
|
|
|
|
'title' => 'test',
|
|
|
|
'html_url' => 'https://git.test.test/issue/0',
|
|
|
|
'created_at' => '2024-08-14-11:00:00',
|
|
|
|
'closed_at' => '2024-08-14-11:00:00',
|
|
|
|
'labels' => [
|
|
|
|
['name' => 'Priority/Low'],
|
|
|
|
['name' => 'RequestBy/Customer'],
|
|
|
|
['name' => 'Status/Resolved'],
|
|
|
|
],
|
|
|
|
'Kind' => '',
|
|
|
|
'RequestBy' => '',
|
|
|
|
'Priority' => '',
|
|
|
|
];
|
|
|
|
|
|
|
|
$result = $this->csv_data_init->initialize_csv_data($issue);
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'Progetto' => 'test',
|
|
|
|
'#' => 0,
|
|
|
|
'Titolo' => 'test',
|
|
|
|
'URL' => 'https://git.test.test/issue/0',
|
|
|
|
'Aperto_il' => '2024-08-14-11:00:00',
|
|
|
|
'Chiuso_il' => '2024-08-14-11:00:00',
|
|
|
|
'Etichette' => 'Priority/Low,RequestBy/Customer,Status/Resolved,',
|
|
|
|
'Kind' => '',
|
|
|
|
'Request By' => '',
|
|
|
|
'Priority' => ''
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2024-07-22 14:17:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandle_labels()
|
|
|
|
{
|
2024-08-14 12:46:25 +02:00
|
|
|
$array = [];
|
|
|
|
$issue_labels = [
|
|
|
|
[
|
|
|
|
'name' => 'Kind: Bug'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'RequestBy: John Doe'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'Priority: High'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'Other Label'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
// Call the handle_labels function
|
|
|
|
$result = $this->csv_data_init->handle_labels($array, $issue_labels);
|
|
|
|
|
|
|
|
// Assert the expected output
|
|
|
|
$this->assertArrayHasKey('Kind', $result);
|
|
|
|
$this->assertEquals('Kind: Bug', $result['Kind']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('Request By', $result);
|
|
|
|
$this->assertEquals('RequestBy: John Doe', $result['Request By']);
|
2024-07-22 14:17:00 +02:00
|
|
|
|
2024-08-14 12:46:25 +02:00
|
|
|
$this->assertArrayHasKey('Priority', $result);
|
|
|
|
$this->assertEquals('Priority: High', $result['Priority']);
|
2024-07-22 14:17:00 +02:00
|
|
|
}
|
|
|
|
}
|