Newer
Older
Angie Byron
committed
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
<?php
/**
* @file
* Definition of Drupal\breakpoint\Tests\BreakpointAPITest.
*/
namespace Drupal\breakpoint\Tests;
use Drupal\breakpoint\Tests\BreakpointsTestBase;
use Drupal\breakpoint\Breakpoint;
use Drupal\breakpoint\InvalidBreakpointNameException;
use Drupal\breakpoint\InvalidBreakpointSourceException;
use Drupal\breakpoint\InvalidBreakpointSourceTypeException;
/**
* Tests for general breakpoint API functions.
*/
class BreakpointAPITest extends BreakpointTestBase {
public static function getInfo() {
return array(
'name' => 'Breakpoint general API functions',
'description' => 'Test general API functions of the breakpoint module.',
'group' => 'Breakpoint',
);
}
/**
* Test Breakpoint::buildConfigName().
*/
public function testConfigName() {
// Try an invalid sourceType.
$breakpoint = entity_create('breakpoint', array(
'label' => drupal_strtolower($this->randomName()),
'source' => 'custom_module',
'sourceType' => 'oops',
));
$exception = FALSE;
try {
$breakpoint->save();
}
catch (InvalidBreakpointSourceTypeException $e) {
$exception = TRUE;
}
$this->assertTrue($exception, 'breakpoint_config_name: An exception is thrown when an invalid sourceType is entered.');
// Try an invalid source.
$breakpoint->id = '';
$breakpoint->sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED;
$breakpoint->source = 'custom*_module source';
$exception = FALSE;
try {
$breakpoint->save();
}
catch (InvalidBreakpointSourceException $e) {
$exception = TRUE;
}
$this->assertTrue($exception, 'breakpoint_config_name: An exception is thrown when an invalid source is entered.');
// Try an invalid name (make sure there is at least once capital letter).
$breakpoint->id = '';
$breakpoint->source = 'custom_module';
$breakpoint->name = drupal_ucfirst($this->randomName());
$exception = FALSE;
try {
$breakpoint->save();
}
catch (InvalidBreakpointNameException $e) {
$exception = TRUE;
}
$this->assertTrue($exception, 'breakpoint_config_name: An exception is thrown when an invalid name is entered.');
// Try a valid breakpoint.
$breakpoint->id = '';
$breakpoint->name = drupal_strtolower($this->randomName());
$breakpoint->mediaQuery = 'all';
$exception = FALSE;
try {
$breakpoint->save();
}
catch (\Exception $e) {
$exception = TRUE;
}
$this->assertFalse($exception, 'breakpoint_config_name: No exception is thrown when a valid breakpoint is passed.');
$this->assertEqual($breakpoint->id(), Breakpoint::SOURCE_TYPE_USER_DEFINED . '.custom_module.' . $breakpoint->name, 'breakpoint_config_name: A id is set when a valid breakpoint is passed.');
}
}