|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author Aaron Francis <[email protected]|https://twitter.com/aarondfrancis> |
| 4 | + */ |
| 5 | + |
| 6 | +namespace Torchlight\Tests; |
| 7 | + |
| 8 | +use Illuminate\Support\Facades\Route; |
| 9 | +use Illuminate\Support\Facades\View; |
| 10 | +use Torchlight\Middleware\RenderTorchlight; |
| 11 | + |
| 12 | +class DualThemeTest extends BaseTest |
| 13 | +{ |
| 14 | + public function getEnvironmentSetUp($app) |
| 15 | + { |
| 16 | + config()->set('torchlight.blade_components', true); |
| 17 | + config()->set('torchlight.token', 'token'); |
| 18 | + config()->set('torchlight.theme', [ |
| 19 | + 'github-dark', |
| 20 | + 'github-light' |
| 21 | + ]); |
| 22 | + } |
| 23 | + |
| 24 | + protected function getView($view) |
| 25 | + { |
| 26 | + // This helps when testing multiple Laravel versions locally. |
| 27 | + $this->artisan('view:clear'); |
| 28 | + |
| 29 | + Route::get('/torchlight', function () use ($view) { |
| 30 | + return View::file(__DIR__ . '/Support/' . $view); |
| 31 | + })->middleware(RenderTorchlight::class); |
| 32 | + |
| 33 | + return $this->call('GET', 'torchlight'); |
| 34 | + } |
| 35 | + |
| 36 | + /** @test */ |
| 37 | + public function multiple_themes_with_comma() |
| 38 | + { |
| 39 | + config()->set('torchlight.theme', [ |
| 40 | + 'github-dark,github-light' |
| 41 | + ]); |
| 42 | + |
| 43 | + $this->assertDarkLight('github-dark', 'github-light'); |
| 44 | + } |
| 45 | + |
| 46 | + /** @test */ |
| 47 | + public function multiple_themes_no_labels() |
| 48 | + { |
| 49 | + config()->set('torchlight.theme', [ |
| 50 | + 'github-dark', |
| 51 | + 'github-light' |
| 52 | + ]); |
| 53 | + |
| 54 | + $this->assertDarkLight('github-dark', 'github-light'); |
| 55 | + } |
| 56 | + |
| 57 | + /** @test */ |
| 58 | + public function multiple_themes_with_labels() |
| 59 | + { |
| 60 | + config()->set('torchlight.theme', [ |
| 61 | + 'dark' => 'github-dark', |
| 62 | + 'light' => 'github-light' |
| 63 | + ]); |
| 64 | + |
| 65 | + $this->assertDarkLight('dark:github-dark', 'light:github-light'); |
| 66 | + } |
| 67 | + |
| 68 | + protected function assertDarkLight($theme1, $theme2) |
| 69 | + { |
| 70 | + $this->fakeSuccessfulResponse('component', [ |
| 71 | + 'classes' => 'torchlight1', |
| 72 | + 'styles' => 'background-color: #111111;', |
| 73 | + 'highlighted' => 'response 1', |
| 74 | + ]); |
| 75 | + |
| 76 | + $this->fakeSuccessfulResponse('component_clone_0', [ |
| 77 | + 'classes' => 'torchlight2', |
| 78 | + 'styles' => 'background-color: #222222;', |
| 79 | + 'highlighted' => 'response 2', |
| 80 | + ]); |
| 81 | + |
| 82 | + $response = $this->getView('simple-php-hello-world.blade.php'); |
| 83 | + |
| 84 | + $this->assertEquals( |
| 85 | + "<pre><code data-theme=\"{$theme1}\" data-lang=\"php\" class=\"torchlight1\" style=\"background-color: #111111;\">response 1</code><code data-theme=\"{$theme2}\" data-lang=\"php\" class=\"torchlight2\" style=\"background-color: #222222;\">response 2</code></pre>", |
| 86 | + $response->content() |
| 87 | + ); |
| 88 | + } |
| 89 | +} |
0 commit comments