Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
fix: remove form unit tests (#9)
Browse files Browse the repository at this point in the history
* fix: remove form unit tests

* fix: migrate to PSR-4

* fix: remove global constant `DATE*_FORMAT` dependency

* fix: allow datetime formats to be configurable

* chore: bump `olcs-common` to `5.0.0-alpha.3`
  • Loading branch information
JoshuaLicense authored Jan 9, 2024
1 parent 7135aff commit 2b2acea
Show file tree
Hide file tree
Showing 189 changed files with 81 additions and 16,789 deletions.
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@
"bamarni/composer-bin-plugin": "^1.8"
},
"autoload": {
"classmap": [
"module/Admin/src",
"module/Olcs/src",
"vendor/olcs/olcs-common/Common/src/Common",
"vendor/olcs/olcs-common/test/Common"
],
"psr-4": {
"Olcs\\": "module/Olcs/src",
"Admin\\": "module/Admin/src",
"Common\\": "vendor/olcs/olcs-common/Common/src/Common",
"CommonTest\\": "vendor/olcs/olcs-common/test/Common/src/"
}
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion module/Admin/Module.php → module/Admin/src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function onBootstrap(MvcEvent $event)

public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
return include __DIR__ . '/../config/module.config.php';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Olcs\Controller\Interfaces\CaseControllerInterface;
use Olcs\Data\Mapper\Opposition as Mapper;
use Olcs\Form\Model\Form\Opposition as Form;
use Olcs\Module;
use Olcs\Mvc\Controller\ParameterProvider\GenericItem;
use Olcs\Mvc\Controller\ParameterProvider\GenericList;

Expand Down Expand Up @@ -211,7 +212,7 @@ private function alterFormForCase($form, $initialData)

if (!empty($caseWithOppositionDates['oorDate'])) {
// set oor date
$oorString = (new \DateTime($caseWithOppositionDates['oorDate']))->format(\DATE_FORMAT);
$oorString = (new \DateTime($caseWithOppositionDates['oorDate']))->format(Module::$dateFormat);

$form->get('fields')
->get('outOfRepresentationDate')
Expand All @@ -220,7 +221,7 @@ private function alterFormForCase($form, $initialData)

if (!empty($caseWithOppositionDates['oooDate'])) {
// set ooo date
$oooString = (new \DateTime($caseWithOppositionDates['oooDate']))->format(\DATE_FORMAT);
$oooString = (new \DateTime($caseWithOppositionDates['oooDate']))->format(Module::$dateFormat);

$form->get('fields')
->get('outOfObjectionDate')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Laminas\Form\Form;
use Olcs\Controller\Lva\Traits\ApplicationControllerTrait;
use Olcs\Module;
use ZfcRbac\Service\AuthorizationService;

/**
Expand Down Expand Up @@ -82,9 +83,9 @@ protected function alterFormForLva(Form $form, $data = null)
$form->get('declarations')->get('verifySignatureText')->setValue(
sprintf(
'This application has been digitally signed on %s by %s with date of birth %s',
(new \DateTime($signatureDetails['date']))->format(\DATE_FORMAT),
(new \DateTime($signatureDetails['date']))->format(Module::$dateFormat),
$signatureDetails['name'],
(new \DateTime($signatureDetails['dob']))->format(\DATE_FORMAT)
(new \DateTime($signatureDetails['dob']))->format(Module::$dateFormat)
)
);

Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Controller/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Laminas\View\Model\ViewModel;
use Olcs\Controller\Traits as ControllerTraits;
use Olcs\Data\Mapper;
use Olcs\Module;
use Olcs\Service\Data\SubCategory;
use Olcs\Service\Data\UserListInternalExcludingLimitedReadOnlyUsers;

Expand Down Expand Up @@ -319,7 +320,7 @@ protected function prepareInfoColumns($data)
{
if (isset($data['lastModifiedOn']) && isset($data['lastModifiedByDetails'])) {
$data['lastModifiedByDetails'] .=
' (' . (new \DateTime($data['lastModifiedOn']))->format(\DATETIMESEC_FORMAT) . ')';
' (' . (new \DateTime($data['lastModifiedOn']))->format(Module::$dateTimeSecFormat) . ')';
}
return $data;
}
Expand Down
5 changes: 3 additions & 2 deletions module/Olcs/src/Data/Mapper/EventHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Olcs\Data\Mapper;

use Dvsa\Olcs\Utils\Helper\DateTimeHelper;
use Olcs\Module;

/**
* Event History
Expand All @@ -23,7 +24,7 @@ public static function mapFromResult(array $data)
$result['details'] = $data['eventHistoryType']['description'];
$result['info'] = $data['eventData'];

$result['date'] = date(\DATETIME_FORMAT, strtotime($data['eventDatetime']));
$result['date'] = date(Module::$dateTimeFormat, strtotime($data['eventDatetime']));

$result['by'] = isset($data['user']['contactDetails']['person']['forename']) &&
isset($data['user']['contactDetails']['person']['familyName']) ?
Expand All @@ -43,7 +44,7 @@ function (&$item) use ($dateFields) {

foreach (['newValue', 'oldValue'] as $key) {
if (!empty($item[$key])) {
$item[$key] = DateTimeHelper::format($item[$key], \DATETIME_FORMAT);
$item[$key] = DateTimeHelper::format($item[$key], Module::$dateTimeFormat);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Data/Mapper/IrfoPsvAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Common\Data\Mapper\MapperInterface;
use Laminas\Form\FormInterface;
use Olcs\Module;

/**
* Class IrfoPsvAuth Mapper
Expand Down Expand Up @@ -35,7 +36,7 @@ public static function mapFromResult(array $data)
if (!empty($formData['fields']['createdOn'])) {
// format createOn date
$createdOn = new \DateTime($formData['fields']['createdOn']);
$formData['fields']['createdOnHtml'] = $createdOn->format(\DATE_FORMAT);
$formData['fields']['createdOnHtml'] = $createdOn->format(Module::$dateFormat);
}

// default all copies fields to 0
Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Data/Mapper/Pi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Common\Data\Mapper\MapperInterface;
use Dvsa\Olcs\Utils\Helper\DateTimeHelper;
use Laminas\Form\FormInterface;
use Olcs\Module;

/**
* Class Pi
Expand Down Expand Up @@ -72,7 +73,7 @@ public static function mapFromErrors(FormInterface $form, array $errors)
foreach ($errors['messages'] as $key => $value) {
if ($key === 'DECISION_DATE_BEFORE_HEARING_DATE') {
/** @var DateTimeSelect $e */
$hearingDate = DateTimeHelper::format($value, DATE_FORMAT);
$hearingDate = DateTimeHelper::format($value, Module::$dateFormat);
$form->get('fields')->get('decisionDate')->setMessages(
['Decision date must be after or the same as the PI hearing date '. $hearingDate]
);
Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Data/Mapper/PiHearing.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Common\Form\Elements\Custom\DateTimeSelect;
use Dvsa\Olcs\Utils\Helper\DateTimeHelper;
use Laminas\Form\FormInterface;
use Olcs\Module;

/**
* Class PiHearing
Expand Down Expand Up @@ -104,7 +105,7 @@ public static function mapFromErrors(FormInterface $form, array $errors)
foreach ($errors['messages'] as $key => $value) {
if ($key === 'HEARING_DATE_BEFORE_PI') {
/** @var DateTimeSelect $e */
$piDate = DateTimeHelper::format($value, DATE_FORMAT);
$piDate = DateTimeHelper::format($value, Module::$dateFormat);
$form->get('fields')->get('hearingDate')->setMessages(
['Hearing date must be after or the same as the PI agreed date '. $piDate]
);
Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Data/Mapper/PublicationLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Common\Data\Mapper\MapperInterface;
use Laminas\Form\FormInterface;
use Olcs\Module;

/**
* Class Generic Mapper for forms with Fields field set
Expand All @@ -25,7 +26,7 @@ public static function mapFromResult(array $data)
'status' => $data['publication']['pubStatus']['description'],
'section' => $data['publicationSection']['description'],
'trafficArea' => $data['publication']['trafficArea']['name'],
'publicationDate' => date(\DATE_FORMAT, strtotime($data['publication']['pubDate']))
'publicationDate' => date(Module::$dateFormat, strtotime($data['publication']['pubDate']))
];

$textFields = [
Expand Down
7 changes: 4 additions & 3 deletions module/Olcs/src/Data/Mapper/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use Common\Data\Mapper\MapperInterface;
use Dvsa\Olcs\Utils\Helper\DateTimeHelper;
use Olcs\Data\Mapper\Traits as MapperTraits;
use Laminas\Form\FormInterface;
use Olcs\Data\Mapper\Traits as MapperTraits;
use Olcs\Module;

/**
* Class User Mapper
Expand Down Expand Up @@ -46,15 +47,15 @@ public static function mapFromResult(array $data)
= !empty($data['lockedOn'])
? sprintf(
'Yes on %s',
(new \DateTime($data['lockedOn']))->format(\DATETIMESEC_FORMAT)
(new \DateTime($data['lockedOn']))->format(Module::$dateTimeSecFormat)
)
: 'No';

if (!empty($data['latestPasswordResetEvent'])) {
$formData['userLoginSecurity']['passwordLastReset'] = sprintf(
'%s on %s',
$data['latestPasswordResetEvent']['eventData'],
DateTimeHelper::format($data['latestPasswordResetEvent']['eventDatetime'], \DATETIMESEC_FORMAT)
DateTimeHelper::format($data['latestPasswordResetEvent']['eventDatetime'], Module::$dateTimeSecFormat)
);
}

Expand Down
13 changes: 11 additions & 2 deletions module/Olcs/Module.php → module/Olcs/src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

namespace Olcs;

use Common\Exception\ResourceNotFoundException;
use Laminas\Mvc\ModuleRouteListener;
use Laminas\Mvc\MvcEvent;
use Laminas\View\Model\ViewModel;
use Common\Exception\ResourceNotFoundException;
use Olcs\Listener\HeaderSearch;
use Olcs\Listener\RouteParams;

Expand All @@ -22,6 +22,10 @@
*/
class Module
{
public static string $dateFormat = 'd/m/Y';
public static string $dateTimeFormat = 'd/m/Y H:i';
public static string $dateTimeSecFormat = 'd/m/Y H:i:s';

/**
* Event to Bootstrap the module
*
Expand All @@ -31,6 +35,11 @@ class Module
*/
public function onBootstrap(MvcEvent $e)
{
$config = $e->getApplication()->getServiceManager()->get('Config');

self::$dateFormat = $config['date_settings']['date_format'] ?? self::$dateFormat;
self::$dateTimeFormat = $config['date_settings']['datetime_format'] ?? self::$dateTimeFormat;
self::$dateTimeSecFormat = $config['date_settings']['datetimesec_format'] ?? self::$dateTimeSecFormat;

$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
Expand Down Expand Up @@ -109,6 +118,6 @@ function (MvcEvent $e) {
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
return include __DIR__ . '/../config/module.config.php';
}
}
3 changes: 2 additions & 1 deletion module/Olcs/src/Table/Tables/NonPi.table.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Common\Service\Table\Formatter\Date;
use Olcs\Module;

return array(
'variables' => array(
Expand Down Expand Up @@ -33,7 +34,7 @@
'case_non_pi', true
);
$column['formatter'] = Date::class;
return '<a class="govuk-link" href="' . $url . '">' . date(\DATETIMESEC_FORMAT, strtotime($data['hearingDate'])) . '</a>';
return '<a class="govuk-link" href="' . $url . '">' . date(Module::$dateTimeSecFormat, strtotime($data['hearingDate'])) . '</a>';
},
'name' => 'id'
),
Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Table/Tables/hearings.table.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Common\Service\Table\Formatter\Date;
use Olcs\Module;

return array(
'variables' => array(
Expand Down Expand Up @@ -37,7 +38,7 @@
$url = $this->generateUrl(['action' => 'edit', 'id' => $data['id']], 'case_pi', true);

$column['formatter'] = Date::class;
return '<a class="govuk-link" href="' . $url . '">' . date(\DATE_FORMAT, strtotime($data['hearingDate'])) . '</a>';
return '<a class="govuk-link" href="' . $url . '">' . date(Module::$dateFormat, strtotime($data['hearingDate'])) . '</a>';
},
'name' => 'id'
),
Expand Down
4 changes: 3 additions & 1 deletion module/Olcs/src/Table/Tables/piHearing.table.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Olcs\Module;

return array(
'variables' => array(
'titleSingular' => 'Hearing',
Expand Down Expand Up @@ -40,7 +42,7 @@
array(
'title' => 'Date of PI',
'formatter' => function ($data) {
$date = date(\DATE_FORMAT, strtotime($data['hearingDate']));
$date = date(Module::$dateFormat, strtotime($data['hearingDate']));
if (!empty($data['pi']['closedDate'])) {
return $date;
} else {
Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Table/Tables/publication.table.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Common\Service\Table\Formatter\Date;
use Olcs\Module;

return array(
'variables' => array(
Expand Down Expand Up @@ -65,7 +66,7 @@
'title' => 'Publication date',
'formatter' => function ($data) {
$date = new DateTime($data['publication']['pubDate']);
return $date->format(\DATE_FORMAT);
return $date->format(Module::$dateFormat);
}
),
array(
Expand Down
3 changes: 2 additions & 1 deletion module/Olcs/src/Table/Tables/submission.table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Common\Service\Table\Formatter\HideIfClosedRadio;
use Common\Service\Table\Formatter\Name;
use Common\Service\Table\Formatter\YesNo;
use Olcs\Module;

return array(
'variables' => array(
Expand Down Expand Up @@ -62,7 +63,7 @@
array(
'title' => 'Date created',
'formatter' => function ($row) {
return date(\DATETIMESEC_FORMAT, strtotime($row['createdOn']));
return date(Module::$dateTimeSecFormat, strtotime($row['createdOn']));
},
'sort' => 'createdOn'
),
Expand Down
Loading

0 comments on commit 2b2acea

Please sign in to comment.