Skip to content

Commit

Permalink
Merge branch 'release/2.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiov committed Nov 5, 2021
2 parents d090eea + 74e1e03 commit ee9dd81
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 17 deletions.
16 changes: 9 additions & 7 deletions coverage.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@


Code Coverage Report:
2021-10-07 10:27:55
2021-11-05 20:17:31

Summary:
Classes: 53.23% (33/62)
Methods: 55.22% (111/201)
Lines: 36.18% (411/1136)
Classes: 57.14% (36/63)
Methods: 59.11% (120/203)
Lines: 38.24% (444/1161)

Application\Controller\PageController
Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 2/ 2)
Expand Down Expand Up @@ -39,13 +39,13 @@ Application\ViewHelper\HelpTooltip
Application\ViewHelper\Pagination
Methods: 0.00% ( 0/ 2) Lines: 0.00% ( 0/ 22)
Application\ViewHelper\RichInlineScript
Methods: 25.00% ( 1/ 4) Lines: 46.67% ( 7/ 15)
Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 15/ 15)
Application\ViewHelper\SbaFormRow
Methods: 0.00% ( 0/ 2) Lines: 0.00% ( 0/ 18)
Application\ViewHelper\SortLink
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 12/ 12)
Application\ViewHelper\UserData
Methods: 0.00% ( 0/ 4) Lines: 0.00% ( 0/ 6)
Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 7/ 7)
Auth\Controller\RegistrationController
Methods: 10.00% ( 1/10) Lines: 8.51% ( 8/ 94)
Auth\Controller\UserController
Expand Down Expand Up @@ -87,7 +87,7 @@ MoneyLog\Controller\CategoryController
MoneyLog\Controller\DashboardController
Methods: 0.00% ( 0/ 2) Lines: 0.00% ( 0/ 46)
MoneyLog\Controller\MovementController
Methods: 0.00% ( 0/10) Lines: 0.00% ( 0/103)
Methods: 0.00% ( 0/10) Lines: 0.00% ( 0/109)
MoneyLog\Controller\ProvisionController
Methods: 0.00% ( 0/ 5) Lines: 0.00% ( 0/ 43)
MoneyLog\Controller\SettingsController
Expand All @@ -112,6 +112,8 @@ MoneyLog\Form\MovementForm
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 28/ 28)
MoneyLog\Form\ProvisionForm
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 10/ 10)
MoneyLog\Form\SearchMovementForm
Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 18/ 18)
MoneyLog\Form\SettingForm
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 8/ 8)
MoneyLog\View\Helper\BalanceModalForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public function getUserAccountBalances(int $userId): array
->select('a.id', 'a.name', 'a.status', 'COALESCE(SUM(m.amount), 0) AS balance')
->from(Account::class, 'a')
->join('a.movements', 'm', Join::WITH, "a.user=$userId")
->groupBy('a.id');
->where('a.status<>:status')
->groupBy('a.id')
->setParameter('status', Account::STATUS_CLOSED);

return $qb->getQuery()->getResult();
}
Expand Down
55 changes: 55 additions & 0 deletions module/Application/test/ViewHelper/RichInlineScriptTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace ApplicationTest\ViewHelper;

use Application\ViewHelper\RichInlineScript;
use Laminas\View\Helper\InlineScript;
use Laminas\View\Renderer\PhpRenderer;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class RichInlineScriptTest extends TestCase
{
use ProphecyTrait;

public function testAddOnDocumentReady(): void
{
$js = 'alert(\'Hello\');';
$expected = "$(document).ready(function(){\n $js\n\n});\n";

$inlineScriptProphecy = $this->prophesize(InlineScript::class);
$inlineScriptProphecy->appendScript($expected)->willReturn(null);
$inlineScriptProphecy->__toString()->willReturn($expected);

$viewProphecy = $this->prophesize(PhpRenderer::class);
$viewProphecy->inlineScript()->willReturn($inlineScriptProphecy->reveal());
/** @var \Laminas\View\Renderer\RendererInterface $view */
$view = $viewProphecy->reveal();

$richInlineScript = new RichInlineScript();
$richInlineScript->setView($view);

$richInlineScript->addOnDocumentReady($js);
self::assertSame($expected, (string) $richInlineScript);
}

public function testAddGeneric(): void
{
$js = 'alert(\'Hello\');';

$inlineScriptProphecy = $this->prophesize(InlineScript::class);
$inlineScriptProphecy->appendScript("$js\n")->willReturn(null);
$inlineScriptProphecy->__toString()->willReturn($js);

$viewProphecy = $this->prophesize(PhpRenderer::class);
$viewProphecy->inlineScript()->willReturn($inlineScriptProphecy->reveal());
/** @var \Laminas\View\Renderer\RendererInterface $view */
$view = $viewProphecy->reveal();

$richInlineScript = new RichInlineScript();
$richInlineScript->setView($view);

$richInlineScript->addGeneric($js);
self::assertSame($js, (string) $richInlineScript);
}
}
30 changes: 30 additions & 0 deletions module/Application/test/ViewHelper/UserDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace ApplicationTest\ViewHelper;

use Application\ViewHelper\UserData;
use Laminas\View\Renderer\PhpRenderer;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class UserDataTest extends TestCase
{
use ProphecyTrait;

public function testUserData(): void
{
$viewProphesize = $this->prophesize(PhpRenderer::class);
$viewProphesize->identity()->willReturn(null);
/** @var \Laminas\View\Renderer\RendererInterface $view */
$view = $viewProphesize->reveal();

$userData = new UserData();
$userData->setView($view);

self::assertSame($userData, $userData());
self::assertNull($userData->getFullName());
self::assertNull($userData->hasStored());
}
}
14 changes: 13 additions & 1 deletion module/MoneyLog/src/MoneyLog/Controller/MovementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use MoneyLog\Form\Filter\MovementFilter;
use MoneyLog\Form\MoveForm;
use MoneyLog\Form\MovementForm;
use MoneyLog\Form\SearchMovementForm;

class MovementController extends AbstractActionController
{
Expand Down Expand Up @@ -55,10 +56,16 @@ public function indexAction(): ViewModel
'orderType' => $params->fromQuery('orderType', 'DESC'),
];

$accounts = $accountRepository->findBy(['user' => $userId], ['name' => 'ASC']);

$searchMovementForm = new SearchMovementForm($accounts);
$searchMovementForm->get('account')->setValue($searchParams['account']);

return new ViewModel([
'accounts' => $accountRepository->findBy(['user' => $userId], ['name' => 'ASC']),
'accounts' => $accounts,
'balances' => $accountRepository->getUserAccountBalances($userId),
'categories' => $categoryRepository->getUserCategories($userId),
'form' => $searchMovementForm,
'page' => $page,
'paginator' => $movementRepository->paginator(array_merge($searchParams, ['user' => $userId]), $page, $pageSize),
'searchParams' => $searchParams,
Expand Down Expand Up @@ -182,6 +189,8 @@ public function addAction()

$request = $this->getRequest();
$form = new MovementForm('movement', $this->em, $this->user->getId());
$form->get('account')->setValue((int) $searchParams['account']);

if ($request->isPost()) {
$data = $request->getPost();
$form->setInputFilter(new MovementFilter());
Expand All @@ -207,6 +216,7 @@ public function addAction()
$this->em->persist($movement);
$this->em->flush();

$searchParams['account'] = $account->getId();
return $this->redirect()->toRoute('accantonaMovement', [], ['query' => $searchParams]);
}
}
Expand Down Expand Up @@ -265,6 +275,8 @@ public function editAction()
$movement->setDescription($data['description']);
$this->em->flush();

$searchParams['account'] = $account->getId();

return $this->redirect()->toRoute('accantonaMovement', [], ['query' => $searchParams]);
}
}
Expand Down
59 changes: 59 additions & 0 deletions module/MoneyLog/src/MoneyLog/Form/SearchMovementForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace MoneyLog\Form;

use Application\Entity\Account;
use Laminas\Form\Element\Select;
use Laminas\Form\Form;

class SearchMovementForm extends Form
{
/**
* @param array<Account> $accounts
*/
public function __construct(array $accounts)
{
parent::__construct();

$this->add([
'attributes' => [
'class' => 'form-control',
],
'name' => 'account',
'options' => [
'value_options' => self::getValueOptions($accounts),
],
'type' => Select::class,
]);
}

/**
* @param array<Account> $accounts
* @return array<int|string, string|array>
*/
private static function getValueOptions(array $accounts): array
{
$openedAccounts = [];
$closedAccounts = [];
$valueOptions = [0 => 'Tutti'];

foreach ($accounts as $account) {
if ($account->getStatus() === Account::STATUS_CLOSED) {
$closedAccounts[$account->getId()] = $account->getName();
} else {
$openedAccounts[$account->getId()] = $account->getName();
}
}

if ($openedAccounts && $closedAccounts) {
return array_merge($valueOptions, [
'opened' => ['label' => 'Aperti', 'options' => $openedAccounts],
'closed' => ['label' => 'Chiusi', 'options' => $closedAccounts],
]);
}

return array_merge($valueOptions, $openedAccounts, $closedAccounts);
}
}
75 changes: 75 additions & 0 deletions module/MoneyLog/test/Form/SearchMovementFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace MoneyLogTest\Form;

use Application\Entity\Account;
use MoneyLog\Form\SearchMovementForm;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class SearchMovementFormTest extends TestCase
{
use ProphecyTrait;

public function testWhitOpenAndClosed(): void
{
$bpmAccountProphecy = $this->prophesize(Account::class);
$bpmAccountProphecy->getId()->willReturn(1);
$bpmAccountProphecy->getName()->willReturn('Banco Popolare di Milano');
$bpmAccountProphecy->getStatus()->willReturn(Account::STATUS_CLOSED);
/** @var Account $bpmAccount */
$bpmAccount = $bpmAccountProphecy->reveal();

$widibaAccountProphecy = $this->prophesize(Account::class);
$widibaAccountProphecy->getId()->willReturn(2);
$widibaAccountProphecy->getName()->willReturn('Widiba');
$widibaAccountProphecy->getStatus()->willReturn(Account::STATUS_OPEN);
/** @var Account $widibaAccount */
$widibaAccount = $widibaAccountProphecy->reveal();

$form = new SearchMovementForm([$bpmAccount, $widibaAccount]);

/** @var \Laminas\Form\Element\Select $selectAccount */
$selectAccount = $form->get('account');

self::assertCount(1, $form->getElements());
self::assertSame([
0 => 'Tutti',
'opened' => [
'label' => 'Aperti',
'options' => [2 => 'Widiba']
],
'closed' => [
'label' => 'Chiusi',
'options' => [1 => 'Banco Popolare di Milano']
]
], $selectAccount->getValueOptions());
}

public function testWhitOpen(): void
{
$bpmAccountProphecy = $this->prophesize(Account::class);
$bpmAccountProphecy->getId()->willReturn(1);
$bpmAccountProphecy->getName()->willReturn('Banco Popolare di Milano');
$bpmAccountProphecy->getStatus()->willReturn(Account::STATUS_OPEN);
/** @var Account $bpmAccount */
$bpmAccount = $bpmAccountProphecy->reveal();

$widibaAccountProphecy = $this->prophesize(Account::class);
$widibaAccountProphecy->getId()->willReturn(2);
$widibaAccountProphecy->getName()->willReturn('Widiba');
$widibaAccountProphecy->getStatus()->willReturn(Account::STATUS_OPEN);
/** @var Account $widibaAccount */
$widibaAccount = $widibaAccountProphecy->reveal();

$form = new SearchMovementForm([$bpmAccount, $widibaAccount]);

/** @var \Laminas\Form\Element\Select $selectAccount */
$selectAccount = $form->get('account');

self::assertCount(1, $form->getElements());
self::assertSame(['Tutti', 'Banco Popolare di Milano', 'Widiba'], $selectAccount->getValueOptions());
}
}
10 changes: 2 additions & 8 deletions module/MoneyLog/view/money-log/movement/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @var Doctrine\ORM\Tools\Pagination\Paginator<\Application\Entity\Movement> $paginator
* @var Laminas\View\Renderer\PhpRenderer $this
* @var MoneyLog\Form\SearchMovementForm $form
* @var array<\Application\Entity\Account> $accounts
* @var array<\Application\Entity\Category> $categories
* @var array<array> $balances
Expand Down Expand Up @@ -63,14 +64,7 @@
<div class="col-lg-3 col-md-3">
<div class="form-group">
<label>Conto</label>
<select class="form-control" name="account">
<option value="0">Tutti</option>
<?php foreach ($accounts as $account): ?>
<option value="<?php echo $account->getId(); ?>"<?php if ($account->getId() == $searchParams['account']) echo ' selected="selected"'?>>
<?php echo $account->getName(); ?>
</option>
<?php endforeach; ?>
</select>
<?php echo $this->formSelect($form->get('account')); ?>
</div>
</div>
<div class="col-lg-3 col-md-3">
Expand Down

0 comments on commit ee9dd81

Please sign in to comment.