Code:
/** @var CategoriesItem $category */ $category = $application->recallObject('c', null, array('skip_autoload' => true)); $category->Clear(); // Set date from virtual. $category->SetDBFieldsFromHash(array( 'CreatedOn_date' => 1732023005, 'CreatedOn_time' => 1732023005, )); $category->UpdateFormattersMasterFields(); $test_result = $category->GetDBField('CreatedOn') == 1732023005 && $category->GetDBField('CreatedOn_date') == 1732023005 && $category->GetDBField('CreatedOn_time') == 1732023005; echo 'Test 1: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL; // Clear date from virtual. $category->SetDBFieldsFromHash(array( 'CreatedOn_date' => null, 'CreatedOn_time' => null, )); $category->UpdateFormattersMasterFields(); $test_result = $category->GetDBField('CreatedOn') === null && $category->GetDBField('CreatedOn_date') === null && $category->GetDBField('CreatedOn_time') === null; echo 'Test 2: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL; // Set date from combined. $category->SetDBFieldsFromHash(array( 'CreatedOn' => 1732023005, 'CreatedOn_date' => 123, 'CreatedOn_time' => 123, 'CreatedOn_combined' => 1, )); $category->UpdateFormattersMasterFields(); $test_result = $category->GetDBField('CreatedOn') == 1732023005 && $category->GetDBField('CreatedOn_date') == 123 && $category->GetDBField('CreatedOn_time') == 123; echo 'Test 3: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL; // Clear date from combined. $category->SetDBFieldsFromHash(array( 'CreatedOn' => null, 'CreatedOn_date' => 456, 'CreatedOn_time' => 456, 'CreatedOn_combined' => 1, )); $category->UpdateFormattersMasterFields(); $test_result = $category->GetDBField('CreatedOn') === null && $category->GetDBField('CreatedOn_date') == 456 && $category->GetDBField('CreatedOn_time') == 456; echo 'Test 4: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL; // Set date directly. $category->SetDBFieldsFromHash(array( 'CreatedOn' => 1732023005, )); $category->UpdateFormattersSubFields(array('CreatedOn')); $test_result = $category->GetDBField('CreatedOn') == 1732023005 && $category->GetDBField('CreatedOn_date') == 1732023005 && $category->GetDBField('CreatedOn_time') == 1732023005; echo 'Test 5: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL; // Clear date directly. $category->SetDBFieldsFromHash(array( 'CreatedOn' => null, )); $category->UpdateFormattersSubFields(array('CreatedOn')); $test_result = $category->GetDBField('CreatedOn') === null && $category->GetDBField('CreatedOn_date') === null && $category->GetDBField('CreatedOn_time') === null; echo 'Test 6: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL;
Test Plan
- in the IDE replace the $application->Run(); line in the /index.php with the above-shown code and save changes
- open the /index.php in the Web Browser
- confirm, that all tests pass