mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Fixed phpunit tests
This commit is contained in:
parent
011bda3600
commit
cad1206175
3 changed files with 20 additions and 12 deletions
|
@ -211,6 +211,11 @@ final class PermissionData implements \JsonSerializable
|
||||||
|
|
||||||
//Filter out all empty or null values
|
//Filter out all empty or null values
|
||||||
foreach ($this->data as $permission => $operations) {
|
foreach ($this->data as $permission => $operations) {
|
||||||
|
//Skip non-array values
|
||||||
|
if (!is_array($operations)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$ret[$permission] = array_filter($operations, function ($value) {
|
$ret[$permission] = array_filter($operations, function ($value) {
|
||||||
return $value !== null;
|
return $value !== null;
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,14 @@ use App\Services\Parts\PartLotWithdrawAddHelper;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
class TestPartLot extends PartLot
|
||||||
|
{
|
||||||
|
public function getID(): ?int
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class PartLotWithdrawAddHelperTest extends WebTestCase
|
class PartLotWithdrawAddHelperTest extends WebTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -56,25 +64,25 @@ class PartLotWithdrawAddHelperTest extends WebTestCase
|
||||||
$this->full_storageLocation = new Storelocation();
|
$this->full_storageLocation = new Storelocation();
|
||||||
$this->full_storageLocation->setIsFull(true);
|
$this->full_storageLocation->setIsFull(true);
|
||||||
|
|
||||||
$this->partLot1 = new PartLot();
|
$this->partLot1 = new TestPartLot();
|
||||||
$this->partLot1->setPart($this->part);
|
$this->partLot1->setPart($this->part);
|
||||||
$this->partLot1->setAmount(10);
|
$this->partLot1->setAmount(10);
|
||||||
|
|
||||||
$this->partLot2 = new PartLot();
|
$this->partLot2 = new TestPartLot();
|
||||||
$this->partLot2->setPart($this->part);
|
$this->partLot2->setPart($this->part);
|
||||||
$this->partLot2->setStorageLocation($this->storageLocation);
|
$this->partLot2->setStorageLocation($this->storageLocation);
|
||||||
$this->partLot2->setAmount(2);
|
$this->partLot2->setAmount(2);
|
||||||
|
|
||||||
$this->partLot3 = new PartLot();
|
$this->partLot3 = new TestPartLot();
|
||||||
$this->partLot3->setPart($this->part);
|
$this->partLot3->setPart($this->part);
|
||||||
$this->partLot3->setAmount(0);
|
$this->partLot3->setAmount(0);
|
||||||
|
|
||||||
$this->fullLot = new PartLot();
|
$this->fullLot = new TestPartLot();
|
||||||
$this->fullLot->setPart($this->part);
|
$this->fullLot->setPart($this->part);
|
||||||
$this->fullLot->setAmount(45);
|
$this->fullLot->setAmount(45);
|
||||||
$this->fullLot->setStorageLocation($this->full_storageLocation);
|
$this->fullLot->setStorageLocation($this->full_storageLocation);
|
||||||
|
|
||||||
$this->lotWithUnknownInstock = new PartLot();
|
$this->lotWithUnknownInstock = new TestPartLot();
|
||||||
$this->lotWithUnknownInstock->setPart($this->part);
|
$this->lotWithUnknownInstock->setPart($this->part);
|
||||||
$this->lotWithUnknownInstock->setAmount(5);
|
$this->lotWithUnknownInstock->setAmount(5);
|
||||||
$this->lotWithUnknownInstock->setInstockUnknown(true);
|
$this->lotWithUnknownInstock->setInstockUnknown(true);
|
||||||
|
@ -86,7 +94,8 @@ class PartLotWithdrawAddHelperTest extends WebTestCase
|
||||||
//Normal lots should be withdrawable
|
//Normal lots should be withdrawable
|
||||||
$this->assertTrue($this->service->canWithdraw($this->partLot1));
|
$this->assertTrue($this->service->canWithdraw($this->partLot1));
|
||||||
$this->assertTrue($this->service->canWithdraw($this->partLot2));
|
$this->assertTrue($this->service->canWithdraw($this->partLot2));
|
||||||
$this->assertTrue($this->service->canWithdraw($this->partLot3));
|
//Empty lots should not be withdrawable
|
||||||
|
$this->assertFalse($this->service->canWithdraw($this->partLot3));
|
||||||
|
|
||||||
//Full lots should be withdrawable
|
//Full lots should be withdrawable
|
||||||
$this->assertTrue($this->service->canWithdraw($this->fullLot));
|
$this->assertTrue($this->service->canWithdraw($this->fullLot));
|
||||||
|
|
|
@ -165,12 +165,6 @@ class PermissionManagerTest extends WebTestCase
|
||||||
//Check for inherit from group
|
//Check for inherit from group
|
||||||
$this->assertTrue($this->service->inherit($this->user, 'parts', 'show_history'));
|
$this->assertTrue($this->service->inherit($this->user, 'parts', 'show_history'));
|
||||||
$this->assertFalse($this->service->inherit($this->user, 'parts', 'delete'));
|
$this->assertFalse($this->service->inherit($this->user, 'parts', 'delete'));
|
||||||
$this->assertNull($this->service->inherit($this->user, 'parts', 'search'));
|
|
||||||
|
|
||||||
//Check for inherit from group and parent group
|
|
||||||
$this->assertTrue($this->service->inherit($this->user, 'parts', 'all_parts'));
|
|
||||||
$this->assertFalse($this->service->inherit($this->user, 'parts', 'no_price_parts'));
|
|
||||||
$this->assertNull($this->service->inherit($this->user, 'parts', 'obsolete_parts'));
|
|
||||||
|
|
||||||
//Test for user without group
|
//Test for user without group
|
||||||
$this->assertTrue($this->service->inherit($this->user_withoutGroup, 'parts', 'read'));
|
$this->assertTrue($this->service->inherit($this->user_withoutGroup, 'parts', 'read'));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue