ee41968a5a4629e08dc66f1e8a9b04888ef903cd
[yaffs-website] / web / core / modules / system / tests / src / Functional / Theme / ThemeInfoTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Theme;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests processing of theme .info.yml properties.
9  *
10  * @group Theme
11  */
12 class ThemeInfoTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['theme_test'];
20
21   /**
22    * The theme handler used in this test for enabling themes.
23    *
24    * @var \Drupal\Core\Extension\ThemeHandler
25    */
26   protected $themeHandler;
27
28   /**
29    * The theme manager used in this test.
30    *
31    * @var \Drupal\Core\Theme\ThemeManagerInterface
32    */
33   protected $themeManager;
34
35   /**
36    * The state service used in this test.
37    *
38    * @var \Drupal\Core\State\StateInterface
39    */
40   protected $state;
41
42   /**
43    * {@inheritdoc}
44    */
45   protected function setUp() {
46     parent::setUp();
47
48     $this->themeHandler = $this->container->get('theme_handler');
49     $this->themeManager = $this->container->get('theme.manager');
50     $this->state = $this->container->get('state');
51   }
52
53   /**
54    * Tests stylesheets-remove.
55    */
56   public function testStylesheets() {
57     $this->themeHandler->install(['test_basetheme', 'test_subtheme']);
58     $this->config('system.theme')
59       ->set('default', 'test_subtheme')
60       ->save();
61
62     $base = drupal_get_path('theme', 'test_basetheme');
63     $sub = drupal_get_path('theme', 'test_subtheme') . '/css';
64
65     // All removals are expected to be based on a file's path and name and
66     // should work nevertheless.
67     $this->drupalGet('theme-test/info/stylesheets');
68
69     $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href'  => "$base/base-add.css"])), "$base/base-add.css found");
70     $this->assertIdentical(0, count($this->xpath('//link[contains(@href, :href)]', [':href'  => "base-remove.css"])), "base-remove.css not found");
71
72     $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href'  => "$sub/sub-add.css"])), "$sub/sub-add.css found");
73     $this->assertIdentical(0, count($this->xpath('//link[contains(@href, :href)]', [':href'  => "sub-remove.css"])), "sub-remove.css not found");
74     $this->assertIdentical(0, count($this->xpath('//link[contains(@href, :href)]', [':href' => "base-add.sub-remove.css"])), "base-add.sub-remove.css not found");
75
76     // Verify that CSS files with the same name are loaded from both the base theme and subtheme.
77     $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href' => "$base/samename.css"])), "$base/samename.css found");
78     $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href' => "$sub/samename.css"])), "$sub/samename.css found");
79
80   }
81
82   /**
83    * Tests that changes to the info file are picked up.
84    */
85   public function testChanges() {
86     $this->themeHandler->install(['test_theme']);
87     $this->config('system.theme')->set('default', 'test_theme')->save();
88     $this->themeManager->resetActiveTheme();
89
90     $active_theme = $this->themeManager->getActiveTheme();
91     // Make sure we are not testing the wrong theme.
92     $this->assertEqual('test_theme', $active_theme->getName());
93     $this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling'], $active_theme->getLibraries());
94
95     // @see theme_test_system_info_alter()
96     $this->state->set('theme_test.modify_info_files', TRUE);
97     drupal_flush_all_caches();
98     $active_theme = $this->themeManager->getActiveTheme();
99     $this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries());
100   }
101
102 }