Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:cross-solution/YAWIK
- Loading branch information
Showing
4 changed files
with
182 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
module/Core/test/CoreTest/Form/View/Helper/FormDatePickerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
namespace CoreTest\Form\View\Helper; | ||
|
||
use Core\Form\View\Helper\FormDatePicker; | ||
use PHPUnit\Framework\TestCase; | ||
use Core\Form\View\Helper\FormDatePicker as DatePickerHelper; | ||
use Core\Form\Element\DatePicker as DatePickerElement; | ||
use Laminas\View\Renderer\PhpRenderer as View; | ||
use Laminas\I18n\Translator\TranslatorInterface as Translator; | ||
|
||
/** | ||
* @coversDefaultClass Core\Form\View\Helper\FormDatePicker | ||
*/ | ||
class FormDatePickerTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var DatePickerHelper | ||
*/ | ||
protected $datePickerHelper; | ||
|
||
/** | ||
* @see PHPUnit\Framework\TestCase::setUp() | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$view = new View(); | ||
|
||
$paramsPluginMock = $this->getMockBuilder('\Core\View\Helper\Params')->disableOriginalConstructor()->getMock(); | ||
$pluginManager = $view->getHelperPluginManager(); | ||
$pluginManager->setService('params', $paramsPluginMock); | ||
$view->setHelperPluginManager($pluginManager); | ||
|
||
$translator = $this->getMockBuilder(Translator::class) | ||
->getMock(); | ||
$translator->method('translate') | ||
->willReturnArgument(0); | ||
|
||
$this->datePickerHelper = new DatePickerHelper(); | ||
$this->datePickerHelper->setView($view); | ||
$this->datePickerHelper->setTranslator($translator); | ||
} | ||
|
||
/** | ||
* @covers ::render | ||
*/ | ||
public function testRenderDateFormatAttribute() | ||
{ | ||
$element = new DatePickerElement('elementName'); | ||
|
||
// test default date forma | ||
$expectedResultString = $this->datePickerHelper->createAttributesString(['data-date-format' => FormDatePicker::DEFAULT_DATE_FORMAT]); | ||
$result = $this->datePickerHelper->render($element); | ||
|
||
$this->assertIsString($result); | ||
$this->assertContains($expectedResultString, $result); | ||
|
||
// test different date format | ||
$element->setAttribute('data-date-format', 'dd/m/yyyy'); | ||
$expectedResultString = $this->datePickerHelper->createAttributesString(['data-date-format' => 'dd/m/yyyy']); | ||
$result = $this->datePickerHelper->render($element); | ||
|
||
$this->assertIsString($result); | ||
$this->assertContains($expectedResultString, $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
module/Jobs/test/JobsTest/Controller/ConsoleControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/* | ||
* This file is part of the Omed Project. | ||
* | ||
* (c) Anthonius Munthi <me@itstoni.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JobsTest\Controller; | ||
|
||
use Core\Repository\RepositoryService; | ||
use Jobs\Controller\ConsoleController; | ||
use Jobs\Entity\Job; | ||
use Jobs\Repository\Job as JobRepository; | ||
use Laminas\Console\Adapter\AdapterInterface as ConsoleAdapter; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ConsoleControllerTest extends TestCase | ||
{ | ||
/** | ||
* @var ConsoleController | ||
*/ | ||
private $target; | ||
|
||
/** | ||
* @var JobRepository | ||
*/ | ||
private $jobRepo; | ||
|
||
/** | ||
* @var MockObject|ConsoleAdapter | ||
*/ | ||
private $console; | ||
|
||
protected function setUp() | ||
{ | ||
$this->jobRepo = $this->createMock(JobRepository::class); | ||
|
||
$repositories = $this->createMock(RepositoryService::class); | ||
$repositories->expects($this->once()) | ||
->method('get') | ||
->with('Jobs/Job') | ||
->willReturn($this->jobRepo); | ||
|
||
$this->console = $this->createMock(ConsoleAdapter::class); | ||
$this->target = $this->getMockBuilder(ConsoleController::class) | ||
->setConstructorArgs([$repositories]) | ||
->setMethods(['params']) | ||
->getMock() | ||
; | ||
$this->target->setConsole($this->console); | ||
} | ||
|
||
/** | ||
* @see https://github.com/cross-solution/YAWIK/issues/442 | ||
*/ | ||
public function testExpireJobsInfoAction() | ||
{ | ||
$jobRepo = $this->jobRepo; | ||
$console = $this->console; | ||
$controller = $this->target; | ||
$controller->method('params') | ||
->willReturnMap([ | ||
['days',30], | ||
['limit',10], | ||
['info',true] | ||
]); | ||
|
||
$job = new Job(); | ||
$job->setId('some-id'); | ||
$job->setTitle('Some Title'); | ||
$job->setCompany('Some Company'); | ||
|
||
$jobRepo->expects($this->once()) | ||
->method('findBy') | ||
->with($this->isType('array'),null,10,0) | ||
->willReturn([$job]); | ||
|
||
$console->expects($this->exactly(2)) | ||
->method('writeLine') | ||
->withConsecutive( | ||
['1 Jobs',4,null], | ||
[$this->stringContains('some-id'),3,null] | ||
); | ||
|
||
$controller->expireJobsAction(); | ||
|
||
} | ||
} |