472 lines
18 KiB
PHP
472 lines
18 KiB
PHP
<?php
|
||
|
||
namespace Tests\Unit;
|
||
|
||
use Tests\TestCase;
|
||
use App\Http\Controllers\AdminController;
|
||
use ReflectionClass;
|
||
use Illuminate\Support\Facades\Schema;
|
||
use Illuminate\Database\Schema\Blueprint;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Config;
|
||
|
||
|
||
class TrimDataTest extends TestCase
|
||
{
|
||
private $adminController;
|
||
private $trimDataMethod;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
Config::set('database.default', 'mysql');
|
||
Config::set('database.connections.mysql.host', 'localhost');
|
||
Config::set('database.connections.mysql.port', '3307');
|
||
Config::set('database.connections.mysql.database', 'stellar_dev');
|
||
Config::set('database.connections.mysql.username', 'stellar_test');
|
||
Config::set('database.connections.mysql.password', 'pGyPXtEmRK1c');
|
||
|
||
// Test veritabanını oluştur
|
||
$this->createTestDatabase();
|
||
|
||
// AdminController instance oluştur
|
||
$this->adminController = new AdminController();
|
||
|
||
// Private method'a erişim için reflection kullan
|
||
$reflection = new ReflectionClass($this->adminController);
|
||
$this->trimDataMethod = $reflection->getMethod('trimData');
|
||
$this->trimDataMethod->setAccessible(true);
|
||
|
||
// currentTable property'sine erişim
|
||
$currentTableProperty = $reflection->getProperty('currentTable');
|
||
$currentTableProperty->setAccessible(true);
|
||
$currentTableProperty->setValue($this->adminController, 'weld_logs');
|
||
}
|
||
|
||
private function createTestDatabase()
|
||
{
|
||
|
||
}
|
||
|
||
public function testTrimDataWithDateFields()
|
||
{
|
||
// Test verisi
|
||
$testData = [
|
||
'welding_date' => ' 2024-03-20 ',
|
||
'pwht_date' => ' 2024-03-21',
|
||
'empty_date' => '',
|
||
'null_date' => null
|
||
];
|
||
|
||
// trimData metodunu çağır
|
||
$result = $this->trimDataMethod->invoke($this->adminController, $testData);
|
||
|
||
// Assertions
|
||
$this->assertEquals('2024-03-20', $result['welding_date']);
|
||
$this->assertEquals('2024-03-21', $result['pwht_date']);
|
||
$this->assertNull($result['null_date']);
|
||
$this->assertEmpty($result['empty_date']);
|
||
|
||
}
|
||
|
||
public function testTrimDataWithStringFields()
|
||
{
|
||
// Test verisi
|
||
$testData = [
|
||
'welder_1' => ' John Doe ',
|
||
'iso_number' => ' ISO-123 ',
|
||
'empty_string' => '',
|
||
'null_string' => null,
|
||
'remarks' => " Test String "
|
||
];
|
||
|
||
// trimData metodunu çağır
|
||
$result = $this->trimDataMethod->invoke($this->adminController, $testData);
|
||
|
||
// Assertions
|
||
$this->assertEquals('John Doe', $result['welder_1']);
|
||
$this->assertEquals('ISO-123', $result['iso_number']);
|
||
$this->assertNull($result['empty_string']);
|
||
$this->assertNull($result['null_string']);
|
||
$this->assertEquals('Test String', $result['remarks']);
|
||
}
|
||
|
||
public function testTrimDataWithNumericFields()
|
||
{
|
||
// Test verisi
|
||
$testData = [
|
||
'design_temperature_s' => ' 12.5 ',
|
||
'design_pressure_mpa' => '25',
|
||
'empty_number' => '',
|
||
'null_number' => null
|
||
];
|
||
|
||
// trimData metodunu çağır
|
||
$result = $this->trimDataMethod->invoke($this->adminController, $testData);
|
||
|
||
// Assertions
|
||
$this->assertEquals('12.5', $result['design_temperature_s']);
|
||
$this->assertEquals('25', $result['design_pressure_mpa']);
|
||
$this->assertNull($result['empty_number']);
|
||
$this->assertNull($result['null_number']);
|
||
}
|
||
|
||
public function testTrimDataWithMixedFields()
|
||
{
|
||
// Test verisi
|
||
$testData = [
|
||
'welding_date' => '2024-03-20 (Europe/Istanbul)',
|
||
'welder_1' => ' John Doe ',
|
||
'design_temperature_s' => ' 12.5 ',
|
||
];
|
||
|
||
// trimData metodunu çağır
|
||
$result = $this->trimDataMethod->invoke($this->adminController, $testData);
|
||
|
||
// Assertions
|
||
$this->assertEquals('2024-03-20', $result['welding_date']);
|
||
$this->assertEquals('John Doe', $result['welder_1']);
|
||
$this->assertEquals('12.5', $result['design_temperature_s']);
|
||
|
||
}
|
||
|
||
public function testTrimDataWithAllPossibleTypes()
|
||
{
|
||
// Test verisi - weld_logs tablosundaki tüm olası alan tipleri için
|
||
$testData = [
|
||
// Tarih alanları
|
||
'welding_date' => '2024-03-20',
|
||
'invalid_date' => '',
|
||
'created_at' => '2024-03-22 14:30:00',
|
||
'updated_at' => '2024-03-22 15:45:00',
|
||
|
||
// String alanları
|
||
'welder_1' => ' John Doe ',
|
||
'iso_number' => ' ISO-123 ',
|
||
'wps_no' => ' WPS-001 ',
|
||
'design_temperature_s' => ' 12.5 ',
|
||
'design_pressure_mpa' => ' 25 ',
|
||
'nps_1' => ' 10.25 ',
|
||
'remarks' => ' Test String ',
|
||
|
||
|
||
// Numerik alanlar
|
||
|
||
// Boş ve null değerler
|
||
'empty_field' => '',
|
||
'null_field' => null,
|
||
|
||
|
||
];
|
||
|
||
// trimData metodunu çağır
|
||
$result = $this->trimDataMethod->invoke($this->adminController, $testData);
|
||
|
||
// Assertions
|
||
// Tarih alanları
|
||
$this->assertEquals('2024-03-20', $result['welding_date']);
|
||
$this->assertEquals('2024-03-22 14:30:00', $result['created_at']);
|
||
$this->assertEquals('2024-03-22 15:45:00', $result['updated_at']);
|
||
|
||
// String alanları
|
||
$this->assertEquals('John Doe', $result['welder_1']);
|
||
$this->assertEquals('ISO-123', $result['iso_number']);
|
||
$this->assertEquals('WPS-001', $result['wps_no']);
|
||
|
||
// Numerik alanlar
|
||
$this->assertEquals('12.5', $result['design_temperature_s']);
|
||
$this->assertEquals('25', $result['design_pressure_mpa']);
|
||
$this->assertEquals('10.25', $result['nps_1']);
|
||
|
||
// Boş ve null değerler
|
||
$this->assertNull($result['empty_field']);
|
||
$this->assertNull($result['null_field']);
|
||
$this->assertNull($result['invalid_date']);
|
||
|
||
// Özel karakterli string'ler
|
||
$this->assertEquals('Test String', $result['remarks']);
|
||
|
||
}
|
||
|
||
public function testTrimDataWithAllWeldLogsColumns()
|
||
{
|
||
// Test verisi - weld_logs tablosundaki tüm sütunlar için
|
||
$testData = [
|
||
// Genel Bilgiler
|
||
'general_contractor' => ' STELLAR ',
|
||
'contractor' => ' ABC Company ',
|
||
'ste_subcontractor' => ' XYZ Corp ',
|
||
'project' => ' Project 123 ',
|
||
'design_area' => ' Area 51 ',
|
||
'line_specification' => ' SPEC-001 ',
|
||
'line_number' => ' LINE-123 ',
|
||
'main_material' => ' Steel ',
|
||
'main_nps' => ' 2" ',
|
||
'fluid_code' => ' FC-001 ',
|
||
'service_category' => ' CAT-A ',
|
||
'fluid_group' => ' Group 1 ',
|
||
'piping_class' => ' Class A ',
|
||
|
||
// Tasarım Değerleri
|
||
'design_temperature_s' => ' 150 ',
|
||
'design_pressure_mpa' => ' 2.5 ',
|
||
'operating_temperature_s' => ' 120 ',
|
||
'operating_pressure_mpa' => ' 2.0 ',
|
||
'painting_cycle' => ' PC-001 ',
|
||
'external_finish_type' => ' Type A ',
|
||
|
||
// ISO ve Spool Bilgileri
|
||
'iso_number' => ' ISO-123-456 ',
|
||
'quantity_of_iso' => ' 5 ',
|
||
'iso_rev' => ' Rev.2 ',
|
||
'spool_number' => ' SP-001 ',
|
||
'spool_number2' => ' SP-002 ',
|
||
'spool_release_date' => '2024-03-20',
|
||
|
||
// Kaynak Bilgileri
|
||
'type_of_joint' => ' Butt Joint ',
|
||
'no_of_the_joint_as_per_as_built_survey' => ' J-001 ',
|
||
'type_of_welds' => ' Full Penetration ',
|
||
'welding_date' => '2024-03-21',
|
||
'wps_no' => ' WPS-001 ',
|
||
'wps_approval_date' => '2024-03-19',
|
||
'welding_method' => ' SMAW ',
|
||
|
||
// Kaynak Malzemeleri
|
||
'welding_materials_1' => ' E7018 ',
|
||
'welding_materials_1_lot_no' => ' LOT-001 ',
|
||
'welding_materials_1_certificate_no' => ' CERT-001 ',
|
||
'welding_materials_2' => ' E6010 ',
|
||
'welding_materials_2_lot_no' => ' LOT-002 ',
|
||
'welding_materials_2_certificate_no' => ' CERT-002 ',
|
||
'welding_materials_3' => ' E7024 ',
|
||
'welding_materials_3_lot_no' => ' LOT-003 ',
|
||
'welding_materials_3_certificate_no' => ' CERT-003 ',
|
||
|
||
// Personel Bilgileri
|
||
'welder_1' => ' John Doe ',
|
||
'welder_2' => ' Jane Smith ',
|
||
'mechanic_supervisor' => ' Mike Johnson ',
|
||
'mechanic_supervisor_control_date' => '2024-03-22',
|
||
'welding_supervisor' => ' Tom Wilson ',
|
||
'welding_supervisor_control_date' => '2024-03-22',
|
||
|
||
// Sertifika Bilgileri
|
||
'certificate_no_1' => ' CERT-W1 ',
|
||
'wpq_report_1' => ' WPQ-001 ',
|
||
'certificate_no_2' => ' CERT-W2 ',
|
||
'wpq_report_2' => ' WPQ-002 ',
|
||
|
||
// Malzeme Bilgileri 1
|
||
'pose_no_1' => ' P001 ',
|
||
'element_code_1' => ' EC-001 ',
|
||
'member_no_1' => ' M001 ',
|
||
'material_no_1' => ' MAT-001 ',
|
||
'ru_material_group_1' => ' RU-001 ',
|
||
'certificate_number_of_1' => ' CERT-M1 ',
|
||
'heat_number_1' => ' HT-001 ',
|
||
'nps_1' => ' 2" ',
|
||
'thickness_by_asme_1' => ' 12.5 ',
|
||
'outside_diameter_1' => ' 60.3 ',
|
||
'wall_thickness_1' => ' 5.54 ',
|
||
|
||
// Malzeme Bilgileri 2
|
||
'pose_no_2' => ' P002 ',
|
||
'element_code_2' => ' EC-002 ',
|
||
'member_no_2' => ' M002 ',
|
||
'material_no_2' => ' MAT-002 ',
|
||
'ru_material_group_2' => ' RU-002 ',
|
||
'certificate_number_of_2' => ' CERT-M2 ',
|
||
'heat_number_2' => ' HT-002 ',
|
||
'nps_2' => ' 2" ',
|
||
'thickness_by_asme_2' => ' 12.5 ',
|
||
'outside_diameter_2' => ' 60.3 ',
|
||
'wall_thickness_2' => ' 5.54 ',
|
||
|
||
// NDT Bilgileri
|
||
'ndt_percent' => ' 100 ',
|
||
|
||
// VT Test Bilgileri
|
||
'vt_scope' => ' 100% ',
|
||
'vt_request_no' => ' VT-001 ',
|
||
'vt_report' => ' VT-REP-001 ',
|
||
'date_of_vt' => '2024-03-23',
|
||
'vt_request_date' => '2024-03-22',
|
||
'test_laboratory_vt' => ' LAB-001 ',
|
||
'vt_result' => ' Accepted ',
|
||
'vt_test_date' => '2024-03-23',
|
||
|
||
// RT Test Bilgileri
|
||
'rt_scope' => ' 100% ',
|
||
'rt_request_no' => ' RT-001 ',
|
||
'rt_report' => ' RT-REP-001 ',
|
||
'rt_test_date' => '2024-03-24',
|
||
'rt_request_date' => '2024-03-23',
|
||
'test_laboratory_rt' => ' LAB-002 ',
|
||
'rt_result' => ' Accepted ',
|
||
|
||
// UT Test Bilgileri
|
||
'ut_scope' => ' 100% ',
|
||
'ut_request_no' => ' UT-001 ',
|
||
'ut_report' => ' UT-REP-001 ',
|
||
'ut_test_date' => '2024-03-25',
|
||
'ut_request_date' => '2024-03-24',
|
||
'test_laboratory_ut' => ' LAB-003 ',
|
||
'ut_result' => ' Accepted ',
|
||
'ut_type' => ' Type A ',
|
||
|
||
// PT Test Bilgileri
|
||
'pt_scope' => ' 100% ',
|
||
'pt_request_no' => ' PT-001 ',
|
||
'pt_report' => ' PT-REP-001 ',
|
||
'pt_test_date' => '2024-03-26',
|
||
'pt_request_date' => '2024-03-25',
|
||
'test_laboratory_pt' => ' LAB-004 ',
|
||
'pt_result' => ' Accepted ',
|
||
|
||
// MT Test Bilgileri
|
||
'mt_scope' => ' 100% ',
|
||
'mt_request_no' => ' MT-001 ',
|
||
'mt_report' => ' MT-REP-001 ',
|
||
'mt_test_date' => '2024-03-27',
|
||
'mt_request_date' => '2024-03-26',
|
||
'test_laboratory_mt' => ' LAB-005 ',
|
||
'mt_result' => ' Accepted ',
|
||
|
||
// PMI Test Bilgileri
|
||
'pmi_scope' => ' 100% ',
|
||
'pmi_request_no' => ' PMI-001 ',
|
||
'pmi_report' => ' PMI-REP-001 ',
|
||
'no_of_testing_report' => ' TR-001 ',
|
||
'pmi_test_date' => '2024-03-28',
|
||
'pmi_request_date' => '2024-03-27',
|
||
'test_laboratory_pmi' => ' LAB-006 ',
|
||
'pmi_result' => ' Accepted ',
|
||
|
||
// NDE ve Grup Bilgileri
|
||
'nde' => ' NDE-001 ',
|
||
'group_no' => ' G-001 ',
|
||
|
||
// PWHT Bilgileri
|
||
'pwht' => ' Yes ',
|
||
'pwht_date' => '2024-03-29',
|
||
'no_of_pwht_report' => ' PWHT-001 ',
|
||
'diagram_number_pwht' => ' DIA-001 ',
|
||
'test_laboratory_pwht' => ' LAB-007 ',
|
||
|
||
// HT Test Bilgileri
|
||
'ht_scope' => ' 100% ',
|
||
'ht_request_no' => ' HT-001 ',
|
||
'ht_request_date' => '2024-03-28',
|
||
'ht_test_date' => '2024-03-29',
|
||
'no_of_ht_hardnes_test' => ' HHT-001 ',
|
||
'date_of_hardnes_test' => '2024-03-29',
|
||
'test_laboratory_ht' => ' LAB-008 ',
|
||
'ht_result' => ' Accepted ',
|
||
|
||
// Ferrit Test Bilgileri
|
||
'ferrite_scope' => ' 100% ',
|
||
'ferrite_check_request_no' => ' FC-001 ',
|
||
'no_of_ferrite_check' => ' FC-001 ',
|
||
'date_of_ferrite_check' => '2024-03-30',
|
||
'test_laboratory_ferrite' => ' LAB-009 ',
|
||
'ferrite_result' => ' Accepted ',
|
||
|
||
// Test Paketi Bilgileri
|
||
'test_package_no' => ' TP-001 ',
|
||
'piping_type' => ' Type A ',
|
||
'p_id' => ' PID-001 ',
|
||
'test_pressure' => ' 3.0 ',
|
||
'type_of_test' => ' Hydro ',
|
||
'date_test' => '2024-03-31',
|
||
'test_result' => ' Accepted ',
|
||
|
||
// Ek Bilgiler
|
||
'real_welder_1' => ' John Doe ',
|
||
'real_welder_2' => ' Jane Smith ',
|
||
'ste_subcontructer' => ' SUB-001 ',
|
||
'remarks' => ' Test Remarks ',
|
||
'fit_up_date' => '2024-04-01',
|
||
'ndt_release_date' => '2024-04-02',
|
||
'paint_release_date' => '2024-04-03',
|
||
'ndt_release_no' => ' NDT-001 ',
|
||
'paint_release_no' => ' PR-001 ',
|
||
'spool_zone' => ' Zone A ',
|
||
'spool_status' => ' Active ',
|
||
'nde_pwht' => ' Yes ',
|
||
|
||
// Ferrit ve PWHT Ek Bilgileri
|
||
'ferrite_request_date' => '2024-04-04',
|
||
'ferrite_request_no' => ' FR-001 ',
|
||
'ferrite_report' => ' FR-REP-001 ',
|
||
'ferrite_test_date' => '2024-04-05',
|
||
'pwht_request_date' => '2024-04-06',
|
||
'pwht_request_no' => ' PWHT-001 ',
|
||
'pwht_result' => ' Accepted ',
|
||
'pwht_scope' => ' 100% ',
|
||
'pwht_report' => ' PWHT-REP-001 ',
|
||
'pwht_test_date' => '2024-04-07',
|
||
|
||
// Kontrol ve Durum Bilgileri
|
||
'spool_ndt_check' => ' Yes ',
|
||
'spool_paint_check' => ' Yes ',
|
||
'spool_ndt_check_no' => ' NDT-CHK-001 ',
|
||
'ndt_release_check' => ' Yes ',
|
||
'paint_release_check' => ' Yes ',
|
||
'circuit_number' => ' CIR-001 ',
|
||
'tp_status' => ' Active ',
|
||
'clearance_no' => ' CLR-001 ',
|
||
'register_paint_no' => ' RP-001 ',
|
||
'register_date' => '2024-04-08',
|
||
|
||
// Operatör ve PDF Bilgileri
|
||
'pwht_operator_name' => ' Tom Wilson ',
|
||
'pwht_operator_id' => ' OP-001 ',
|
||
'pdf_engineering' => ' PDF-001 ',
|
||
'pdf_spool_iso' => ' PDF-002 ',
|
||
'spool_ndt_check_date' => '2024-04-09',
|
||
'clearance_date' => '2024-04-10',
|
||
'spool_remarks' => ' Additional Remarks '
|
||
];
|
||
|
||
// trimData metodunu çağır
|
||
$result = $this->trimDataMethod->invoke($this->adminController, $testData);
|
||
|
||
// Assertions - Örnek kontroller
|
||
// Tarih alanları
|
||
$this->assertEquals('2024-03-20', $result['spool_release_date']);
|
||
$this->assertEquals('2024-03-21', $result['welding_date']);
|
||
$this->assertEquals('2024-03-19', $result['wps_approval_date']);
|
||
|
||
// String alanları
|
||
$this->assertEquals('STELLAR', $result['general_contractor']);
|
||
$this->assertEquals('ABC Company', $result['contractor']);
|
||
$this->assertEquals('XYZ Corp', $result['ste_subcontractor']);
|
||
|
||
// Numerik alanları
|
||
$this->assertEquals('150', $result['design_temperature_s']);
|
||
$this->assertEquals('2.5', $result['design_pressure_mpa']);
|
||
$this->assertEquals('100', $result['ndt_percent']);
|
||
|
||
// Boş alanlar için kontrol
|
||
$this->assertArrayHasKey('remarks', $result);
|
||
$this->assertEquals('Test Remarks', $result['remarks']);
|
||
|
||
// Özel karakterli alanlar
|
||
$this->assertEquals('ISO-123-456', $result['iso_number']);
|
||
$this->assertEquals('SP-001', $result['spool_number']);
|
||
|
||
// PWHT Operatör bilgileri
|
||
$this->assertEquals('Tom Wilson', $result['pwht_operator_name']);
|
||
$this->assertEquals('OP-001', $result['pwht_operator_id']);
|
||
|
||
// Test sonuçları
|
||
$this->assertEquals('Accepted', $result['vt_result']);
|
||
$this->assertEquals('Accepted', $result['rt_result']);
|
||
$this->assertEquals('Accepted', $result['ut_result']);
|
||
$this->assertEquals('Accepted', $result['pt_result']);
|
||
$this->assertEquals('Accepted', $result['mt_result']);
|
||
$this->assertEquals('Accepted', $result['pmi_result']);
|
||
}
|
||
}
|