|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Files\Grid\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Grid\Factory\GridFactory; |
|
8
|
|
|
use AbterPhp\Admin\Grid\Factory\PaginationFactory; |
|
9
|
|
|
use AbterPhp\Admin\Helper\DateHelper; |
|
10
|
|
|
use AbterPhp\Files\Domain\Entities\File as Entity; |
|
11
|
|
|
use AbterPhp\Files\Grid\Factory\Table\File as TableFactory; |
|
12
|
|
|
use AbterPhp\Files\Grid\Filters\File as Filters; |
|
13
|
|
|
use AbterPhp\Framework\Grid\IGrid; |
|
14
|
|
|
use Opulence\Routing\Urls\UrlGenerator; |
|
15
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class FileTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var File - System Under Test */ |
|
21
|
|
|
protected $sut; |
|
22
|
|
|
|
|
23
|
|
|
/** @var MockObject|UrlGenerator */ |
|
24
|
|
|
protected $urlGeneratorMock; |
|
25
|
|
|
|
|
26
|
|
|
/** @var MockObject|PaginationFactory */ |
|
27
|
|
|
protected $paginationFactoryMock; |
|
28
|
|
|
|
|
29
|
|
|
/** @var MockObject|TableFactory */ |
|
30
|
|
|
protected $tableFactoryMock; |
|
31
|
|
|
|
|
32
|
|
|
/** @var MockObject|GridFactory */ |
|
33
|
|
|
protected $gridFactoryMock; |
|
34
|
|
|
|
|
35
|
|
|
/** @var MockObject|Filters */ |
|
36
|
|
|
protected $filtersMock; |
|
37
|
|
|
|
|
38
|
|
|
public function setUp(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->urlGeneratorMock = $this->createMock(UrlGenerator::class); |
|
41
|
|
|
$this->paginationFactoryMock = $this->createMock(PaginationFactory::class); |
|
42
|
|
|
$this->tableFactoryMock = $this->createMock(TableFactory::class); |
|
43
|
|
|
$this->gridFactoryMock = $this->createMock(GridFactory::class); |
|
44
|
|
|
$this->filtersMock = $this->createMock(Filters::class); |
|
45
|
|
|
|
|
46
|
|
|
$this->sut = new File( |
|
47
|
|
|
$this->urlGeneratorMock, |
|
48
|
|
|
$this->paginationFactoryMock, |
|
49
|
|
|
$this->tableFactoryMock, |
|
50
|
|
|
$this->gridFactoryMock, |
|
51
|
|
|
$this->filtersMock |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testCreateGrid() |
|
56
|
|
|
{ |
|
57
|
|
|
$params = []; |
|
58
|
|
|
$baseUrl = ''; |
|
59
|
|
|
|
|
60
|
|
|
$actualResult = $this->sut->createGrid($params, $baseUrl); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertInstanceOf(IGrid::class, $actualResult); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testGetUploadedAtFormatsDateValue() |
|
66
|
|
|
{ |
|
67
|
|
|
$dateStub = new \DateTime(); |
|
68
|
|
|
|
|
69
|
|
|
$entityMock = $this->createMock(Entity::class); |
|
70
|
|
|
$entityMock->expects($this->any())->method('getUploadedAt')->willReturn($dateStub); |
|
71
|
|
|
|
|
72
|
|
|
putenv('ADMIN_DATE_FORMAT=Y-m-d'); |
|
73
|
|
|
|
|
74
|
|
|
$actualResult = $this->sut->getUploadedAt($entityMock); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertSame(DateHelper::mysqlDateTime($dateStub), $actualResult); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|