summaryrefslogtreecommitdiffstats
path: root/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php
blob: 646100ac87f1aba2ca784e49f708f79fbd7e568d (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
<?php
/**
 * @file
 * Definition of Drupal\breakpoint\Tests\BreakpointCRUDTest.
 */

namespace Drupal\breakpoint\Tests;

use Drupal\breakpoint\Tests\BreakpointTestBase;
use Drupal\breakpoint\Entity\Breakpoint;

/**
 * Tests for breakpoint CRUD operations.
 */
class BreakpointCRUDTest extends BreakpointTestBase {

  public static function getInfo() {
    return array(
      'name' => 'Breakpoint CRUD operations',
      'description' => 'Test creation, loading, updating, deleting of breakpoints.',
      'group' => 'Breakpoint',
    );
  }

  /**
   * Test CRUD operations for breakpoints.
   */
  public function testBreakpointCRUD() {
    // Add a breakpoint with minimum data only.
    $label = $this->randomName();
    $breakpoint = entity_create('breakpoint', array(
      'label' => $label,
      'mediaQuery' => '(min-width: 600px)',
      'name' => drupal_strtolower($label),
    ));
    $breakpoint->save();

    $this->verifyBreakpoint($breakpoint);

    // Test breakpoint_load_all
    $all_breakpoints = entity_load_multiple('breakpoint');
    $config_name = $breakpoint->id();
    $this->assertTrue(isset($all_breakpoints[$config_name]), 'breakpoint_load_all: New breakpoint is present when loading all breakpoints.');
    $this->verifyBreakpoint($breakpoint, $all_breakpoints[$config_name]);

    // Update the breakpoint.
    $breakpoint->weight = 1;
    $breakpoint->multipliers['2x'] = '2x';
    $breakpoint->save();
    $this->verifyBreakpoint($breakpoint);

    // Delete the breakpoint.
    $breakpoint->delete();
    $this->assertFalse(breakpoint_load($config_name), 'breakpoint_load: Loading a deleted breakpoint returns false.', 'Breakpoints API');
  }
}