Completed
Push — master ( 402c8e...a49823 )
by Philip
22:11
created

testRemoveNonEmptyDirectoryTest()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 38
rs 8.8571
cc 1
eloc 23
nc 1
nop 0
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
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function getFixtureClasses()
20
    {
21
        return [Users::class];
22
    }
23
24
    public function testRemoveEmptyDirectoryTest()
25
    {
26
        $directoryPath = DirectoryPath::parse('/testdirectory/');
27
        /** @var FileSystemService $fileSystemService */
28
        $fileSystemService = $this->getContainer()->get(
29
            'test.Dontdrinkandroot\GitkiBundle\Service\FileSystem\FileSystemService'
30
        );
31
        /** @var WikiService $wikiService */
32
        $wikiService = $this->getContainer()->get('test.Dontdrinkandroot\GitkiBundle\Service\Wiki\WikiService');
33
        $wikiService->createFolder($directoryPath);
34
        $this->assertFileExists(
35
            $directoryPath->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
36
        );
37
38
        $this->login($this->getUser(Users::COMMITTER));
39
        $this->client->request('GET', '/browse/testdirectory/?action=remove');
40
        $this->assertStatusCode(302, $this->client);
41
        $this->assertEquals('/browse/', $this->client->getResponse()->headers->get('Location'));
42
43
        $this->assertFileNotExists(
44
            $directoryPath->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
45
        );
46
    }
47
48
    public function testRemoveNonEmptyDirectoryTest()
49
    {
50
        /** @var FileSystemService $fileSystemService */
51
        $fileSystemService = $this->getContainer()->get(
52
            'test.Dontdrinkandroot\GitkiBundle\Service\FileSystem\FileSystemService'
53
        );
54
55
        $exampleFile = FilePath::parse('/examples/toc-example.md');
56
        $exampleDirectory = DirectoryPath::parse('/examples/');
57
58
        $this->assertFileExists(
59
            $exampleFile->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
60
        );
61
        $this->assertFileExists(
62
            $exampleDirectory->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
63
        );
64
65
        $this->logIn($this->getUser(Users::COMMITTER));
66
        $crawler = $this->client->request('GET', '/browse/examples/?action=remove');
67
        $this->assertStatusCode(200, $this->client);
68
        $submitButton = $crawler->selectButton('Remove all files');
69
        $form = $submitButton->form();
70
        $this->client->submit(
71
            $form,
72
            [
73
                'form[commitMessage]' => 'A test commit message'
74
            ]
75
        );
76
        $this->assertStatusCode(302, $this->client);
77
        $this->assertEquals('/browse/', $this->client->getResponse()->headers->get('Location'));
78
79
        $this->assertFileNotExists(
80
            $exampleFile->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
81
        );
82
        $this->assertFileNotExists(
83
            $exampleDirectory->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
84
        );
85
    }
86
87
    public function testRemoveNonEmptyDirectoryWithLockTest()
88
    {
89
        $exampleFile = FilePath::parse('/examples/toc-example.md');
90
        $exampleDirectory = DirectoryPath::parse('/examples/');
91
92
        /** @var FileSystemService $fileSystemService */
93
        $fileSystemService = $this->getContainer()->get(
94
            'test.Dontdrinkandroot\GitkiBundle\Service\FileSystem\FileSystemService'
95
        );
96
        /** @var WikiService $wikiService */
97
        $wikiService = $this->getContainer()->get('test.Dontdrinkandroot\GitkiBundle\Service\Wiki\WikiService');
98
        $wikiService->createLock($this->getUser(Users::ADMIN), $exampleFile);
99
100
        $this->assertFileExists(
101
            $exampleFile->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
102
        );
103
        $this->assertFileExists(
104
            $exampleDirectory->prepend($fileSystemService->getBasePath())->toAbsoluteFileSystemString()
105
        );
106
107
        $this->logIn($this->getUser(Users::COMMITTER));
108
        $crawler = $this->client->request('GET', '/browse/examples/?action=remove');
109
        $this->assertStatusCode(200, $this->client);
110
        $submitButton = $crawler->selectButton('Remove all files');
111
        $form = $submitButton->form();
112
        $this->client->submit(
113
            $form,
114
            [
115
                'form[commitMessage]' => 'A test commit message'
116
            ]
117
        );
118
        $this->assertStatusCode(500, $this->client);
119
    }
120
}
121