|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maestriam\Samurai\Tests\Unit\Entities\Theme; |
|
4
|
|
|
|
|
5
|
|
|
use Maestriam\Samurai\Foundation\ConfigKeeper; |
|
6
|
|
|
use Maestriam\Samurai\Foundation\EnvHandler; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Testes de funcionalidades básicas apresentadas no README.md |
|
10
|
|
|
*/ |
|
11
|
|
|
class ThemeURLTest extends ThemeTestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testThemeUrl() |
|
14
|
|
|
{ |
|
15
|
|
|
$name = 'bands/edguy'; |
|
16
|
|
|
$theme = $this->theme($name)->findOrCreate(); |
|
17
|
|
|
|
|
18
|
|
|
$expected = $this->getUrl($name); |
|
19
|
|
|
$actual = $theme->url(); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertEquals($expected, $actual); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testUrlFileFromTheme() |
|
25
|
|
|
{ |
|
26
|
|
|
$name = 'bands/edguy'; |
|
27
|
|
|
$file = 'js/index.js'; |
|
28
|
|
|
$theme = $this->theme($name)->findOrCreate(); |
|
29
|
|
|
|
|
30
|
|
|
$expected = $this->getUrl($name, $file); |
|
31
|
|
|
$actual = $theme->url($file); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertEquals($expected, $actual); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getUrl($theme, $file = null) |
|
37
|
|
|
{ |
|
38
|
|
|
$public = $this->getPublishable(); |
|
39
|
|
|
$domain = $this->registerDomain(); |
|
40
|
|
|
|
|
41
|
|
|
$file = '/' . $file ?? ''; |
|
42
|
|
|
|
|
43
|
|
|
return sprintf("%s/%s/%s%s", $domain, $public, $theme, $file); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function registerDomain() : string |
|
47
|
|
|
{ |
|
48
|
|
|
$env = new EnvHandler(); |
|
49
|
|
|
|
|
50
|
|
|
$domain = 'http://localhost:8000'; |
|
51
|
|
|
|
|
52
|
|
|
$env->set('APP_URL', $domain); |
|
53
|
|
|
|
|
54
|
|
|
return $domain; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function getPublishable() : string |
|
58
|
|
|
{ |
|
59
|
|
|
$config = new ConfigKeeper(); |
|
60
|
|
|
|
|
61
|
|
|
return $config->publishable(); |
|
62
|
|
|
} |
|
63
|
|
|
} |