Skip to content

Commit

Permalink
Added checkbox to check/uncheck all software.
Browse files Browse the repository at this point in the history
  • Loading branch information
hschletz committed Oct 27, 2018
1 parent 24b2aa6 commit c4c1ec5
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 330 deletions.
117 changes: 68 additions & 49 deletions module/Console/Test/View/Helper/Form/SoftwareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,73 +115,92 @@ public function testRenderSoftwareFieldset()
{
$view = $this->createMock('Zend\View\Renderer\PhpRenderer');

$checkbox = $this->createMock('\Zend\Form\ElementInterface');
$checkbox1 = $this->createMock('\Zend\Form\ElementInterface');
$checkbox2 = $this->createMock('\Zend\Form\ElementInterface');

$fieldset = $this->createMock('Zend\Form\FieldsetInterface');
$fieldset->method('get')
->with('c29mdHdhcmVfbmFtZQ==') // 'software_name'
->willReturn($checkbox);
->withConsecutive(
['c29mdHdhcmVfbmFtZTE='], // 'software_name1'
['c29mdHdhcmVfbmFtZTI='] // 'software_name2'
)->willReturnOnConsecutiveCalls($checkbox1, $checkbox2);

$software = [
['name' => 'software_name', 'num_clients' => 42],
['name' => 'software_name1', 'num_clients' => 2],
['name' => 'software_name2', 'num_clients' => 1],
];

$sorting = ['order' => 'current_order', 'direction' => 'current_direction'];

$formRow = $this->createMock('Zend\Form\View\Helper\FormRow');
$formRow->expects($this->at(0))->method('isTranslatorEnabled')->willReturn('translatorEnabled');
$formRow->expects($this->at(1))->method('setTranslatorEnabled')->with(false);
$formRow->expects($this->at(2))->method('__invoke')
->with($checkbox, \Zend\Form\View\Helper\FormRow::LABEL_APPEND)
->willReturn('checkbox');
$formRow->expects($this->at(3))->method('setTranslatorEnabled')->with('translatorEnabled');
->with($checkbox1, \Zend\Form\View\Helper\FormRow::LABEL_APPEND)
->willReturn('checkbox1');
$formRow->expects($this->at(3))->method('__invoke')
->with($checkbox2, \Zend\Form\View\Helper\FormRow::LABEL_APPEND)
->willReturn('checkbox2');
$formRow->expects($this->at(4))->method('setTranslatorEnabled')->with('translatorEnabled');

$translate = $this->createMock('Zend\I18n\View\Helper\Translate');
$translate->method('__invoke')->willReturnMap([
['Name', null, null, 'NAME'],
['Count', null, null, 'COUNT'],
]);
$translate->method('__invoke')
->withConsecutive(
['Name', null, null],
['Count', null, null]
)->willReturnOnConsecutiveCalls('NAME', 'COUNT');

$consoleUrl = $this->createMock('Library\View\Helper\HtmlElement');
$consoleUrl->method('__invoke')->with(
'client',
'index',
[
'columns' => 'Name,UserName,LastContactDate,InventoryDate,Software.Version',
'jumpto' => 'software',
'filter' => 'Software',
'search' => 'software_name',
]
)->willReturn('url');
$consoleUrl->method('__invoke')
->withConsecutive(
[
'client',
'index',
[
'columns' => 'Name,UserName,LastContactDate,InventoryDate,Software.Version',
'jumpto' => 'software',
'filter' => 'Software',
'search' => 'software_name1',
]
],
[
'client',
'index',
[
'columns' => 'Name,UserName,LastContactDate,InventoryDate,Software.Version',
'jumpto' => 'software',
'filter' => 'Software',
'search' => 'software_name2',
]
]
)->willReturnOnConsecutiveCalls('url1', 'url2');

$htmlElement = $this->createMock('Library\View\Helper\HtmlElement');
$htmlElement->method('__invoke')->with('a', 42, ['href' => 'url'])->willReturn('link');
$htmlElement->method('__invoke')
->withConsecutive(
['a', 2, ['href' => 'url1']],
['a', 1, ['href' => 'url2']]
)->willReturnOnConsecutiveCalls('link1', 'link2');

$table = $this->createMock('Console\View\Helper\Table');
$table->method('__invoke')
->with(
$software,
[
'name' => 'NAME',
'num_clients' => 'COUNT'
],
'sorting',
$this->callback(function ($subject) use ($view, $software) {
if (count($subject) != 2) {
return false;
}
$checkbox = $subject['name']($view, $software[0]);
if ($checkbox != 'checkbox') {
printf("\nnname callback expected 'checkbox', got: %s\n", var_export($checkbox, true));
return false;
}
$link = $subject['num_clients']($view, $software[0]);
if ($link != 'link') {
printf("\nnum_clients callback expected 'link', got: %s\n", var_export($link, true));
return false;
}
return true;
}),
['num_clients' => 'textright']
)->willReturn('softwareFieldset');
$table->method('row')
->withConsecutive(
[
['name' => '<input type="checkbox" class="checkAll">header_name', 'num_clients' => 'header_count'],
true,
[],
null,
],
[['name' => 'checkbox1', 'num_clients' => 'link1'], false, ['num_clients' => 'textright'], null],
[['name' => 'checkbox2', 'num_clients' => 'link2'], false, ['num_clients' => 'textright'], null]
)
->willReturnOnConsecutiveCalls('<header>', '<row1>', '<row2>');
$table->method('sortableHeader')
->withConsecutive(
['NAME', 'name', 'current_order', 'current_direction'],
['COUNT', 'num_clients', 'current_order', 'current_direction']
)->willReturnOnConsecutiveCalls('header_name', 'header_count');
$table->method('tag')->with('<header><row1><row2>')->willReturn('softwareFieldset');

$view->method('plugin')->willReturnMap([
['formRow', null, $formRow],
Expand All @@ -199,7 +218,7 @@ public function testRenderSoftwareFieldset()

$this->assertEquals(
'softwareFieldset',
$helper->renderSoftwareFieldset($fieldset, $software, 'sorting')
$helper->renderSoftwareFieldset($fieldset, $software, $sorting)
);
}
}
Loading

0 comments on commit c4c1ec5

Please sign in to comment.