You are here

public function XlsTest::testEncodeMetaData in Excel Serialization 8

Tests metadata.

@covers ::encode

File

tests/src/Unit/Encoder/XlsTest.php, line 59

Class

XlsTest
Tests the XLS encoder.

Namespace

Drupal\Tests\xls_serialization\Unit\Encoder

Code

public function testEncodeMetaData() {

  // Test metadata.
  $style_plugin = new \stdClass();
  $style_plugin->options = [
    'xls_settings' => [
      'xls_format' => 'Excel2007',
      'metadata' => [
        'creator' => 'J Author',
        'last_modified_by' => 'That one guy, down the hall?',
        'created' => 1320998400,
        'modified' => 1355299200,
        'title' => 'A fantastic title. The best title.',
        'description' => 'Such a great description. Everybody is saying.',
        'subject' => 'This spreadsheet is about numbers.',
        'keywords' => 'testing xls spreadsheets',
        'category' => 'test category',
        'manager' => 'J Q Manager',
        'company' => 'Drupal',
        'custom_properties' => [
          'foo' => 'bar',
          'biz' => [
            12345.12,
            'f',
          ],
          'baz' => [
            1320998400,
            'd',
          ],
        ],
      ],
    ],
  ];
  $context['views_style_plugin'] = $style_plugin;
  $encoder = new Xls();
  $encoded = $encoder
    ->encode([], 'xlsx', $context);
  $file = $this
    ->loadXlsFile($encoded, 'xlsx');
  $metadata = $style_plugin->options['xls_settings']['metadata'];
  $properties = $file
    ->getProperties();
  $this
    ->assertEquals($metadata['creator'], $properties
    ->getCreator());
  $this
    ->assertEquals($metadata['last_modified_by'], $properties
    ->getLastModifiedBy());
  $this
    ->assertEquals($metadata['created'], $properties
    ->getCreated());
  $this
    ->assertEquals($metadata['modified'], $properties
    ->getModified());
  $this
    ->assertEquals($metadata['title'], $properties
    ->getTitle());
  $this
    ->assertEquals($metadata['description'], $properties
    ->getDescription());
  $this
    ->assertEquals($metadata['subject'], $properties
    ->getSubject());
  $this
    ->assertEquals($metadata['keywords'], $properties
    ->getKeywords());
  $this
    ->assertEquals($metadata['category'], $properties
    ->getCategory());
  $this
    ->assertEquals($metadata['manager'], $properties
    ->getManager());
  $this
    ->assertEquals($metadata['company'], $properties
    ->getCompany());

  // Verify custom properties.
  $this
    ->assertEquals('bar', $properties
    ->getCustomPropertyValue('foo'));
  $this
    ->assertEquals('12345.12', $properties
    ->getCustomPropertyValue('biz'));
  $this
    ->assertEquals('1320998400', $properties
    ->getCustomPropertyValue('baz'));
}