1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-18 13:10:08 -07:00

Add ZipService tests, Add ApplicationAvailabilityTest

This commit is contained in:
Unknown 2017-06-08 22:48:48 +02:00
parent 31889a95da
commit 6685658a89
60 changed files with 270 additions and 94 deletions

View File

@ -33,7 +33,9 @@
<span class="truncate-multiline"><small>{{ model.name }}</small></span>
</div>
<div class="description">
{% if model.category is not null %}
<span><small>{{ model.category.name }}</small></span>
{% endif %}
{% if quantity %}<span class="right floated">{{ quantity }}x</span>{% endif %}
</div>
</div>
@ -71,7 +73,9 @@
<div class="meta">
<span class="left floated">{{ set.id }}</span>
<br>
{% if set.theme is not null %}
<span title="{{ set.theme.fullName }}" class="left floated truncate"><small>{{ set.theme.fullName }}</small></span>
{% endif %}
</div>
<div class="description">
<small>

View File

@ -39,7 +39,11 @@
</tr>
<tr>
<td>{{ 'set.theme' | trans }}</td>
<td><a href="{{ path('set_index',{'theme' : set.theme.id }) }}">{{ set.theme ? set.theme.fullName }}</a></td>
<td>
{% if set.theme is not null %}
<a href="{{ path('set_index',{'theme' : set.theme.id }) }}">{{ set.theme ? set.theme.fullName }}</a>
{% endif %}
</td>
</tr>
<tr>
<td>{{ 'set.parts' | trans }}</td><td>

View File

@ -3,6 +3,7 @@ fos_elastica:
default: { host: '%elastica_host%', port: '%elastica_port%', logger: true }
indexes:
app:
index_name: app_%kernel.environment%
settings:
index:
analysis:

View File

@ -48,6 +48,14 @@ class Inventory_Part
*/
protected $inventory;
/**
* @param int $quantity
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
}
/**
* Get count.
*

View File

@ -35,6 +35,18 @@ class SetService
$this->inventorySetRepository = $em->getRepository(Inventory_Set::class);
}
/**
* Find set by id
*
* @param $id
*
* @return Set
*/
public function findSet($id)
{
return $this->setRepository->find($id);
}
/**
* Get all sets in the set inventory.
*

View File

@ -117,7 +117,7 @@ class ZipService
* @param Set $set
* @param bool $spare If true - add only spare parts, false - add only regular parts, null - add all parts
*/
public function addSetGroupedByColor(Set $set, $spare = null)
private function addSetGroupedByColor(Set $set, $spare = null)
{
$colors = $this->setService->getModelsGroupedByColor($set, $spare);
@ -141,7 +141,7 @@ class ZipService
* @param Set $set
* @param bool $spare If true - add only spare parts, false - add only regular parts, null - add all parts
*/
public function addSet(Set $set, $spare = null)
private function addSet(Set $set, $spare = null)
{
$models = $this->setService->getModels($set, $spare);

View File

@ -1,39 +0,0 @@
<?php
namespace Tests\AppBundle;
use Tests\AppBundle\Fixtures\LoadBaseData;
class ApplicationAvailabilityTest extends BaseTest
{
protected function setUp()
{
$this->setUpDb();
$this->loadFixtures([
LoadBaseData::class
]);
parent::setUp();
}
/**
* @dataProvider urlProvider
*/
public function testPageIsSuccessful($url)
{
$client = $this->makeClient();
$client->request('GET', $url);
$this->assertTrue( $client->getResponse()->isSuccessful());
}
public function urlProvider()
{
return array(
array('/'),
array('/models')
);
}
}

View File

@ -13,27 +13,22 @@ use Symfony\Component\HttpKernel\KernelInterface;
abstract class BaseTest extends WebTestCase
{
protected $_container;
/* @var FilesystemInterface $filesystem */
protected $filesystem;
/** @var EntityManagerInterface */
protected $em;
public function __construct()
public function setUp()
{
self::bootKernel();
$this->_container = self::$kernel->getContainer();
$this->filesystem = $this->get('oneup_flysystem.media_filesystem');
$this->em = $this->get('doctrine.orm.entity_manager');
parent::__construct();
}
public function setUpDb()
{
// Make sure we are in the test environment
if ('test' !== self::$kernel->getEnvironment()) {
if ('test' !== $this->get('kernel')->getEnvironment()) {
throw new \LogicException('setUpDb must be executed in the test environment');
}
@ -45,11 +40,11 @@ abstract class BaseTest extends WebTestCase
protected function get($service)
{
return $this->_container->get($service);
return $this->getContainer()->get($service);
}
protected function getParameter($parameter)
{
return $this->_container->getParameter($parameter);
return $this->getContainer()->getParameter($parameter);
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace Tests\AppBundle;
use Tests\AppBundle\Controller\BaseControllerTest;
class ApplicationAvailabilityTest extends BaseControllerTest
{
/**
* @dataProvider urlProvider
*/
public function testPageIsSuccessful($url) {
$client = static::createClient();
$client->request('GET', $url);
$this->assertTrue( $client->getResponse()->isSuccessful());
}
public function urlProvider()
{
return array(
array('/'),
array('/colors/'),
array('/bricks/'),
array('/bricks/1'),
array('/bricks/1/sets'),
array('/sets/'),
array('/sets/8049-1'),
array('/sets/8049-1/inventory'),
array('/sets/8049-1/models'),
array('/sets/8049-1/colors'),
array('/parts/1')
);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Tests\AppBundle\Controller;
use Liip\FunctionalTestBundle\Test\WebTestCase;
use Tests\AppBundle\Fixtures\LoadBaseData;
abstract class BaseControllerTest extends WebTestCase
{
public function setUp()
{
// If you are using the Doctrine Fixtures Bundle you could load these here
$this->loadFixtures([
LoadBaseData::class
]);
$this->runCommand('fos:elastica:populate');
}
}

View File

@ -1,15 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: hubnedav
* Date: 8.6.17
* Time: 16:05
*/
namespace Tests\AppBundle\Controller;
class DefaultControllerTest
{
}

View File

@ -6,6 +6,10 @@ namespace Tests\AppBundle\Fixtures;
use AppBundle\Entity\Color;
use AppBundle\Entity\LDraw\Author;
use AppBundle\Entity\LDraw\Model;
use AppBundle\Entity\Rebrickable\Inventory;
use AppBundle\Entity\Rebrickable\Inventory_Part;
use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
@ -25,17 +29,54 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface
public function load(ObjectManager $manager)
{
// Add sample author
$author = new Author();
$author->setName('Author');
$manager->persist($author);
// Add sample model
$model = new Model();
$model->setId(1);
$model->setAuthor($author);
$model->setModified(new \DateTime());
$model->setName('Name');
$model->setPath('models/1.stl');
$manager->persist($model);
// Add sample part
$part = new Part();
$part->setId(1);
$part->setName('Name');
$part->setModel($model);
$manager->persist($part);
$set = new Set();
$set->setName('Set');
$set->setId('8049-1');
$set->setPartCount(1);
$set->setYear(2011);
$manager->persist($set);
$color = new Color();
$color->setId(1);
$color->setName('Black');
$color->setRgb('000000');
$color->setTransparent(false);
$manager->persist($color);
$inventory = new Inventory();
$inventory->setSet($set);
$inventory->setVersion(1);
$manager->persist($inventory);
$inventoryPart = new Inventory_Part();
$inventoryPart->setColor($color);
$inventoryPart->setQuantity(5);
$inventoryPart->setPart($part);
$inventoryPart->setInventory($inventory);
$inventoryPart->setSpare(false);
$manager->persist($inventoryPart);
$manager->flush();
}
}

Binary file not shown.

View File

@ -29,8 +29,10 @@ class ModelLoaderTest extends BaseTest
/** @var AliasRepository */
private $aliasRepository;
protected function setUp()
public function setUp()
{
parent::setUp();
$this->modelRepository = $this->em->getRepository(Model::class);
$this->aliasRepository = $this->em->getRepository(Alias::class);

View File

@ -16,6 +16,8 @@ class StlConverterTest extends BaseTest
public function setUp()
{
parent::setUp();
$ldview = $this->getParameter('ldview_bin');
$stlFixer = $this->createMock(StlFixerService::class);

View File

@ -21,6 +21,8 @@ class StlFixer extends BaseTest
public function setUp()
{
parent::setUp();
$this->stlFixer = new StlFixerService($this->getParameter('admesh_bin'));
$this->input = __DIR__ . '/fixtures/ascii.stl';
}

View File

@ -20,7 +20,9 @@ class StlRendererTest extends BaseTest
public function setUp()
{
$layout = $this->get('kernel')->getRootDir().'/Resources/povray_layout/layout.tmpl';
parent::setUp();
$layout = __DIR__ . '/fixtures/layout.tmpl';
$povray = $this->getParameter('povray_bin');
$stl2pov = $this->getParameter('stl2pov_bin');

View File

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -0,0 +1,52 @@
#declare main_mesh = m_MYSOLID;
#include "math.inc"
#include "finish.inc"
#include "transforms.inc"
#include "colors.inc"
background {color rgb 1}
light_source { <-10,-15,15> color White }
light_source { <-11,-4,10> color White }
light_source { <-10,14,20> color White }
global_settings {
assumed_gamma 2.1
}
#declare Min = min_extent( main_mesh );
#declare Max = max_extent( main_mesh );
#declare MaxLength = max(
Max.x-Min.x,
Max.y-Min.y,
Max.z-Min.z
);
// Calculate camera distace factor - if object is large on Y axis and Z axis move the camera further
#declare cameraDistance = (((Max.y-Min.y)*(1/MaxLength) > 0.3) & ((Max.z-Min.z)*(1/MaxLength) > 0.95) ? 1: 0.9);
camera
{
location <-1.5*cameraDistance, -1*cameraDistance, 1.1*cameraDistance>
angle 45
sky z
look_at 0
translate <0,0.05,-0.15>
right -1*x
}
object
{
main_mesh
Center_Trans(main_mesh, x+y+z)
texture
{
pigment{ color rgb<0, 0.34, 0.6> }
finish { phong .51}
}
scale (1/MaxLength)
}

View File

@ -0,0 +1,60 @@
<?php
namespace Tests\AppBundle\Service;
use AppBundle\Service\ModelService;
use AppBundle\Service\SetService;
use AppBundle\Service\ZipService;
use Tests\AppBundle\BaseTest;
use Tests\AppBundle\Fixtures\LoadBaseData;
class ZipServiceTest extends BaseTest
{
/** @var ZipService */
private $zipService;
/** @var ModelService */
private $modelService;
/** @var SetService */
private $setService;
public function setUp()
{
parent::setUp();
$this->loadFixtures([
LoadBaseData::class
]);
$this->modelService = $this->get(ModelService::class);
$this->setService = $this->get(SetService::class);
$this->filesystem->write('models/1.stl',file_get_contents(__DIR__.'/../Fixtures/models/1.stl'));
$this->zipService = new ZipService($this->filesystem,$this->modelService,$this->setService);
}
public function tearDown()
{
$this->filesystem->delete('models/1.stl');
}
public function testModelZip()
{
$model = $this->modelService->findModel(1);
$path = $this->zipService->createFromModel($model, 'modelzip');
$this->assertFileExists($path);
}
public function testSetZip()
{
$set = $this->setService->findSet('8049-1');
$path = $this->zipService->createFromSet($set, 'setzip');
$this->assertFileExists($path);
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace Tests\AppBundle\Service;
use Tests\AppBundle\BaseTest;
class ZipServiceTest extends BaseTest
{
}