Completed
Push — theme-bundle ( bce4cb...aad440 )
by Kamil
23:47 queued 05:45
created

AssetTest::testAssets()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 27
rs 8.5806
cc 4
eloc 15
nc 6
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Tests\Functional;
13
14
use Sylius\Bundle\ThemeBundle\Asset\Installer\AssetsInstallerInterface;
15
16
/**
17
 * @author Kamil Kokot <[email protected]>
18
 */
19
class AssetTest extends ThemeBundleTestCase
20
{
21
    /**
22
     * @dataProvider getSymlinkMasks
23
     *
24
     * @param int $symlinkMask
25
     */
26
    public function testAssets($symlinkMask)
27
    {
28
        $webDirectory = $this->getTmpDirPath(self::TEST_CASE) . '/web';
29
        if (!is_dir($webDirectory)) {
30
            mkdir($webDirectory, 0777, true);
31
        }
32
33
        chdir($webDirectory);
34
35
        $client = $this->getClient();
36
37
        $client->getContainer()->get('sylius.theme.asset.assets_installer')->installAssets($webDirectory, $symlinkMask);
38
39
        $crawler = $client->request('GET', '/template/:Asset:assetsTest.txt.twig');
40
        $lines = explode("\n", $crawler->text());
41
        foreach ($lines as $line) {
42
            if (empty($line)) {
43
                continue;
44
            }
45
46
            list($expectedText, $assetFile) = explode(": ", $line);
47
48
            $contents = file_get_contents($webDirectory . $assetFile);
49
50
            $this->assertEquals($expectedText, trim($contents));
51
        }
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getSymlinkMasks()
58
    {
59
        return [
60
            [AssetsInstallerInterface::RELATIVE_SYMLINK],
61
            [AssetsInstallerInterface::SYMLINK],
62
            [AssetsInstallerInterface::HARD_COPY],
63
        ];
64
    }
65
}
66