mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-11-08 23:43:32 -05:00
Add feature tests verifying CSV/PDF/XML/SQL export endpoints work correctly across many controllers, plus helper unit tests and shared fixtures to support them. - Add downloadResponseBody() reflection helper (reads private $binary property on DownloadResponse) to CashupControllerTest, EmployeesControllerTest, ItemKitsControllerTest for asserting streamed download content - Add exportAll CSV/PDF tests for Attributes, Customers, Expenses_categories, Expenses, Giftcards, ItemKits, Cashup, Employees controllers - Add export_helperTest covering CSV sanitization (formula injection guard), JSON/XML/SQL writers, tag sanitization, and file generation - Add Tests/Support/ExportFixtureTrait with reusable fixture objects for sales, employees, customers, suppliers, items, giftcards, item kits, attributes, expenses, cashups, tax rates - Update AGENTS.md: clarify `use` import rule applies to every reference including global-namespace classes (ReflectionClass/ReflectionProperty/Exception) and method-signature type-hints, not just namespaced app classes Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
141 lines
4.1 KiB
PHP
141 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Controllers;
|
|
|
|
use App\Models\Supplier;
|
|
use CodeIgniter\Database\Config;
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
use CodeIgniter\Test\DatabaseTestTrait;
|
|
use CodeIgniter\Test\FeatureTestTrait;
|
|
use Tests\Support\EmployeeFixtureTrait;
|
|
|
|
class SuppliersControllerTest extends CIUnitTestCase
|
|
{
|
|
use DatabaseTestTrait;
|
|
use FeatureTestTrait;
|
|
use EmployeeFixtureTrait;
|
|
|
|
protected $migrate = true;
|
|
protected $migrateOnce = true;
|
|
protected $seedOnce = true;
|
|
protected $refresh = false;
|
|
protected $namespace = null;
|
|
|
|
private static $doneBootstrap = false;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
if (self::$doneBootstrap === false) {
|
|
Config::seeder($this->DBGroup)->call('App\Database\Seeds\TestDatabaseBootstrapSeeder');
|
|
Config::connect($this->DBGroup)->close();
|
|
|
|
self::$doneBootstrap = true;
|
|
}
|
|
|
|
parent::setUp();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
parent::tearDown();
|
|
}
|
|
|
|
protected function createSuppliersEmployee(): int
|
|
{
|
|
return $this->createEmployee(
|
|
grants: [
|
|
['permission_id' => 'suppliers', 'menu_group' => 'home'],
|
|
]
|
|
);
|
|
}
|
|
|
|
protected function loginAsSuppliersEmployee(int $personId): void
|
|
{
|
|
$this->withSession([
|
|
'person_id' => $personId,
|
|
'menu_group' => 'home',
|
|
]);
|
|
}
|
|
|
|
private function seedSupplier(string $companyName): void
|
|
{
|
|
$personData = [
|
|
'first_name' => 'Richard',
|
|
'last_name' => 'Roe',
|
|
'gender' => 'male',
|
|
'email' => 'supplier.' . uniqid() . '@test.com',
|
|
'phone_number' => '555-9999',
|
|
'address_1' => '',
|
|
'address_2' => '',
|
|
'city' => '',
|
|
'state' => '',
|
|
'zip' => '',
|
|
'country' => '',
|
|
'comments' => '',
|
|
];
|
|
|
|
$supplierData = [
|
|
'company_name' => $companyName,
|
|
'agency_name' => '',
|
|
'category' => '',
|
|
'account_number' => null,
|
|
'tax_id' => '',
|
|
];
|
|
|
|
model(Supplier::class)->save_supplier($personData, $supplierData);
|
|
}
|
|
|
|
public function testGetExportAll_StreamsCsvDownload(): void
|
|
{
|
|
$employeeId = $this->createSuppliersEmployee();
|
|
$this->loginAsSuppliersEmployee($employeeId);
|
|
|
|
$companyName = 'Acme Corp ' . uniqid();
|
|
$this->seedSupplier($companyName);
|
|
|
|
$response = $this->get('/suppliers/exportAll/csv');
|
|
|
|
$response->assertStatus(200);
|
|
$contentDisposition = $response->getHeaderLine('Content-Disposition');
|
|
$this->assertStringContainsString('attachment', $contentDisposition);
|
|
$this->assertStringContainsString('suppliers_', $contentDisposition);
|
|
$this->assertStringContainsString($companyName, $response->getBody());
|
|
}
|
|
|
|
public function testGetExportAll_StreamsPdfDownload(): void
|
|
{
|
|
$employeeId = $this->createSuppliersEmployee();
|
|
$this->loginAsSuppliersEmployee($employeeId);
|
|
|
|
$this->seedSupplier('Acme Corp ' . uniqid());
|
|
|
|
$response = $this->get('/suppliers/exportAll/pdf');
|
|
|
|
$response->assertStatus(200);
|
|
$this->assertStringContainsString('application/pdf', $response->getHeaderLine('Content-Type'));
|
|
}
|
|
|
|
public function testGetExportAll_DoesNotTruncateToTwentyFiveRows(): void
|
|
{
|
|
$employeeId = $this->createSuppliersEmployee();
|
|
$this->loginAsSuppliersEmployee($employeeId);
|
|
|
|
$uniqueSuffix = uniqid();
|
|
$companyNames = [];
|
|
for ($i = 0; $i < 26; $i++) {
|
|
$companyName = "SupplierBulk{$uniqueSuffix}_{$i}";
|
|
$companyNames[] = $companyName;
|
|
$this->seedSupplier($companyName);
|
|
}
|
|
|
|
$response = $this->get('/suppliers/exportAll/csv');
|
|
|
|
$response->assertStatus(200);
|
|
$body = $response->getBody();
|
|
|
|
foreach ($companyNames as $companyName) {
|
|
$this->assertStringContainsString($companyName, $body);
|
|
}
|
|
}
|
|
}
|