2020-01-11 06:30:25 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) Антон Аксенов (aka Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
use AtolOnline\{Constants\PaymentMethods,
|
|
|
|
|
Constants\PaymentObjects,
|
|
|
|
|
Constants\VatTypes,
|
|
|
|
|
Entities\Item,
|
|
|
|
|
Exceptions\AtolNameTooLongException,
|
|
|
|
|
Exceptions\AtolPriceTooHighException,
|
2020-05-27 15:10:30 +00:00
|
|
|
|
Exceptions\AtolTooManyException,
|
2020-01-11 06:30:25 +00:00
|
|
|
|
Exceptions\AtolUnitTooLongException,
|
2020-05-27 15:10:30 +00:00
|
|
|
|
Exceptions\AtolUserdataTooLongException};
|
2020-01-11 06:30:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class ItemTest
|
|
|
|
|
*/
|
|
|
|
|
class ItemTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку параметров через конструктор
|
|
|
|
|
*
|
|
|
|
|
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
|
|
|
|
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
2020-05-27 15:10:30 +00:00
|
|
|
|
* @throws AtolOnline\Exceptions\AtolTooManyException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructor()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item(
|
|
|
|
|
'Банан',
|
|
|
|
|
65.99,
|
|
|
|
|
2.74,
|
|
|
|
|
'кг',
|
|
|
|
|
VatTypes::NONE,
|
|
|
|
|
PaymentObjects::COMMODITY,
|
|
|
|
|
PaymentMethods::FULL_PAYMENT
|
|
|
|
|
);
|
|
|
|
|
$this->checkAtolEntity($item);
|
|
|
|
|
$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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку параметров через сеттеры
|
|
|
|
|
*
|
|
|
|
|
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
|
|
|
|
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
2020-05-27 15:10:30 +00:00
|
|
|
|
* @throws AtolOnline\Exceptions\AtolTooManyException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
|
|
|
* @throws AtolOnline\Exceptions\AtolUserdataTooLongException
|
|
|
|
|
*/
|
|
|
|
|
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');
|
|
|
|
|
$this->checkAtolEntity($item);
|
|
|
|
|
$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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку ставки НДС разными путями
|
|
|
|
|
*
|
2020-05-29 14:15:47 +00:00
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком длинном наименовании
|
|
|
|
|
*
|
2020-05-29 14:15:47 +00:00
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolNameTooLongException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
|
|
|
|
$this->expectException(AtolNameTooLongException::class);
|
2020-05-29 14:15:47 +00:00
|
|
|
|
$item->setName(self::randomString(130));
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком высоком количестве
|
|
|
|
|
*
|
2020-05-29 14:15:47 +00:00
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException
|
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolTooManyException
|
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolUnitTooLongException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolQuantityTooHighException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
2020-05-27 15:10:30 +00:00
|
|
|
|
$this->expectException(AtolTooManyException::class);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$item->setQuantity(100000.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком высокой цене
|
|
|
|
|
*
|
2020-05-29 14:15:47 +00:00
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolPriceTooHighException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
|
|
|
|
$this->expectException(AtolPriceTooHighException::class);
|
|
|
|
|
$item->setPrice(42949673.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком длинных польз. данных
|
|
|
|
|
*
|
2020-05-29 14:15:47 +00:00
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolUserdataTooLongException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolUserdataTooLongException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
|
|
|
|
$this->expectException(AtolUserdataTooLongException::class);
|
|
|
|
|
$item->setUserData('User data User data User data User data User data User data User data');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о слишком длинной единице измерения
|
|
|
|
|
*
|
2020-05-29 14:15:47 +00:00
|
|
|
|
* @throws \AtolOnline\Exceptions\AtolUnitTooLongException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testAtolUnitTooLongException()
|
|
|
|
|
{
|
|
|
|
|
$item = new Item();
|
|
|
|
|
$this->expectException(AtolUnitTooLongException::class);
|
|
|
|
|
$item->setMeasurementUnit('кг кг кг кг кг кг кг кг кг ');
|
|
|
|
|
}
|
|
|
|
|
}
|