summaryrefslogtreecommitdiffstats
path: root/core/modules/breakpoint/tests/src/BreakpointConfigEntityUnitTest.php
blob: 3b1080162a5e06dd09be7923d07b1dce42d08627 (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
123
<?php

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

namespace Drupal\breakpoint\Tests;

use Drupal\breakpoint\Entity\Breakpoint;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;

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

  /**
   * The entity under test.
   *
   * @var \Drupal\breakpoint\Entity\Breakpoint|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $entity;

  /**
   * The entity type used for testing.
   *
   * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $entityType;

  /**
   * The entity manager used for testing.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $entityManager;

  /**
   * The ID of the type of the entity under test.
   *
   * @var string
   */
  protected $entityTypeId;

  /**
   * The UUID generator used for testing.
   *
   * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $uuid;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    $this->entityTypeId = $this->randomMachineName();

    $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
    $this->entityType->expects($this->any())
      ->method('getProvider')
      ->will($this->returnValue('breakpoint'));

    $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
    $this->entityManager->expects($this->any())
      ->method('getDefinition')
      ->with($this->entityTypeId)
      ->will($this->returnValue($this->entityType));

    $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');

    $container = new ContainerBuilder();
    $container->set('entity.manager', $this->entityManager);
    $container->set('uuid', $this->uuid);
    \Drupal::setContainer($container);
  }

  /**
   * @covers ::calculateDependencies
   */
  public function testCalculateDependenciesModule() {
    $values = array(
      'name' => 'test',
      'source' => 'test_module',
      'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
    );
    $entity = new Breakpoint($values, $this->entityTypeId);

    $dependencies = $entity->calculateDependencies();
    $this->assertArrayNotHasKey('theme', $dependencies);
    $this->assertContains('test_module', $dependencies['module']);
  }

  /**
   * @covers ::calculateDependencies
   */
  public function testCalculateDependenciesTheme() {
    $values = array(
      'name' => 'test',
      'source' => 'test_theme',
      'sourceType' => Breakpoint::SOURCE_TYPE_THEME,
    );
    $entity = new Breakpoint($values, $this->entityTypeId);

    $dependencies = $entity->calculateDependencies();
    $this->assertArrayNotHasKey('module', $dependencies);
    $this->assertContains('test_theme', $dependencies['theme']);
  }

  /**
   * @expectedException \Drupal\breakpoint\InvalidBreakpointNameException
   */
  public function testNameException () {
    new Breakpoint(array(
      'label' => $this->randomMachineName(),
      'source' => 'custom_module',
      'sourceType' => 'oops',
    ));
  }

}