1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Acceptance; |
4
|
|
|
|
5
|
|
|
use App\DataFixtures\UserReferenceTrait; |
6
|
|
|
use App\DataFixtures\Users; |
7
|
|
|
use Dontdrinkandroot\GitkiBundle\Service\FileSystem\FileSystemService; |
8
|
|
|
use Dontdrinkandroot\GitkiBundle\Service\Wiki\WikiService; |
9
|
|
|
use Dontdrinkandroot\Path\DirectoryPath; |
10
|
|
|
use Dontdrinkandroot\Path\FilePath; |
11
|
|
|
|
12
|
|
|
class DirectoryRemoveTest extends BaseAcceptanceTest |
13
|
|
|
{ |
14
|
|
|
use UserReferenceTrait; |
15
|
|
|
|
16
|
|
|
public function testRemoveEmptyDirectoryTest() |
17
|
|
|
{ |
18
|
|
|
$referenceRepository = $this->loadClientAndFixtures([Users::class]); |
19
|
|
|
|
20
|
|
|
$directoryPath = DirectoryPath::parse('/testdirectory/'); |
21
|
|
|
/** @var FileSystemService $fileSystemService */ |
22
|
|
|
$fileSystemService = $this->getContainer()->get(FileSystemService::class); |
23
|
|
|
/** @var WikiService $wikiService */ |
24
|
|
|
$wikiService = $this->getContainer()->get(WikiService::class); |
25
|
|
|
$wikiService->createFolder($directoryPath); |
26
|
|
|
$this->assertFileExists( |
27
|
|
|
$directoryPath->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$this->login($this->getUser(Users::COMMITTER, $referenceRepository)); |
31
|
|
|
$this->client->request('GET', '/browse/testdirectory/?action=remove'); |
32
|
|
|
// $this->assertStatusCode(302, $client); |
33
|
|
|
$this->assertEquals(302, $this->client->getResponse()->getStatusCode()); |
34
|
|
|
$this->assertEquals('/browse/', $this->client->getResponse()->headers->get('Location')); |
35
|
|
|
|
36
|
|
|
$this->assertFileNotExists( |
37
|
|
|
$directoryPath->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testRemoveNonEmptyDirectoryTest() |
42
|
|
|
{ |
43
|
|
|
$referenceRepository = $this->loadClientAndFixtures([Users::class]); |
44
|
|
|
|
45
|
|
|
/** @var FileSystemService $fileSystemService */ |
46
|
|
|
$fileSystemService = $this->getContainer()->get(FileSystemService::class); |
47
|
|
|
|
48
|
|
|
$exampleFile = FilePath::parse('/examples/toc-example.md'); |
49
|
|
|
$exampleDirectory = DirectoryPath::parse('/examples/'); |
50
|
|
|
|
51
|
|
|
$this->assertFileExists( |
52
|
|
|
$exampleFile->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
53
|
|
|
); |
54
|
|
|
$this->assertFileExists( |
55
|
|
|
$exampleDirectory->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->logIn($this->getUser(Users::COMMITTER, $referenceRepository)); |
59
|
|
|
$crawler = $this->client->request('GET', '/browse/examples/?action=remove'); |
60
|
|
|
// $this->assertStatusCode(200, $client); |
61
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
62
|
|
|
$submitButton = $crawler->selectButton('Remove all files'); |
63
|
|
|
$form = $submitButton->form(); |
64
|
|
|
$this->client->submit( |
65
|
|
|
$form, |
66
|
|
|
[ |
67
|
|
|
'form[commitMessage]' => 'A test commit message' |
68
|
|
|
] |
69
|
|
|
); |
70
|
|
|
// $this->assertStatusCode(302, $client); |
71
|
|
|
$this->assertEquals(302, $this->client->getResponse()->getStatusCode()); |
72
|
|
|
$this->assertEquals('/browse/', $this->client->getResponse()->headers->get('Location')); |
73
|
|
|
|
74
|
|
|
$this->assertFileNotExists( |
75
|
|
|
$exampleFile->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
76
|
|
|
); |
77
|
|
|
$this->assertFileNotExists( |
78
|
|
|
$exampleDirectory->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testRemoveNonEmptyDirectoryWithLockTest() |
83
|
|
|
{ |
84
|
|
|
$referenceRepository = $this->loadClientAndFixtures([Users::class]); |
85
|
|
|
|
86
|
|
|
$exampleFile = FilePath::parse('/examples/toc-example.md'); |
87
|
|
|
$exampleDirectory = DirectoryPath::parse('/examples/'); |
88
|
|
|
|
89
|
|
|
/** @var FileSystemService $fileSystemService */ |
90
|
|
|
$fileSystemService = $this->getContainer()->get(FileSystemService::class); |
91
|
|
|
/** @var WikiService $wikiService */ |
92
|
|
|
$wikiService = $this->getContainer()->get(WikiService::class); |
93
|
|
|
$wikiService->createLock($this->getUser(Users::ADMIN, $referenceRepository), $exampleFile); |
94
|
|
|
|
95
|
|
|
$this->assertFileExists( |
96
|
|
|
$exampleFile->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
97
|
|
|
); |
98
|
|
|
$this->assertFileExists( |
99
|
|
|
$exampleDirectory->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString() |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$this->logIn($this->getUser(Users::COMMITTER, $referenceRepository)); |
103
|
|
|
$crawler = $this->client->request('GET', '/browse/examples/?action=remove'); |
104
|
|
|
// $this->assertStatusCode(200, $client); |
105
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
106
|
|
|
$submitButton = $crawler->selectButton('Remove all files'); |
107
|
|
|
$form = $submitButton->form(); |
108
|
|
|
$this->client->submit( |
109
|
|
|
$form, |
110
|
|
|
[ |
111
|
|
|
'form[commitMessage]' => 'A test commit message' |
112
|
|
|
] |
113
|
|
|
); |
114
|
|
|
// $this->assertStatusCode(500, $client); |
115
|
|
|
$this->assertEquals(500, $this->client->getResponse()->getStatusCode()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|