Skip to content

Commit a610a55

Browse files
authored
Merge pull request #10 from samsonasik/test-display
Test display
2 parents 1f96a65 + 0f757b1 commit a610a55

3 files changed

Lines changed: 76 additions & 25 deletions

File tree

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
"repositories": [
2222
{
2323
"type": "vcs",
24-
"url": "https://github.com/codeigniter4/CodeIgniter4"
24+
"url": "https://github.com/codeigniter4/CodeIgniter4",
25+
"no-api": true
2526
},
2627
{
2728
"type": "vcs",
28-
"url": "https://github.com/lonnieezell/myth-auth"
29+
"url": "https://github.com/lonnieezell/myth-auth",
30+
"no-api": true
2931
},
3032
{
3133
"type": "composer",

tests/feature/DisplayTest.php

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,81 @@ public function testNoFiles()
1919
public function testDefaultDisplaysCards()
2020
{
2121
$file = fake(FileFaker::class);
22-
22+
2323
$result = $this->get('files');
2424

2525
$result->assertStatus(200);
2626
$result->assertSee($file->filename);
2727
}
28+
29+
public function provideSort()
30+
{
31+
yield ['filename', 'filename'];
32+
yield ['localname', 'localname'];
33+
yield ['clientname', 'clientname'];
34+
yield ['type', 'type'];
35+
yield ['size', 'size'];
36+
yield ['thumbnail', 'thumbnail'];
37+
yield ['invalidsort', 'filename'];
38+
}
39+
40+
/**
41+
* @dataProvider provideSort
42+
*/
43+
public function testSorts(string $sort, string $configSort)
44+
{
45+
$_REQUEST['sort'] = $sort;
46+
47+
$file = fake(FileFaker::class);
48+
$result = $this->get('files');
49+
50+
$result->assertStatus(200);
51+
$this->assertEquals($configSort, service('settings')->filesSort);
52+
}
53+
54+
public function provideOrder()
55+
{
56+
yield ['asc', 'asc'];
57+
yield ['desc', 'desc'];
58+
yield ['invalid', 'asc'];
59+
}
60+
61+
/**
62+
* @dataProvider provideOrder
63+
*/
64+
public function testOrders(string $order, string $configOrder)
65+
{
66+
$_REQUEST['order'] = $order;
67+
68+
$file = fake(FileFaker::class);
69+
$result = $this->get('files');
70+
71+
$result->assertStatus(200);
72+
$this->assertEquals($configOrder, service('settings')->filesOrder);
73+
}
74+
75+
public function provideSearch()
76+
{
77+
yield ['Heathcote'];
78+
}
79+
80+
/**
81+
* @dataProvider provideSearch
82+
*/
83+
public function testSearches(string $keyword)
84+
{
85+
$_REQUEST['search'] = $keyword;
86+
87+
$file = fake(FileFaker::class);
88+
$result = $this->get('files');
89+
90+
$result->assertStatus(200);
91+
$content = $result->response->getBody();
92+
93+
if (strpos($content, $keyword) !== false) {
94+
$result->assertSee($keyword);
95+
} else {
96+
$result->assertSee('You have no files!');
97+
}
98+
}
2899
}

tests/unit/ControllerTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ protected function setUp(): void
2424
$this->controller = null;
2525
}
2626

27-
public function testThrowsWithoutAuthFunction()
28-
{
29-
// Since we cannot un-define a function we use the config override cheat
30-
$this->config->failNoAuth = true; // @phpstan-ignore-line
31-
32-
$this->expectException(FilesException::class);
33-
$this->expectExceptionMessage(lang('Files.noAuth'));
34-
35-
$controller = new Files($this->config);
36-
}
37-
3827
public function testThrowsWithInvalidStoragePath()
3928
{
4029
$this->config->storagePath = HOMEPATH . 'README.md';
@@ -57,17 +46,6 @@ public function testCreatesMissingStoragePath()
5746
$this->assertDirectoryIsWritable($this->config->storagePath);
5847
}
5948

60-
public function testUsesExternalModelIfFound()
61-
{
62-
require_once SUPPORTPATH . 'app/Models/FileModel.php';
63-
64-
$this->controller(Files::class);
65-
66-
$result = $this->getPrivateProperty($this->controller, 'model');
67-
68-
$this->assertInstanceOf('App\Models\FileModel', $result);
69-
}
70-
7149
//--------------------------------------------------------------------
7250

7351
public function testGetSortUsesInput()

0 commit comments

Comments
 (0)