fb755a402d77e906cad6cce600020539dc3fa966
[yaffs-website] / web / modules / contrib / fontyourface / tests / src / Functional / FontYourFaceFontDisplayTest.php
1 <?php
2
3 namespace Drupal\Tests\fontyourface\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9  * Tests that font displays show css.
10  *
11  * @group fontyourface
12  */
13 class FontYourFaceFontDisplayTest extends WebTestBase {
14
15   /**
16    * Modules to install.
17    *
18    * @var array
19    */
20   public static $modules = ['views', 'fontyourface', 'websafe_fonts_test'];
21
22   /**
23    * A test user with permission to access the @font-your-face sections.
24    *
25    * @var \Drupal\user\UserInterface
26    */
27   protected $adminUser;
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function setUp() {
33     parent::setUp();
34     // Create and log in an administrative user.
35     $this->adminUser = $this->drupalCreateUser([
36       'administer font entities',
37     ]);
38     $this->drupalLogin($this->adminUser);
39
40     // Set up default themes.
41     \Drupal::service('theme_handler')->install(['bartik', 'seven']);
42     $this->config('system.theme')
43       ->set('default', 'bartik')
44       ->set('admin', 'seven')
45       ->save();
46
47     // Enable Arial font.
48     $this->drupalPostForm(Url::fromRoute('font.settings'), ['load_all_enabled_fonts' => FALSE], t('Save configuration'));
49     $this->drupalPostForm(Url::fromRoute('font.settings'), [], t('Import from websafe_fonts_test'));
50   }
51
52   /**
53    * Tests font not displayed even when Arial is loaded.
54    */
55   public function testFontNotDisplayed() {
56     $this->drupalGet(url::fromRoute('entity.font.activate', ['font' => 1, 'js' => 'nojs']));
57     $this->resetAll();
58     // Assert no fonts load to start.
59     $this->drupalGet('/node');
60     $this->assertNoRaw('<meta name="Websafe Font" content="Arial" />');
61   }
62
63   /**
64    * Tests font displayed once added in FontDisplay.
65    */
66   public function testFontDisplayedViaFontDisplayRule() {
67     $this->drupalGet(url::fromRoute('entity.font.activate', ['font' => 1, 'js' => 'nojs']));
68
69     $edit = [
70       'label' => 'Headers',
71       'id' => 'headers',
72       'font_url' => 'https://en.wikipedia.org/wiki/Arial',
73       'fallback' => '',
74       'preset_selectors' => '.fontyourface h1, .fontyourface h2, .fontyourface h3, .fontyourface h4, .fontyourface h5, .fontyourface h6',
75       'selectors' => '.fontyourface h1, .fontyourface h2, .fontyourface h3, .fontyourface h4, .fontyourface h5, .fontyourface h6',
76       'theme' => 'bartik',
77     ];
78     $this->drupalPostForm(Url::fromRoute('entity.font_display.add_form'), $edit, 'Save');
79     $this->drupalGet(Url::fromRoute('entity.font_display.collection'));
80     $this->resetAll();
81
82     // Assert Arial loads in general bartik section.
83     $this->drupalGet('/node');
84     $this->assertRaw('<meta name="Websafe Font" content="Arial" />');
85     $this->assertRaw("fontyourface/font_display/headers.css");
86   }
87
88 }