You are here

public function BreakpointGroupAPITest::testConfigName in Breakpoints 8

Test Breakpoint::buildConfigName().

File

lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php, line 35
Definition of Drupal\breakpoint\Tests\BreakpointGroupAPITest.

Class

BreakpointGroupAPITest
Tests for general breakpoint group API functions.

Namespace

Drupal\breakpoint\Tests

Code

public function testConfigName() {

  // Try an invalid sourceType.
  $breakpoint_group = entity_create('breakpoint_group', array(
    'label' => drupal_strtolower($this
      ->randomName()),
    'source' => 'custom_module',
    'sourceType' => 'oops',
  ));
  $exception = FALSE;
  try {
    $breakpoint_group
      ->save();
  } catch (InvalidBreakpointSourceTypeException $e) {
    $exception = TRUE;
  }
  $this
    ->assertTrue($exception, t('An exception is thrown when an invalid sourceType is entered.'));

  // Try an invalid source.
  $breakpoint_group->id = '';
  $breakpoint_group->sourceType = Breakpoint::SOURCE_TYPE_CUSTOM;
  $breakpoint_group->source = 'custom*_module source';
  $exception = FALSE;
  try {
    $breakpoint_group
      ->save();
  } catch (InvalidBreakpointSourceException $e) {
    $exception = TRUE;
  }
  $this
    ->assertTrue($exception, t('An exception is thrown when an invalid source is entered.'));

  // Try a valid breakpoint_group.
  $breakpoint_group->id = 'test';
  $breakpoint_group->source = 'custom_module_source';
  $exception = FALSE;
  try {
    $breakpoint_group
      ->save();
  } catch (\Exception $e) {
    $exception = TRUE;
  }
  $this
    ->assertFalse($exception, t('No exception is thrown when a valid data is passed.'));
}