Skip to content

Commit

Permalink
Fix doctype export tests
Browse files Browse the repository at this point in the history
Everything is green :)
  • Loading branch information
Stoakes committed Feb 18, 2018
1 parent b77c119 commit cff1c23
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ script:
- docker-compose run --rm web php bin/console doctrine:schema:validate --ansi
# Run tests on test env
- sleep 10 && docker-compose run --rm web php bin/console cache:clear -e=test --no-warmup
- docker-compose run --rm web vendor/bin/behat ./features/
- docker-compose exec web php -d memory_limit=1024M vendor/bin/behat ./features/
- docker-compose stop


1 change: 1 addition & 0 deletions docker/apache/start_safe_perms
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ main() {
chown -R "$owner:$group" /var/{lock,log,run}/apache*
chown -R "$owner:$group" var
chown -R "$owner:$group" web/tmp
rm web/tmp/*--* # clean web/tmp folder from exported file
exec /usr/sbin/apache2ctl "$@"
}

Expand Down
6 changes: 3 additions & 3 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(ManagerRegistry $doctrine, KernelInterface $kernel)
}

/**
* @BeforeScenario @createSchema
* @createSchema
*/
public function createDatabase()
{
Expand All @@ -94,7 +94,7 @@ public function createDatabase()
}

/**
* @AfterScenario @dropSchema
* @dropSchema
* Beware : the annotation in cucumber should also match the case (dropschema is invalid)
*/
public function dropDatabase()
Expand All @@ -109,7 +109,7 @@ public function afterStep(AfterStepScope $event)
echo $this->getSession()->getCurrentUrl() . "\n\n-------";
echo substr($this->getSession()->getPage()->getContent(), 100, 200); // the title of the page
echo "\n\n------";
echo substr($this->getSession()->getPage()->getContent(), 11000, 2000);
echo substr($this->getSession()->getPage()->getContent(), 13500, 2000);
}
}

Expand Down
19 changes: 19 additions & 0 deletions features/doctypes/default-doctypes.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Default Doctypes
The provided doctypes can be published out of the box.

# the "@createSchema" annotation provided by Behat creates a temporary SQLite database for testing the API
@createSchema
Scenario: I can export the default AP
Given I am logged in as "admin"
Given I am on "/Documents/Publiposter/AP/etude/2"
Then the response status code should not be 500
Then the response status code should be 200


# The "@dropSchema" annotation must be added on the last scenario of the feature file to drop the temporary SQLite database
@dropSchema
Scenario: I can export the default CC
Given I am logged in as "admin"
Given I am on "/Documents/Publiposter/CC/etude/2"
Then the response status code should not be 500
Then the response status code should be 200
4 changes: 3 additions & 1 deletion features/suivi/etude_crud.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ Feature: Etude
# The "@dropSchema" annotation must be added on the last scenario of the feature file to drop the temporary SQLite database
@dropSchema
Scenario: Void
Given I am logged in as "admin"
Given I am logged in as "admin"
When I go to "/suivi/etude/315GLA"
Then the response status code should be 200
11 changes: 5 additions & 6 deletions src/Mgate/PubliBundle/Controller/TraitementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function publiposterAction($templateName, $rootName, $rootObject_id)
{
$this->publipostage($templateName, $rootName, $rootObject_id);

return $this->telechargerAction($templateName);
return $this->telechargerAction();
}

private function publipostage($templateName, $rootName, $rootObject_id, $debug = false)
Expand Down Expand Up @@ -176,7 +176,6 @@ private function publipostage($templateName, $rootName, $rootObject_id, $debug =
$chemin = $this->getDoctypeAbsolutePathFromName($templateName, $debug);

$templatesXMLtraite = $this->traiterTemplates($chemin, $rootName, $rootObject);
$repertoire = 'tmp';

//SI DM on prend la ref de RM et ont remplace RM par DM
if (self::DOCTYPE_DESCRIPTIF_MISSION == $templateName) {
Expand Down Expand Up @@ -206,7 +205,7 @@ private function publipostage($templateName, $rootName, $rootObject_id, $debug =
if (isset($isDM) && $isDM) {
$refDocx = preg_replace('#RM#', 'DM', $refDocx);
}

$repertoire = $this->get('kernel')->getRootDir() . '' .Document::DOCUMENT_TMP_FOLDER ; // tmp folder in web directory
$idDocx = $refDocx . '-' . ((int) strtotime('now') + rand());
copy($chemin, $repertoire . '/' . $idDocx);
$zip = new \ZipArchive();
Expand Down Expand Up @@ -257,14 +256,14 @@ private function publipostage($templateName, $rootName, $rootObject_id, $debug =
/**
* @Security("has_role('ROLE_SUIVEUR')")
*/
public function telechargerAction($templateName)
public function telechargerAction()
{
$this->purge();
if (isset($this->idDocx) && isset($this->refDocx)) {
$idDocx = $this->idDocx;
$refDocx = $this->refDocx;

$templateName = 'tmp/' . $idDocx;
$templateName = $this->get('kernel')->getRootDir() . '' . Document::DOCUMENT_TMP_FOLDER . '/' . $idDocx;

$response = new Response();
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
Expand Down Expand Up @@ -301,7 +300,7 @@ private function getDoctypeAbsolutePathFromName($doc, $debug = false)
if (!$documenttype = $em->getRepository('Mgate\PubliBundle\Entity\Document')->findOneBy(['name' => $doc])) {
throw $this->createNotFoundException('Le doctype ' . $doc . ' n\'existe pas... C\'est bien balo');
} else {
$chemin = $this->get('kernel')->getRootDir() . '' . $documenttype::DOCUMENT_STORAGE_ROOT . '/' . $documenttype->getPath();
$chemin = $this->get('kernel')->getRootDir() . '' . Document::DOCUMENT_STORAGE_ROOT . '/' . $documenttype->getPath();
}

return $chemin;
Expand Down
2 changes: 2 additions & 0 deletions src/Mgate/PubliBundle/Entity/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Document
{
const DOCUMENT_STORAGE_ROOT = '/../var/documents'; //document storage root on kernerl->getrootdir() path.

const DOCUMENT_TMP_FOLDER = '/../web/tmp'; // tmp folder in web directory on kernerl->getrootdir() path.

/**
* @ORM\Id
* @ORM\Column(type="integer")
Expand Down
83 changes: 61 additions & 22 deletions src/Mgate/SuiviBundle/Manager/ChartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
namespace Mgate\SuiviBundle\Manager;

use Doctrine\ORM\EntityManager;
use Mgate\PubliBundle\Entity\Document;
use Mgate\SuiviBundle\Entity\ClientContact;
use Mgate\SuiviBundle\Entity\Etude as Etude;
use Mgate\SuiviBundle\Entity\Phase;
use Monolog\Logger;
use Ob\HighchartsBundle\Highcharts\Highchart;
use Symfony\Component\HttpKernel\KernelInterface;
use Webmozart\KeyValueStore\Api\KeyValueStore;
use Zend\Json\Expr;

Expand All @@ -30,9 +32,12 @@ class ChartManager /*extends \Twig_Extension*/

protected $namingConvention;

protected $rootDir;

private const SIX_MONTHS = 15724800;

public function __construct(EntityManager $em, EtudeManager $etudeManager, Logger $logger, KeyValueStore $keyValueStore)
public function __construct(EntityManager $em, EtudeManager $etudeManager, Logger $logger,
KeyValueStore $keyValueStore, KernelInterface $kernel)
{
$this->em = $em;
$this->etudeManager = $etudeManager;
Expand All @@ -42,6 +47,7 @@ public function __construct(EntityManager $em, EtudeManager $etudeManager, Logge
} else {
$this->namingConvention = 'id';
}
$this->rootDir = $kernel->getRootDir();
}

public function getGantt(Etude $etude, $type)
Expand All @@ -66,7 +72,9 @@ public function getGantt(Etude $etude, $type)
}

$data[] = ['x' => count($cats), 'y' => $date->getTimestamp() * 1000,
'titre' => $contact->getObjet(), 'detail' => 'fait par ' . $contact->getFaitPar()->getPrenomNom() . ' le ' . $date->format('d/m/Y'), ];
'titre' => $contact->getObjet(), 'detail' => 'fait par ' . $contact->getFaitPar()
->getPrenomNom() . ' le ' . $date->format('d/m/Y'),
];
}
$series[] = ['type' => 'scatter', 'data' => $data];
$cats[] = 'Contact client';
Expand All @@ -91,8 +99,11 @@ public function getGantt(Etude $etude, $type)
}

$data[] = ['x' => count($cats), 'y' => $date->getTimestamp() * 1000,
'titre' => 'Avant-Projet', 'detail' => 'signé le ' . $date->format('d/m/Y'), ];
$series[] = ['type' => 'scatter', 'data' => $data, 'marker' => ['symbol' => 'square', 'fillColor' => 'blue']];
'titre' => 'Avant-Projet', 'detail' => 'signé le ' . $date->format('d/m/Y'),
];
$series[] = ['type' => 'scatter', 'data' => $data,
'marker' => ['symbol' => 'square', 'fillColor' => 'blue'],
];
}
$data = $dataSauv;
if ($etude->getCc() && $etude->getCc()->getDateSignature()) {
Expand All @@ -105,8 +116,11 @@ public function getGantt(Etude $etude, $type)
}

$data[] = ['x' => count($cats), 'y' => $date->getTimestamp() * 1000,
'titre' => 'Convention Client', 'detail' => 'signé le ' . $date->format('d/m/Y'), ];
$series[] = ['type' => 'scatter', 'data' => $data, 'marker' => ['symbol' => 'triangle', 'fillColor' => 'red']];
'titre' => 'Convention Client', 'detail' => 'signé le ' . $date->format('d/m/Y'),
];
$series[] = ['type' => 'scatter', 'data' => $data,
'marker' => ['symbol' => 'triangle', 'fillColor' => 'red'],
];
}
$data = $dataSauv;
if ($etude->getPvr() && $etude->getPvr()->getDateSignature()) {
Expand All @@ -119,7 +133,8 @@ public function getGantt(Etude $etude, $type)
}

$data[] = ['x' => count($cats), 'y' => $date->getTimestamp() * 1000,
'titre' => 'Procès Verbal de Recette', 'detail' => 'signé le ' . $date->format('d/m/Y'), ];
'titre' => 'Procès Verbal de Recette', 'detail' => 'signé le ' . $date->format('d/m/Y'),
];
$series[] = ['type' => 'scatter', 'data' => $data, 'marker' => ['symbol' => 'circle']];
}
$cats[] = 'Documents';
Expand All @@ -137,8 +152,11 @@ public function getGantt(Etude $etude, $type)
$debut = $etude->getDateLancement();
$fin = $etude->getDateFin(true);

$data[] = ['low' => $debut->getTimestamp() * 1000, 'y' => $fin->getTimestamp() * 1000, 'color' => '#005CA4',
'titre' => 'Durée de déroulement des phases', 'detail' => 'du ' . $debut->format('d/m/Y') . ' au ' . $fin->format('d/m/Y'), ];
$data[] = ['low' => $debut->getTimestamp() * 1000, 'y' => $fin->getTimestamp() * 1000,
'color' => '#005CA4',
'titre' => 'Durée de déroulement des phases',
'detail' => 'du ' . $debut->format('d/m/Y') . ' au ' . $fin->format('d/m/Y'),
];

$cats[] = 'Etude';
}
Expand All @@ -160,8 +178,13 @@ public function getGantt(Etude $etude, $type)

$func = new Expr('function() {return this.point.titre;}');
$data[] = ['low' => $fin->getTimestamp() * 1000, 'y' => $debut->getTimestamp() * 1000,
'titre' => $phase->getTitre(), 'detail' => 'du ' . $debut->format('d/m/Y') . ' au ' . $fin->format('d/m/Y'), 'color' => '#F26729',
'dataLabels' => ['enabled' => true, 'align' => 'left', 'inside' => true, 'verticalAlign' => 'bottom', 'formatter' => $func, 'y' => -5], ];
'titre' => $phase->getTitre(),
'detail' => 'du ' . $debut->format('d/m/Y') . ' au ' . $fin->format('d/m/Y'),
'color' => '#F26729',
'dataLabels' => ['enabled' => true, 'align' => 'left', 'inside' => true,
'verticalAlign' => 'bottom', 'formatter' => $func, 'y' => -5,
],
];
} else {
$data[] = [];
}
Expand All @@ -177,10 +200,14 @@ public function getGantt(Etude $etude, $type)
$now = new \DateTime('NOW');
$mort = ($now > $mort ? clone $now : $mort);
$data[] = ['x' => 0, 'y' => $now->getTimestamp() * 1000,
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'), ];
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'),
];
$data[] = ['x' => count($cats) - 1, 'y' => $now->getTimestamp() * 1000,
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'), ];
$series[] = ['type' => 'spline', 'data' => $data, 'marker' => ['radius' => 1, 'color' => '#545454'], 'color' => '#545454', 'lineWidth' => 1, 'pointWidth' => 5];
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'),
];
$series[] = ['type' => 'spline', 'data' => $data, 'marker' => ['radius' => 1, 'color' => '#545454'],
'color' => '#545454', 'lineWidth' => 1, 'pointWidth' => 5,
];
}
}

Expand All @@ -196,8 +223,8 @@ public function exportGantt(Highchart $ob, $filename, $width = 800)
$logger = $this->logger;

// Create the file
$chemin = 'tmp/' . $filename . '.json';
$destination = 'tmp/' . $filename . '.png';
$chemin = $this->rootDir . '' . Document::DOCUMENT_TMP_FOLDER .'/'. $filename . '.json';
$destination = $this->rootDir . '' . Document::DOCUMENT_TMP_FOLDER .'/'. $filename . '.png';

$render = $ob->render();

Expand Down Expand Up @@ -271,8 +298,13 @@ public function getGanttSuivi(array $etudes)

$func = new Expr('function() {return this.point.titre;}');
$data[] = ['low' => $fin->getTimestamp() * 1000, 'y' => $debut->getTimestamp() * 1000,
'titre' => $etude->getNom(), 'detail' => 'du ' . $debut->format('d/m/Y') . ' au ' . $fin->format('d/m/Y'), 'color' => '#F26729',
'dataLabels' => ['enabled' => true, 'align' => 'left', 'inside' => true, 'verticalAlign' => 'bottom', 'formatter' => $func, 'y' => -5], ];
'titre' => $etude->getNom(),
'detail' => 'du ' . $debut->format('d/m/Y') . ' au ' . $fin->format('d/m/Y'),
'color' => '#F26729',
'dataLabels' => ['enabled' => true, 'align' => 'left', 'inside' => true,
'verticalAlign' => 'bottom', 'formatter' => $func, 'y' => -5,
],
];
} else {
$data[] = [];
}
Expand All @@ -286,10 +318,14 @@ public function getGanttSuivi(array $etudes)

$now = new \DateTime('NOW');
$data[] = ['x' => 0, 'y' => $now->getTimestamp() * 1000,
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'), ];
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'),
];
$data[] = ['x' => count($categories) - 1, 'y' => $now->getTimestamp() * 1000,
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'), ];
$series[] = ['type' => 'spline', 'data' => $data, 'marker' => ['radius' => 1, 'color' => '#545454'], 'color' => '#545454', 'lineWidth' => 1, 'pointWidth' => 5];
'titre' => "aujourd'hui", 'detail' => 'le ' . $now->format('d/m/Y'),
];
$series[] = ['type' => 'spline', 'data' => $data, 'marker' => ['radius' => 1, 'color' => '#545454'],
'color' => '#545454', 'lineWidth' => 1, 'pointWidth' => 5,
];

$ob = $this->ganttChartFactory($series, $categories);
$ob->chart->renderTo('ganttChart'); // The #id of the div where to render the chart
Expand All @@ -316,7 +352,10 @@ private function ganttChartFactory($series, $categories)
$ob->credits->enabled(false);
$ob->legend->enabled(false);
$ob->exporting->enabled(false);
$ob->plotOptions->series(['pointPadding' => 0, 'groupPadding' => 0, 'pointWidth' => 10, 'groupPadding' => 0, 'marker' => ['radius' => 5], 'tooltip' => ['pointFormat' => '<b>{point.titre}</b><br /> {point.detail}']]);
$ob->plotOptions->series(['pointPadding' => 0, 'groupPadding' => 0, 'pointWidth' => 10, 'groupPadding' => 0,
'marker' => ['radius' => 5],
'tooltip' => ['pointFormat' => '<b>{point.titre}</b><br /> {point.detail}'],
]);
$ob->plotOptions->scatter(['tooltip' => ['headerFormat' => '']]);
$ob->series($series);

Expand Down
1 change: 1 addition & 0 deletions src/Mgate/SuiviBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- "@Mgate.etude_manager"
- "@logger"
- "@app.json_key_value_store"
- "@kernel"

form.type_extension.help_message:
class: Mgate\SuiviBundle\Form\Extension\HelpMessageTypeExtension
Expand Down

0 comments on commit cff1c23

Please sign in to comment.