summaryrefslogtreecommitdiffstats
path: root/core/modules/breakpoint/tests/src/BreakpointTest.php
blob: a2b62ea8e85a57fb3d078758c0f14ffddc03e673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php

/**
 * @file
 * Contains \Drupal\breakpoint\Tests\BreakpointTest.
 */

namespace Drupal\breakpoint\Tests;

use Drupal\breakpoint\Breakpoint;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\breakpoint\Breakpoint
 * @group Breakpoint
 */
class BreakpointTest extends UnitTestCase {

  /**
   * The used plugin ID.
   *
   * @var string
   */
  protected $pluginId = 'breakpoint';

  /**
   * The used plugin definition.
   *
   * @var array
   */
  protected $pluginDefinition = array(
    'id' => 'breakpoint',
  );

  /**
   * The breakpoint under test.
   *
   * @var \Drupal\breakpoint\Breakpoint
   */
  protected $breakpoint;

  /**
   * The mocked translator.
   *
   * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $stringTranslation;

  protected function setUp() {
    parent::setUp();

    $this->stringTranslation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
  }

  /**
   * Sets up the breakpoint defaults.
   */
  protected function setupBreakpoint() {
    $this->breakpoint = new Breakpoint(array(), $this->pluginId, $this->pluginDefinition);
    $this->breakpoint->setStringTranslation($this->stringTranslation);
  }

  /**
   * @covers ::getLabel
   */
  public function testGetLabel() {
    $this->pluginDefinition['label'] = 'Test label';
    $this->stringTranslation->expects($this->once())
      ->method('translate')
      ->with($this->pluginDefinition['label'], array(), array('context' => 'breakpoint'))
      ->will($this->returnValue('Test label translated'));
    $this->setupBreakpoint();
    $this->assertEquals('Test label translated', $this->breakpoint->getLabel());
  }

  /**
   * @covers ::getWeight
   */
  public function testGetWeight() {
    $this->pluginDefinition['weight'] = '4';
    $this->setupBreakpoint();
    // Assert that the type returned in an integer.
    $this->assertSame(4, $this->breakpoint->getWeight());
  }

  /**
   * @covers ::getMediaQuery
   */
  public function testGetMediaQuery() {
    $this->pluginDefinition['mediaQuery'] = 'only screen and (min-width: 3456px)';
    $this->setupBreakpoint();
    $this->assertEquals('only screen and (min-width: 3456px)', $this->breakpoint->getMediaQuery());
  }

  /**
   * @covers ::getMultipliers
   */
  public function testGetMultipliers() {
    $this->pluginDefinition['multipliers'] = array('1x', '2x');
    $this->setupBreakpoint();
    $this->assertSame(array('1x', '2x'), $this->breakpoint->getMultipliers());
  }

  /**
   * @covers ::getProvider
   */
  public function testGetProvider() {
    $this->pluginDefinition['provider'] = 'Breakpoint';
    $this->setupBreakpoint();
    $this->assertEquals('Breakpoint', $this->breakpoint->getProvider());
  }

  /**
   * @covers ::getGroup
   */
  public function testGetGroup() {
    $this->pluginDefinition['group'] = 'Breakpoint';
    $this->setupBreakpoint();
    $this->assertEquals('Breakpoint', $this->breakpoint->getGroup());
  }

}