Added an PHP CS fixer config file and applied it to files.

We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
Jan Böhmer 2019-11-09 00:47:20 +01:00
parent 89258bc102
commit e557bdedd5
210 changed files with 2099 additions and 2742 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,29 +17,21 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
abstract class AbstractAdminControllerTest extends WebTestCase
{
protected static $base_path = 'not_valid';
protected static $entity_class = 'not valid';
public function setUp()
{
parent::setUp();
@ -52,7 +44,7 @@ abstract class AbstractAdminControllerTest extends WebTestCase
['noread', false],
['anonymous', true],
['user', true],
['admin', true]
['admin', true],
];
}
@ -66,20 +58,20 @@ abstract class AbstractAdminControllerTest extends WebTestCase
//Test read access
$client = static::createClient([], [
'PHP_AUTH_USER' => $user,
'PHP_AUTH_PW' => 'test',
'PHP_AUTH_PW' => 'test',
]);
if ($read == false) {
if (false == $read) {
$this->expectException(AccessDeniedException::class);
}
$client->catchExceptions(false);
//Test read/list access by access /new overview page
$crawler = $client->request('GET', static::$base_path . '/new');
$crawler = $client->request('GET', static::$base_path.'/new');
$this->assertFalse($client->getResponse()->isRedirect());
$this->assertEquals($read, $client->getResponse()->isSuccessful(), "Controller was not successful!");
$this->assertEquals($read, !$client->getResponse()->isForbidden(), "Permission Checking not working!");
$this->assertEquals($read, $client->getResponse()->isSuccessful(), 'Controller was not successful!');
$this->assertEquals($read, !$client->getResponse()->isForbidden(), 'Permission Checking not working!');
}
/**
@ -92,19 +84,19 @@ abstract class AbstractAdminControllerTest extends WebTestCase
//Test read access
$client = static::createClient([], [
'PHP_AUTH_USER' => $user,
'PHP_AUTH_PW' => 'test',
'PHP_AUTH_PW' => 'test',
]);
$client->catchExceptions(false);
if ($read == false) {
if (false == $read) {
$this->expectException(AccessDeniedException::class);
}
//Test read/list access by access /new overview page
$crawler = $client->request('GET', static::$base_path . '/1');
$crawler = $client->request('GET', static::$base_path.'/1');
$this->assertFalse($client->getResponse()->isRedirect());
$this->assertEquals($read, $client->getResponse()->isSuccessful(), "Controller was not successful!");
$this->assertEquals($read, !$client->getResponse()->isForbidden(), "Permission Checking not working!");
$this->assertEquals($read, $client->getResponse()->isSuccessful(), 'Controller was not successful!');
$this->assertEquals($read, !$client->getResponse()->isForbidden(), 'Permission Checking not working!');
}
public function deleteDataProvider()
@ -113,12 +105,13 @@ abstract class AbstractAdminControllerTest extends WebTestCase
['noread', false],
['anonymous', false],
['user', true],
['admin', true]
['admin', true],
];
}
/**
* Tests if deleting an entity is working.
*
* @group slow
* @dataProvider deleteDataProvider
*/
@ -127,20 +120,19 @@ abstract class AbstractAdminControllerTest extends WebTestCase
//Test read access
$client = static::createClient([], [
'PHP_AUTH_USER' => $user,
'PHP_AUTH_PW' => 'test',
'PHP_AUTH_PW' => 'test',
]);
$client->catchExceptions(false);
if ($delete == false) {
$this->expectException(AccessDeniedException::class);
if (false == $delete) {
$this->expectException(AccessDeniedException::class);
}
//Test read/list access by access /new overview page
$crawler = $client->request('DELETE', static::$base_path . '/7');
$crawler = $client->request('DELETE', static::$base_path.'/7');
//Page is redirected to '/new', when delete was successful
$this->assertEquals($delete, $client->getResponse()->isRedirect(static::$base_path . '/new'));
$this->assertEquals($delete, !$client->getResponse()->isForbidden(), "Permission Checking not working!");
$this->assertEquals($delete, $client->getResponse()->isRedirect(static::$base_path.'/new'));
$this->assertEquals($delete, !$client->getResponse()->isForbidden(), 'Permission Checking not working!');
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,20 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class AttachmentTypeControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/attachment_type';
protected static $base_path = '/en'.'/attachment_type';
protected static $entity_class = AttachmentType::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
@ -26,10 +25,9 @@ use App\Entity\Parts\Category;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class CategoryControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/category';
protected static $base_path = '/en'.'/category';
protected static $entity_class = Category::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,21 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Devices\Device;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class DeviceControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/device';
protected static $base_path = '/en'.'/device';
protected static $entity_class = Device::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,21 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\Footprint;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class FootprintControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/footprint';
protected static $base_path = '/en'.'/footprint';
protected static $entity_class = Footprint::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,22 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class ManufacturerControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/manufacturer';
protected static $base_path = '/en'.'/manufacturer';
protected static $entity_class = Manufacturer::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,23 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class MeasurementUnitControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/measurement_unit';
protected static $base_path = '/en'.'/measurement_unit';
protected static $entity_class = MeasurementUnit::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Storelocation;
use Symfony\Component\HttpKernel\HttpCache\Store;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class StorelocationControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/store_location';
protected static $base_path = '/en'.'/store_location';
protected static $entity_class = Storelocation::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,23 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Supplier;
/**
* @group slow
* @package App\Tests\Controller\AdminPages
*/
class SupplierControllerTest extends AbstractAdminControllerTest
{
protected static $base_path = '/en' . '/supplier';
protected static $base_path = '/en'.'/supplier';
protected static $entity_class = Supplier::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Proxies\__CG__\App\Entity\UserSystem\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @group slow
* @package App\Tests\Controller
*/
class RedirectControllerTest extends WebTestCase
{
@ -59,6 +56,7 @@ class RedirectControllerTest extends WebTestCase
/**
* Test if a certain request to an url will be redirected.
*
* @dataProvider urlMatchDataProvider
* @group slow
*/
@ -67,7 +65,7 @@ class RedirectControllerTest extends WebTestCase
$client = static::createClient();
$client->request('GET', $url);
$response = $client->getResponse();
if($expect_redirect) {
if ($expect_redirect) {
$this->assertEquals(302, $response->getStatusCode());
}
$this->assertEquals($expect_redirect, $response->isRedirect());
@ -90,9 +88,11 @@ class RedirectControllerTest extends WebTestCase
/**
* Test if the user is redirected to the localized version of a page, based on his settings.
*
* @dataProvider urlAddLocaleDataProvider
* @group slow
* @depends testUrlMatch
*
* @param $user_locale
* @param $input_path
* @param $redirect_path
@ -100,7 +100,7 @@ class RedirectControllerTest extends WebTestCase
public function testAddLocale($user_locale, $input_path, $redirect_path)
{
//Redirect path is absolute
$redirect_path = 'http://localhost' . $redirect_path;
$redirect_path = 'http://localhost'.$redirect_path;
/** @var User $user */
$user = $this->userRepo->findOneBy(['name' => 'user']);
@ -110,7 +110,7 @@ class RedirectControllerTest extends WebTestCase
$client = static::createClient([], [
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'test',
'PHP_AUTH_PW' => 'test',
]);
$client->followRedirects(false);
@ -119,7 +119,8 @@ class RedirectControllerTest extends WebTestCase
}
/**
* Test if the user is redirected to password change page if he should do that
* Test if the user is redirected to password change page if he should do that.
*
* @depends testAddLocale
* @group slow
* @testWith ["de"]
@ -137,13 +138,11 @@ class RedirectControllerTest extends WebTestCase
$client = static::createClient([], [
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'test',
'PHP_AUTH_PW' => 'test',
]);
$client->followRedirects(false);
$client->request('GET', '/part/3');
$this->assertEquals("/$locale/user/settings", $client->getResponse()->headers->get('Location'));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\Attachments;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
@ -50,11 +48,10 @@ use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Component\HttpKernel\HttpCache\Store;
class AttachmentTest extends TestCase
{
public function testEmptyState() : void
public function testEmptyState(): void
{
$attachment = new PartAttachment();
@ -73,7 +70,7 @@ class AttachmentTest extends TestCase
$this->assertEmpty($attachment->getFilename());
}
public function subClassesDataProvider() : array
public function subClassesDataProvider(): array
{
return [
[AttachmentTypeAttachment::class, AttachmentType::class],
@ -87,16 +84,14 @@ class AttachmentTest extends TestCase
[PartAttachment::class, Part::class],
[StorelocationAttachment::class, Storelocation::class],
[SupplierAttachment::class, Supplier::class],
[UserAttachment::class, User::class]
[UserAttachment::class, User::class],
];
}
/**
* @dataProvider subClassesDataProvider
* @param string $attachment_class
* @param string $allowed_class
*/
public function testSetElement(string $attachment_class, string $allowed_class) : void
public function testSetElement(string $attachment_class, string $allowed_class): void
{
/** @var Attachment $attachment */
$attachment = new $attachment_class();
@ -110,16 +105,17 @@ class AttachmentTest extends TestCase
/**
* Test that all attachment subclasses like PartAttachment or similar returns an exception, when an not allowed
* element is passed.
*
* @dataProvider subClassesDataProvider
* @depends testSetElement
*/
public function testSetElementExceptionOnSubClasses(string $attachment_class, string $allowed_class) : void
public function testSetElementExceptionOnSubClasses(string $attachment_class, string $allowed_class): void
{
$this->expectException(\InvalidArgumentException::class);
/** @var Attachment $attachment */
$attachment = new $attachment_class();
if ($allowed_class !== Device::class) {
if (Device::class !== $allowed_class) {
$element = new Device();
} else {
$element = new Category();
@ -138,7 +134,7 @@ class AttachmentTest extends TestCase
['%SECURE%/test.txt', false],
['%test%/foo/bar.ghp', true],
['foo%MEDIA%/foo.jpg', true],
['foo%MEDIA%/%BASE%foo.jpg', true]
['foo%MEDIA%/%BASE%foo.jpg', true],
];
}
@ -211,7 +207,7 @@ class AttachmentTest extends TestCase
['%BASE%/foo/bar.txt', false],
['/', false],
['https://google.de', false],
['%FOOTPRINTS%/foo/bar.txt', true]
['%FOOTPRINTS%/foo/bar.txt', true],
];
}
@ -249,7 +245,7 @@ class AttachmentTest extends TestCase
return [
['%MEDIA%/foo/bar.txt', null, 'bar.txt'],
['%MEDIA%/foo/bar.JPeg', 'test.txt', 'test.txt'],
['https://www.google.de/test.txt', null, null]
['https://www.google.de/test.txt', null, null],
];
}
@ -278,11 +274,11 @@ class AttachmentTest extends TestCase
}
/**
* Sets a protected property on a given object via reflection
* Sets a protected property on a given object via reflection.
*
* @param object $object - instance in which protected value is being modified
* @param object $object - instance in which protected value is being modified
* @param string $property - property on instance being modified
* @param mixed $value - new value of the property being modified
* @param mixed $value - new value of the property being modified
*
* @return void
*/
@ -293,5 +289,4 @@ class AttachmentTest extends TestCase
$reflection_property->setAccessible(true);
$reflection_property->setValue($object, $value);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\Attachments;
use App\Entity\Attachments\AttachmentType;
use Doctrine\Common\Collections\Collection;
use PHPUnit\Framework\TestCase;
@ -35,4 +33,4 @@ class AttachmentTypeTest extends TestCase
$this->assertInstanceOf(Collection::class, $attachment_type->getAttachmentsForType());
$this->assertEmpty($attachment_type->getFiletypeFilter());
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\Parts;
use App\Entity\Parts\PartLot;
use PHPUnit\Framework\TestCase;
@ -41,4 +39,4 @@ class PartLotTest extends TestCase
$lot->setExpirationDate($datetime->setTimestamp(strtotime('now -1 hour')));
$this->assertTrue($lot->isExpired(), 'Lot with expiration date in the past must be expired!');
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\Parts;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
@ -109,4 +107,4 @@ class PartTest extends TestCase
$measurement_unit->setIsInteger(true);
$this->assertEquals(1000000013, $part->getAmountSum());
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\PriceSystem;
use App\Entity\PriceInformations\Currency;
use PHPUnit\Framework\TestCase;
@ -38,7 +36,7 @@ class CurrencyTest extends TestCase
$currency->setExchangeRate('0');
$this->assertNull($currency->getInverseExchangeRate());
$currency->setExchangeRate("1.45643");
$this->assertEquals("0.68661", $currency->getInverseExchangeRate());
$currency->setExchangeRate('1.45643');
$this->assertEquals('0.68661', $currency->getInverseExchangeRate());
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\PriceSystem;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use Doctrine\Common\Collections\Collection;
@ -62,4 +60,4 @@ class OrderdetailTest extends TestCase
$this->assertEquals($price5, $orderdetail->findPriceForQty(5.3));
$this->assertEquals($price5, $orderdetail->findPriceForQty(10000));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,13 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\PriceSystem;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
@ -42,7 +39,6 @@ class PricedetailTest extends TestCase
$this->assertEquals('43.58000', $pricedetail->getPricePerUnit());
$this->assertEquals('139.45600', $pricedetail->getPricePerUnit('3.2'));
$pricedetail->setPrice('10000000.2345'); //Ten million
$pricedetail->setPriceRelatedQuantity(1.234e9); //100 billion
$this->assertEquals('0.00810', $pricedetail->getPricePerUnit());
@ -61,7 +57,6 @@ class PricedetailTest extends TestCase
$orderdetail2 = $this->createMock(Orderdetail::class);
$orderdetail2->method('getPart')->willReturn($part2);
//By default a price detail returns 1
$this->assertEquals(1, $pricedetail->getPriceRelatedQuantity());
@ -90,7 +85,6 @@ class PricedetailTest extends TestCase
$orderdetail2 = $this->createMock(Orderdetail::class);
$orderdetail2->method('getPart')->willReturn($part2);
//By default a price detail returns 1
$this->assertEquals(1, $pricedetail->getMinDiscountQuantity());
@ -105,4 +99,4 @@ class PricedetailTest extends TestCase
$pricedetail->setOrderdetail($orderdetail2);
$this->assertEquals(0.23, $pricedetail->getMinDiscountQuantity());
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\Category;
use PHPUnit\Framework\TestCase;
@ -31,7 +29,6 @@ use Symfony\Component\Yaml\Tests\A;
/**
* Test StructuralDBElement entities.
* Note: Because StructuralDBElement is abstract we use AttachmentType here as a placeholder.
* @package App\Tests\Entity
*/
class StructuralDBElementTest extends TestCase
{
@ -92,7 +89,8 @@ class StructuralDBElementTest extends TestCase
public function testChildOfExtendedClass()
{
//Doctrine extends the entities for proxy classes so the isChildOf mus also work for inheritance types
$inheritance = new class extends AttachmentType {};
$inheritance = new class() extends AttachmentType {
};
$inheritance->setParent($this->root);
$this->assertTrue($inheritance->isChildOf($this->root));
$this->assertFalse($this->root->isChildOf($inheritance));
@ -119,5 +117,4 @@ class StructuralDBElementTest extends TestCase
$this->assertEquals([$this->root, $this->child1], $this->child1->getPathArray());
$this->assertEquals([$this->root], $this->root->getPathArray());
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\UserSystem;
@ -25,7 +24,6 @@ namespace App\Tests\Entity\UserSystem;
use App\Entity\UserSystem\PermissionsEmbed;
use Doctrine\ORM\Mapping\Embedded;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Http\RememberMe\PersistentTokenBasedRememberMeServices;
class PermissionsEmbedTest extends TestCase
{
@ -40,29 +38,28 @@ class PermissionsEmbedTest extends TestCase
//For newly created embedded, all things should be set to inherit => null
//Test both normal name and constants
$this->assertNull( $embed->getPermissionValue(PermissionsEmbed::PARTS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::CONFIG, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::ATTACHMENT_TYPES, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::CATEGORIES, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::DATABASE, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::DEVICE_PARTS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::DEVICES, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::FOOTRPINTS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::GROUPS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::DATABASE, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::LABELS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::MANUFACTURERS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_ATTACHMENTS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_COMMENT, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_DESCRIPTION, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_FOOTPRINT, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_MANUFACTURER, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_MINAMOUNT, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_NAME, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_ORDER, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::PARTS_ORDERDETAILS, 0));
$this->assertEquals(null, $embed->getPermissionValue(PermissionsEmbed::USERS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::CONFIG, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::ATTACHMENT_TYPES, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::CATEGORIES, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::DATABASE, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::DEVICE_PARTS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::DEVICES, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::FOOTRPINTS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::GROUPS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::DATABASE, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::LABELS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::MANUFACTURERS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_ATTACHMENTS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_COMMENT, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_DESCRIPTION, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_FOOTPRINT, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_MANUFACTURER, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_MINAMOUNT, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_NAME, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_ORDER, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS_ORDERDETAILS, 0));
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::USERS, 0));
//Set a value for testing to the part property
$reflection = new \ReflectionClass($embed);
@ -77,13 +74,10 @@ class PermissionsEmbedTest extends TestCase
$this->assertTrue($embed->getPermissionValue(PermissionsEmbed::PARTS, 4));
// 11 is reserved, but it should be also treat as INHERIT.
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS, 6));
}
public function testGetBitValue()
{
$embed = new PermissionsEmbed();
//Set a value for testing to the part property
@ -94,11 +88,11 @@ class PermissionsEmbedTest extends TestCase
$property->setValue($embed, 0b11011000); // 11 01 10 00
//Test if function is working correctly
$this->assertEquals(PermissionsEmbed::INHERIT ,$embed->getBitValue(PermissionsEmbed::PARTS, 0));
$this->assertEquals(PermissionsEmbed::DISALLOW ,$embed->getBitValue(PermissionsEmbed::PARTS, 2));
$this->assertEquals(PermissionsEmbed::ALLOW ,$embed->getBitValue(PermissionsEmbed::PARTS, 4));
$this->assertEquals(PermissionsEmbed::INHERIT, $embed->getBitValue(PermissionsEmbed::PARTS, 0));
$this->assertEquals(PermissionsEmbed::DISALLOW, $embed->getBitValue(PermissionsEmbed::PARTS, 2));
$this->assertEquals(PermissionsEmbed::ALLOW, $embed->getBitValue(PermissionsEmbed::PARTS, 4));
// 11 is reserved, but it should be also treat as INHERIT.
$this->assertEquals(0b11 ,$embed->getBitValue(PermissionsEmbed::PARTS, 6));
$this->assertEquals(0b11, $embed->getBitValue(PermissionsEmbed::PARTS, 6));
}
public function testInvalidPermissionName()
@ -139,7 +133,7 @@ class PermissionsEmbedTest extends TestCase
'ALLOW' => [PermissionsEmbed::ALLOW],
'DISALLOW' => [PermissionsEmbed::DISALLOW],
'INHERIT' => [PermissionsEmbed::INHERIT],
'0b11' => [0b11]
'0b11' => [0b11],
];
}
@ -149,7 +143,7 @@ class PermissionsEmbedTest extends TestCase
'ALLOW' => [true],
'DISALLOW' => [false],
'INHERIT' => [null],
'0b11' => [null]
'0b11' => [null],
];
}
@ -188,7 +182,7 @@ class PermissionsEmbedTest extends TestCase
$embed->setRawPermissionValues([
PermissionsEmbed::PARTS => 0,
PermissionsEmbed::USERS => 100,
PermissionsEmbed::CATEGORIES => 1304
PermissionsEmbed::CATEGORIES => 1304,
]);
$this->assertEquals(0, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
@ -204,7 +198,5 @@ class PermissionsEmbedTest extends TestCase
$this->assertEquals(0, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
$this->assertEquals(100, $embed->getRawPermissionValue(PermissionsEmbed::USERS));
$this->assertEquals(1304, $embed->getRawPermissionValue(PermissionsEmbed::CATEGORIES));
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity\UserSystem;
use App\Entity\UserSystem\User;
use PHPUnit\Framework\TestCase;
@ -38,4 +36,4 @@ class UserTest extends TestCase
$this->assertEquals('John Doe', $user->getFullName(false));
$this->assertEquals('John Doe (username)', $user->getFullName(true));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Helpers;
use App\Helpers\BBCodeToMarkdownConverter;
use PHPUnit\Framework\TestCase;
@ -50,6 +48,7 @@ class BBCodeToMarkdownConverterTest extends TestCase
/**
* @dataProvider dataProvider
*
* @param $bbcode
* @param $expected
*/
@ -57,4 +56,4 @@ class BBCodeToMarkdownConverterTest extends TestCase
{
$this->assertEquals($expected, $this->converter->convert($bbcode));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,18 +17,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Helpers;
use App\Helpers\TreeViewNode;
use PHPUnit\Framework\TestCase;
class TreeViewNodeTest extends TestCase
{
/**
* @var TreeViewNode
*/
@ -40,18 +37,17 @@ class TreeViewNodeTest extends TestCase
public function setUp()
{
$sub_nodes = array();
$sub_nodes[] = new TreeViewNode("Subnode 1");
$sub_sub_nodes[] = array();
$sub_nodes = [];
$sub_nodes[] = new TreeViewNode('Subnode 1');
$sub_sub_nodes[] = [];
$sub_sub_nodes[] = new TreeViewNode('Sub Subnode 1');
$sub_sub_nodes[] = new TreeViewNode('Sub Subnode 2');
$sub_nodes[] = new TreeViewNode("Subnode 2");
$sub_nodes[] = new TreeViewNode('Subnode 2');
//Init node1 with default arguments;
$this->node1 = new TreeViewNode('Name');
//Node 2 gets values for all arguments
$this->node2 = new TreeViewNode('Name', 'www.foo.bar', $sub_nodes);
}
public function testConstructor()
@ -62,10 +58,8 @@ class TreeViewNodeTest extends TestCase
$this->assertEquals('Name', $this->node1->getText());
//The second node must have the given things as properties.
$this->assertEquals('Name',$this->node2->getText());
$this->assertEquals('Name', $this->node2->getText());
$this->assertEquals('www.foo.bar', $this->node2->getHref());
$this->assertNotEmpty($this->node2->getNodes());
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,16 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services;
use App\Entity\Parts\MeasurementUnit;
use App\Services\AmountFormatter;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Intl\Locale\Locale;
class AmountFormatterTest extends WebTestCase
{
@ -46,23 +43,23 @@ class AmountFormatterTest extends WebTestCase
public function testFormatWithoutUnit()
{
$this->assertEquals("2", $this->service->format(2.321));
$this->assertEquals("1002", $this->service->format(1002.356));
$this->assertEquals("1000454", $this->service->format(1000454.0));
$this->assertEquals("0", $this->service->format(0.01));
$this->assertEquals("0", $this->service->format(0));
$this->assertEquals('2', $this->service->format(2.321));
$this->assertEquals('1002', $this->service->format(1002.356));
$this->assertEquals('1000454', $this->service->format(1000454.0));
$this->assertEquals('0', $this->service->format(0.01));
$this->assertEquals('0', $this->service->format(0));
}
public function testInvalidInput()
{
$this->expectException(\InvalidArgumentException::class);
$this->service->format("test");
$this->service->format('test');
}
public function testFormatUnitWithoutSI()
{
$meters = new MeasurementUnit();
$meters->setIsInteger(false)->setUseSIPrefix(false)->setUnit("m");
$meters->setIsInteger(false)->setUseSIPrefix(false)->setUnit('m');
$this->assertEquals('0.32 m', $this->service->format(0.3245, $meters));
$this->assertEquals('10003.56 m', $this->service->format(10003.556, $meters));
@ -96,4 +93,4 @@ class AmountFormatterTest extends WebTestCase
$this->assertEquals('12002.32 m', $this->service->format(12002.32, $meters, ['show_prefix' => false]));
$this->assertEquals('123 m', $this->service->format(123.234, $meters, ['is_integer' => true]));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,15 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
use App\Services\AmountFormatter;
use App\Services\Attachments\AttachmentPathResolver;
use ReflectionClass;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AttachmentPathResolverTest extends WebTestCase
@ -47,8 +44,8 @@ class AttachmentPathResolverTest extends WebTestCase
self::bootKernel();
self::$projectDir_orig = realpath(self::$kernel->getProjectDir());
self::$projectDir = str_replace('\\', '/', self::$projectDir_orig);
self::$media_path = self::$projectDir . '/public/media';
self::$footprint_path = self::$projectDir . '/public/img/footprints';
self::$media_path = self::$projectDir.'/public/media';
self::$footprint_path = self::$projectDir.'/public/img/footprints';
}
public static function setUpBeforeClass()
@ -69,8 +66,8 @@ class AttachmentPathResolverTest extends WebTestCase
$this->assertEquals(self::$projectDir_orig, self::$service->parameterToAbsolutePath(self::$projectDir));
//Relative pathes should be resolved
$this->assertEquals(self::$projectDir_orig . DIRECTORY_SEPARATOR . 'src', self::$service->parameterToAbsolutePath('src'));
$this->assertEquals(self::$projectDir_orig . DIRECTORY_SEPARATOR . 'src', self::$service->parameterToAbsolutePath('./src'));
$this->assertEquals(self::$projectDir_orig.\DIRECTORY_SEPARATOR.'src', self::$service->parameterToAbsolutePath('src'));
$this->assertEquals(self::$projectDir_orig.\DIRECTORY_SEPARATOR.'src', self::$service->parameterToAbsolutePath('./src'));
//Invalid pathes should return null
$this->assertNull(self::$service->parameterToAbsolutePath('/this/path/does/not/exist'));
@ -80,9 +77,9 @@ class AttachmentPathResolverTest extends WebTestCase
public function placeholderDataProvider()
{
return [
['%FOOTPRINTS%/test/test.jpg', self::$footprint_path . '/test/test.jpg'],
['%FOOTPRINTS%/test/', self::$footprint_path . '/test/'],
['%MEDIA%/test', self::$media_path . '/test'],
['%FOOTPRINTS%/test/test.jpg', self::$footprint_path.'/test/test.jpg'],
['%FOOTPRINTS%/test/', self::$footprint_path.'/test/'],
['%MEDIA%/test', self::$media_path.'/test'],
['%MEDIA%', self::$media_path],
['%FOOTPRINTS%', self::$footprint_path],
//Footprints 3D are disabled
@ -95,24 +92,24 @@ class AttachmentPathResolverTest extends WebTestCase
['%FOOTPRINTS%/%MEDIA%', null], //No more than one placholder
['%FOOTPRINTS%/%FOOTPRINTS%', null],
['%FOOTPRINTS%/../../etc/passwd', null],
['%FOOTPRINTS%/0\..\test', null]
['%FOOTPRINTS%/0\..\test', null],
];
}
public function realPathDataProvider()
{
return [
[self::$media_path . '/test/img.jpg', '%MEDIA%/test/img.jpg'],
[self::$media_path . '/test/img.jpg', '%BASE%/data/media/test/img.jpg', true],
[self::$footprint_path . '/foo.jpg', '%FOOTPRINTS%/foo.jpg'],
[self::$footprint_path . '/foo.jpg', '%FOOTPRINTS%/foo.jpg', true],
[self::$media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'],
[self::$media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true],
[self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'],
[self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true],
//Every kind of absolute path, that is not based with our placeholder dirs must be invald
['/etc/passwd', null],
['C:\\not\\existing.txt', null],
//More then one placeholder is not allowed
[self::$footprint_path . '/test/' . self::$footprint_path, null],
[self::$footprint_path.'/test/'.self::$footprint_path, null],
//Path must begin with path
['/not/root' . self::$footprint_path, null]
['/not/root'.self::$footprint_path, null],
];
}
@ -131,4 +128,4 @@ class AttachmentPathResolverTest extends WebTestCase
{
$this->assertEquals($expected, self::$service->realPathToPlaceholder($param, $old_method));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\Attachments\BuiltinAttachmentsFinder;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AttachmentURLGeneratorTest extends WebTestCase
{
protected const PUBLIC_DIR = "/public";
protected const PUBLIC_DIR = '/public';
protected static $service;
@ -47,12 +44,13 @@ class AttachmentURLGeneratorTest extends WebTestCase
['/public/folder/test.jpg', 'folder/test.jpg'],
['/not/public/test.jpg', null],
['/public/', ''],
['not/absolute/test.jpg', null]
['not/absolute/test.jpg', null],
];
}
/**
* @dataProvider dataProvider
*
* @param $input
* @param $expected
*/
@ -60,4 +58,4 @@ class AttachmentURLGeneratorTest extends WebTestCase
{
$this->assertEquals($expected, static::$service->absolutePathToAssetPath($input, static::PUBLIC_DIR));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
@ -32,7 +31,7 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
protected static $mock_list = [
'%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS%/123.jpg', '%FOOTPRINTS%/123.jpeg',
'%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt'
'%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt',
];
public static function setUpBeforeClass()
@ -51,11 +50,10 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
//Basic search for keyword
['test', [], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS_3D%/test.jpg']],
['%FOOTPRINTS_3D%', [], ['%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt']],
['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt'] ],
['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt']],
//Filter extensions
//['test', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/123.jpeg', '%FOOTPRINTS_3D%/test.jpg']],
//['test.jpg', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS_3D%/test.jpg']]
];
}
@ -69,4 +67,4 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
$this->assertEquals([], array_diff($value, $expected), 'Additional');
$this->assertEquals([], array_diff($expected, $value), 'Missing:');
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
@ -35,7 +34,7 @@ class FileTypeFilterToolsTest extends WebTestCase
self::$service = self::$container->get(FileTypeFilterTools::class);
}
public function validateDataProvider() : array
public function validateDataProvider(): array
{
return [
['', true], //Empty string is valid
@ -47,11 +46,11 @@ class FileTypeFilterToolsTest extends WebTestCase
['test.png', false], //No full filename
['application/*', false], //Only certain placeholders are allowed
['.png;.png,.jpg', false], //Wrong separator
['.png .jpg .gif', false]
['.png .jpg .gif', false],
];
}
public function normalizeDataProvider() : array
public function normalizeDataProvider(): array
{
return [
['', ''],
@ -67,7 +66,7 @@ class FileTypeFilterToolsTest extends WebTestCase
];
}
public function extensionAllowedDataProvider() : array
public function extensionAllowedDataProvider(): array
{
return [
['', 'txt', true],
@ -88,10 +87,9 @@ class FileTypeFilterToolsTest extends WebTestCase
}
/**
* Test the validateFilterString method
* Test the validateFilterString method.
*
* @dataProvider validateDataProvider
* @param string $filter
* @param bool $expected
*/
public function testValidateFilterString(string $filter, bool $expected)
{
@ -100,8 +98,6 @@ class FileTypeFilterToolsTest extends WebTestCase
/**
* @dataProvider normalizeDataProvider
* @param string $filter
* @param string $expected
*/
public function testNormalizeFilterString(string $filter, string $expected)
{
@ -115,4 +111,4 @@ class FileTypeFilterToolsTest extends WebTestCase
{
$this->assertEquals($expected, self::$service->isExtensionAllowed($filter, $extension), $expected);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,16 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\PermissionsEmbed;
use App\Entity\UserSystem\User;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\Services\PermissionResolver;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -90,7 +87,6 @@ class PermissionResolverTest extends WebTestCase
$this->group->method('getParent')->willReturn($parent_group);
}
public function getPermissionNames()
{
//List all possible operation names.
@ -116,7 +112,7 @@ class PermissionResolverTest extends WebTestCase
[PermissionsEmbed::CATEGORIES],
[PermissionsEmbed::PARTS_PRICES],
[PermissionsEmbed::ATTACHMENT_TYPES],
[PermissionsEmbed::CONFIG]
[PermissionsEmbed::CONFIG],
];
}
@ -196,5 +192,4 @@ class PermissionResolverTest extends WebTestCase
$this->assertNull($this->service->inherit($this->user_withoutGroup, 'parts', 'show_history'));
$this->assertNull($this->service->inherit($this->user_withoutGroup, 'parts', 'delete'));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
@ -90,4 +88,4 @@ class PricedetailHelperTest extends WebTestCase
{
$this->assertEquals($expected_result, $this->service->getMaxDiscountAmount($part), $message);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services;
@ -50,7 +49,6 @@ class SIFormatterTest extends WebTestCase
$this->assertSame(0, $this->service->getMagnitude(-1.0));
$this->assertSame(0, $this->service->getMagnitude(-9.9));
$this->assertSame(3, $this->service->getMagnitude(9999.99));
$this->assertSame(3, $this->service->getMagnitude(1000.0));
$this->assertSame(3, $this->service->getMagnitude(-9999.99));
@ -59,7 +57,7 @@ class SIFormatterTest extends WebTestCase
$this->assertSame(-1, $this->service->getMagnitude(0.1));
$this->assertSame(-1, $this->service->getMagnitude(-0.9999));
$this->assertSame(-25, $this->service->getMagnitude(- 1.246e-25));
$this->assertSame(-25, $this->service->getMagnitude(-1.246e-25));
$this->assertSame(12, $this->service->getMagnitude(9.99e12));
}
@ -78,9 +76,9 @@ class SIFormatterTest extends WebTestCase
public function testFormat()
{
$this->assertSame("2.32 km", $this->service->format(2321, 'm'));
$this->assertEquals("230.45 km", $this->service->format(230450.3, 'm'));
$this->assertSame("-98.20 mg", $this->service->format(-0.0982, 'g'));
$this->assertSame('2.32 km', $this->service->format(2321, 'm'));
$this->assertEquals('230.45 km', $this->service->format(230450.3, 'm'));
$this->assertSame('-98.20 mg', $this->service->format(-0.0982, 'g'));
$this->assertSame('-0.23 g', $this->service->format(-0.23, 'g'));
}
}
}