Files
opensourcepos/tests/Models/ItemTaxesMultipleTest.php
T
objecttothis c004a3f412 feat(items): add server-side "export all" download for items table
Add ability to export the items manage-table results (respecting
current search/filters/sort) to downloadable files in multiple
formats, instead of only the on-screen page.

- app/Controllers/Items.php: new getExportAll(format) endpoint that
  re-runs the current search/filter query, builds raw export rows via
  getItemExportRow(), times db/build/write phases for debug logging,
  and streams back either a PDF response or a generic file download.
- app/Helpers/export_helper.php (new): shared writer dispatch
  (generateExportFile) supporting csv, txt, json, xml, sql, xlsx and
  pdf formats, with per-format value coercion (currency/quantity/
  numeric columns), XLSX temp-file caching with stale-file sweeping,
  and SQL INSERT generation keyed off the target table name.
- app/Helpers/tabular_helper.php: add itemExportHeaders() (manage
  table columns minus UI-only icon columns) and getItemExportRow()
  (unformatted raw values for export consumers); rename
  expand_attribute_values() to expandAttributeValues() and add a
  $raw flag to skip locale decimal formatting for exports.
- app/Controllers/Reports.php: update call sites for the
  expandAttributeValues() rename.
- app/Config/Autoload.php: autoload new 'export' helper.
- app/Config/Mimes.php: register .sql mime type for export downloads.
- app/Controllers/Items.php: getSearch() now defaults missing
  'search' param to '' instead of null.

Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
2026-10-13 15:17:53 +04:00

80 lines
2.4 KiB
PHP

<?php
namespace Tests\Models;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use App\Models\Item_taxes;
use Config\Database;
use Tests\Support\ItemSearchFixtureTrait;
class ItemTaxesMultipleTest extends CIUnitTestCase
{
use DatabaseTestTrait;
use ItemSearchFixtureTrait;
protected $migrate = true;
protected $migrateOnce = true;
protected $seed = '';
protected $seedOnce = true;
protected $refresh = false;
protected $namespace = null;
protected $item_taxes;
public static function setUpBeforeClass(): void
{
$seeder = Database::seeder('tests');
$seeder->call('TestDatabaseBootstrapSeeder');
}
protected function setUp(): void
{
parent::setUp();
$this->item_taxes = model(Item_taxes::class);
}
public function testGetInfoMultipleReturnsTaxesGroupedByItemId(): void
{
$itemOneId = $this->createSearchableItem();
$itemTwoId = $this->createSearchableItem();
$itemOneTaxes = [['name' => 'VAT', 'percent' => 20]];
$itemTwoTaxes = [['name' => 'GST', 'percent' => 10]];
$this->item_taxes->save_value($itemOneTaxes, $itemOneId);
$this->item_taxes->save_value($itemTwoTaxes, $itemTwoId);
$result = $this->item_taxes->getInfoMultiple([$itemOneId, $itemTwoId]);
$this->assertArrayHasKey($itemOneId, $result);
$this->assertArrayHasKey($itemTwoId, $result);
$this->assertCount(1, $result[$itemOneId]);
$this->assertCount(1, $result[$itemTwoId]);
$this->assertEquals('VAT', $result[$itemOneId][0]['name']);
$this->assertEquals('GST', $result[$itemTwoId][0]['name']);
}
public function testGetInfoMultipleItemWithNoTaxesOmittedFromResult(): void
{
$itemWithTaxesId = $this->createSearchableItem();
$itemWithoutTaxesId = $this->createSearchableItem();
$taxes = [['name' => 'VAT', 'percent' => 20]];
$this->item_taxes->save_value($taxes, $itemWithTaxesId);
$result = $this->item_taxes->getInfoMultiple([$itemWithTaxesId, $itemWithoutTaxesId]);
$this->assertArrayHasKey($itemWithTaxesId, $result);
$this->assertArrayNotHasKey($itemWithoutTaxesId, $result);
}
public function testGetInfoMultipleEmptyItemIdsReturnsEmptyArray(): void
{
$result = $this->item_taxes->getInfoMultiple([]);
$this->assertSame([], $result);
}
}