2020-01-11 06:30:25 +00:00
|
|
|
|
<?php
|
2021-11-18 04:24:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-18 04:24:30 +00:00
|
|
|
|
namespace AtolOnline\Tests;
|
|
|
|
|
|
|
|
|
|
use AtolOnline\{
|
|
|
|
|
Constants\PaymentMethods,
|
2020-01-11 06:30:25 +00:00
|
|
|
|
Constants\PaymentObjects,
|
|
|
|
|
Constants\VatTypes,
|
|
|
|
|
Entities\Item,
|
2021-11-18 04:24:30 +00:00
|
|
|
|
Exceptions\BasicTooManyException,
|
|
|
|
|
Exceptions\TooHighPriceException,
|
|
|
|
|
Exceptions\TooLongNameException,
|
|
|
|
|
Exceptions\TooLongUnitException,
|
|
|
|
|
Exceptions\TooLongUserdataException,};
|
2020-01-11 06:30:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class ItemTest
|
|
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
|
class ItemTestTodo extends BasicTestCase
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку параметров через конструктор
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws AtolOnline\Exceptions\TooLongNameException
|
|
|
|
|
* @throws AtolOnline\Exceptions\TooHighPriceException
|
|
|
|
|
* @throws AtolOnline\Exceptions\BasicTooManyException
|
|
|
|
|
* @throws AtolOnline\Exceptions\TooLongUnitException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructor()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item(
|
|
|
|
|
'Банан',
|
|
|
|
|
65.99,
|
|
|
|
|
2.74,
|
|
|
|
|
'кг',
|
|
|
|
|
VatTypes::NONE,
|
|
|
|
|
PaymentObjects::COMMODITY,
|
|
|
|
|
PaymentMethods::FULL_PAYMENT
|
|
|
|
|
);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->assertAtolable($item);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$this->assertEquals('Банан', $item->getName());
|
|
|
|
|
$this->assertEquals(65.99, $item->getPrice());
|
|
|
|
|
$this->assertEquals(2.74, $item->getQuantity());
|
|
|
|
|
$this->assertEquals('кг', $item->getMeasurementUnit());
|
|
|
|
|
$this->assertEquals(VatTypes::NONE, $item->getVat()->getType());
|
|
|
|
|
$this->assertEquals(PaymentObjects::COMMODITY, $item->getPaymentObject());
|
|
|
|
|
$this->assertEquals(PaymentMethods::FULL_PAYMENT, $item->getPaymentMethod());
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку параметров через сеттеры
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws AtolOnline\Exceptions\TooLongNameException
|
|
|
|
|
* @throws AtolOnline\Exceptions\TooHighPriceException
|
|
|
|
|
* @throws AtolOnline\Exceptions\BasicTooManyException
|
|
|
|
|
* @throws AtolOnline\Exceptions\TooLongUnitException
|
|
|
|
|
* @throws AtolOnline\Exceptions\TooLongUserdataException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testSetters()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
|
|
|
|
$item->setName('Банан');
|
|
|
|
|
$item->setPrice(65.99);
|
|
|
|
|
$item->setQuantity(2.74);
|
|
|
|
|
$item->setMeasurementUnit('кг');
|
|
|
|
|
$item->setVatType(VatTypes::NONE);
|
|
|
|
|
$item->setPaymentObject(PaymentObjects::COMMODITY);
|
|
|
|
|
$item->setPaymentMethod(PaymentMethods::FULL_PAYMENT);
|
|
|
|
|
$item->setUserData('Some user data');
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->assertAtolable($item);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$this->assertEquals('Банан', $item->getName());
|
|
|
|
|
$this->assertEquals(65.99, $item->getPrice());
|
|
|
|
|
$this->assertEquals(2.74, $item->getQuantity());
|
|
|
|
|
$this->assertEquals('кг', $item->getMeasurementUnit());
|
|
|
|
|
$this->assertEquals(VatTypes::NONE, $item->getVat()->getType());
|
|
|
|
|
$this->assertEquals(PaymentObjects::COMMODITY, $item->getPaymentObject());
|
|
|
|
|
$this->assertEquals(PaymentMethods::FULL_PAYMENT, $item->getPaymentMethod());
|
|
|
|
|
$this->assertEquals('Some user data', $item->getUserData());
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку ставки НДС разными путями
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws TooHighPriceException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testSetVat()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
|
|
|
|
$item->setVatType(VatTypes::NONE);
|
|
|
|
|
$this->assertEquals(VatTypes::NONE, $item->getVat()->getType());
|
|
|
|
|
$item->setVatType(VatTypes::VAT20);
|
|
|
|
|
$this->assertEquals(VatTypes::VAT20, $item->getVat()->getType());
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком длинном наименовании
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws TooLongNameException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolNameTooLongException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->expectException(TooLongNameException::class);
|
|
|
|
|
$item->setName(Helpers::randomStr(130));
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком высоком количестве
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws TooHighPriceException
|
|
|
|
|
* @throws BasicTooManyException
|
|
|
|
|
* @throws TooLongUnitException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolQuantityTooHighException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->expectException(BasicTooManyException::class);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$item->setQuantity(100000.1);
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком высокой цене
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws TooHighPriceException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolPriceTooHighException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->expectException(TooHighPriceException::class);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$item->setPrice(42949673.1);
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком длинных польз. данных
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws TooLongUserdataException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolUserdataTooLongException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->expectException(TooLongUserdataException::class);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$item->setUserData('User data User data User data User data User data User data User data');
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком длинной единице измерения
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws TooLongUnitException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolUnitTooLongException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
2021-11-18 04:24:30 +00:00
|
|
|
|
$this->expectException(TooLongUnitException::class);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$item->setMeasurementUnit('кг кг кг кг кг кг кг кг кг ');
|
|
|
|
|
}
|
|
|
|
|
}
|