Completed
Push — master ( af9685...cffdd8 )
by Philip
03:38
created

testRemoveEmptyDirectoryTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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