Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / file_mdm / file_mdm_font / tests / src / Kernel / FileMetadataFontTest.php
1 <?php
2
3 namespace Drupal\Tests\file_mdm_font\Kernel;
4
5 use Drupal\file_mdm\FileMetadataInterface;
6 use Drupal\Tests\file_mdm\Kernel\FileMetadataManagerTestBase;
7
8 /**
9  * Tests that the file metadata 'font' plugin works properly.
10  *
11  * @group File Metadata
12  */
13 class FileMetadataFontTest extends FileMetadataManagerTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = [
21     'system',
22     'simpletest',
23     'file_mdm',
24     'file_mdm_font',
25     'file_test',
26     'image_effects',
27   ];
28
29   /**
30    * {@inheritdoc}
31    */
32   public function setUp() {
33     parent::setUp();
34     $this->installConfig(['file_mdm_font']);
35   }
36
37   /**
38    * Test 'font' plugin.
39    */
40   public function testFontPlugin() {
41     // The font files that will be tested.
42     $font_files = [
43       [
44         'uri' => drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf',
45         'count_keys' => 15,
46         'test_keys' => [
47           ['Version', 'Version 5.3.0 ; ttfautohint (v0.9)'],
48           ['version', 'Version 5.3.0 ; ttfautohint (v0.9)'],
49           ['VeRsIoN', 'Version 5.3.0 ; ttfautohint (v0.9)'],
50           ['FontWeight', 400],
51         ],
52       ],
53       [
54         'uri' => drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinBiolinum_Kah.ttf',
55         'count_keys' => 15,
56         'test_keys' => [
57           ['FullName', 'Linux Biolinum Keyboard'],
58           ['fullname', 'Linux Biolinum Keyboard'],
59           ['fUlLnAmE', 'Linux Biolinum Keyboard'],
60         ],
61       ],
62     ];
63
64     $fmdm = $this->container->get('file_metadata_manager');
65
66     // Walk through test files.
67     foreach ($font_files as $font_file) {
68       $file_metadata = $fmdm->uri($font_file['uri']);
69       if (!$file_metadata) {
70         $this->fail("File not found: {$font_file['uri']}");
71         continue;
72       }
73       $this->assertEqual($font_file['count_keys'], $this->countMetadataKeys($file_metadata, 'font'));
74       $this->assertIdentical(FileMetadataInterface::LOADED_FROM_FILE, $file_metadata->isMetadataLoaded('font'));
75       foreach ($font_file['test_keys'] as $test) {
76         $this->assertEqual($test[1], $file_metadata->getMetadata('font', $test[0]));
77       }
78     }
79   }
80
81   /**
82    * Test 'font' plugin supported keys.
83    */
84   public function testSupportedKeys() {
85     $expected_keys = [
86       'FontType',
87       'FontWeight',
88       'Copyright',
89       'FontName',
90       'FontSubfamily',
91       'UniqueID',
92       'FullName',
93       'Version',
94       'PostScriptName',
95       'Trademark',
96       'Manufacturer',
97       'Designer',
98       'Description',
99       'FontVendorURL',
100       'FontDesignerURL',
101       'LicenseDescription',
102       'LicenseURL',
103       'PreferredFamily',
104       'PreferredSubfamily',
105       'CompatibleFullName',
106       'SampleText',
107     ];
108
109     $fmdm = $this->container->get('file_metadata_manager');
110     $file_md = $fmdm->uri(drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf');
111     $this->assertEqual($expected_keys, $file_md->getSupportedKeys('font'));
112   }
113
114 }