Newer
Older
<?php
/**
* @file
* Contains \Drupal\breakpoint\Tests\BreakpointGroupConfigEntityUnitTest.
*/
namespace Drupal\breakpoint\Tests;
use Drupal\breakpoint\Entity\Breakpoint;
Angie Byron
committed
use Drupal\breakpoint\Entity\BreakpointGroup;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\breakpoint\Entity\BreakpointGroup
* @group breakpoint
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
*/
class BreakpointGroupConfigEntityUnitTest extends UnitTestCase {
/**
* The entity under test.
*
* @var \Drupal\breakpoint\Entity\BreakpointGroup|\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}
*/
Alex Pott
committed
protected function setUp() {
Alex Pott
committed
$this->entityTypeId = $this->randomMachineName();
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
$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);
}
/**
* Sets up the entity to test.
*/
public function setUpEntity($values) {
// Mocking the entity under test because the class contains calls to
// procedural code.
$this->entity = $this->getMockBuilder('\Drupal\breakpoint\Entity\BreakpointGroup')
->setConstructorArgs(array($values, $this->entityTypeId))
->setMethods(array('getBreakpoints'))
->getMock();
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependenciesModule() {
$this->setUpEntity(
array(
Angie Byron
committed
'name' => 'test',
'source' => 'test_module',
'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
)
);
$breakpoint = $this->getMock('\Drupal\breakpoint\BreakpointInterface');
$breakpoint->expects($this->once())
->method('getConfigDependencyName')
->will($this->returnValue('breakpoint.breakpoint.test'));
$this->entity->expects($this->once())
->method('getBreakpoints')
->will($this->returnValue(array($breakpoint)));
$dependencies = $this->entity->calculateDependencies();
$this->assertArrayNotHasKey('theme', $dependencies);
$this->assertContains('test_module', $dependencies['module']);
$this->assertContains('breakpoint.breakpoint.test', $dependencies['entity']);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependenciesTheme() {
$this->setUpEntity(
array(
Angie Byron
committed
'name' => 'test',
'source' => 'test_theme',
'sourceType' => Breakpoint::SOURCE_TYPE_THEME,
)
);
$breakpoint = $this->getMockBuilder('\Drupal\breakpoint\Entity\Breakpoint')
->disableOriginalConstructor()->getMock();
$breakpoint->expects($this->once())
->method('getConfigDependencyName')
->will($this->returnValue('breakpoint.breakpoint.test'));
$this->entity->expects($this->once())
->method('getBreakpoints')
->will($this->returnValue(array($breakpoint)));
$dependencies = $this->entity->calculateDependencies();
$this->assertArrayNotHasKey('module', $dependencies);
$this->assertContains('test_theme', $dependencies['theme']);
$this->assertContains('breakpoint.breakpoint.test', $dependencies['entity']);
}
Angie Byron
committed
/**
* @expectedException \Drupal\breakpoint\InvalidBreakpointNameException
*/
public function testNameException () {
new BreakpointGroup(array(
Alex Pott
committed
'label' => $this->randomMachineName(),
Angie Byron
committed
'source' => 'custom_module',
'sourceType' => 'oops',
));
}