/** * @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']); }
/** * Verify that a breakpoint is properly stored. */ public function verifyBreakpoint(Breakpoint $breakpoint, Breakpoint $compare_breakpoint = NULL) { $properties = array('label', 'mediaQuery', 'source', 'sourceType', 'weight', 'multipliers'); // Verify Breakpoint::load(). $compare_breakpoint = is_null($compare_breakpoint) ? Breakpoint::load($breakpoint->id()) : $compare_breakpoint; foreach ($properties as $property) { $t_args = array('%breakpoint' => $breakpoint->label(), '%property' => $property); $this->assertEqual($compare_breakpoint->{$property}, $breakpoint->{$property}, format_string('Proper %property for breakpoint %breakpoint.', $t_args), 'Breakpoint API'); } }
/** * Test invalid media queries. */ public function testInvalidMediaQueries() { $media_queries = array('', 'not (orientation)', 'only (orientation)', 'all and not all', 'screen and (width: 0xx)', 'screen and (width: -8xx)', 'screen and (width: -xx)', 'screen and (width: xx)', 'screen and (width: px)', 'screen and (width: -8px)', 'screen and (width: -0.8px)', 'screen and (height: 0xx)', 'screen and (height: -8xx)', 'screen and (height: -xx)', 'screen and (height: xx)', 'screen and (height: px)', 'screen and (height: -8px)', 'screen and (height: -0.8px)', 'screen and (device-width: 0xx)', 'screen and (device-width: -8xx)', 'screen and (device-width: -xx)', 'screen and (device-width: xx)', 'screen and (device-width: px)', 'screen and (device-width: -8px)', 'screen and (device-width: -0.8px)', 'screen and (device-height: 0xx)', 'screen and (device-height: -8xx)', 'screen and (device-height: -xx)', 'screen and (device-height: xx)', 'screen and (device-height: px)', 'screen and (device-height: -8px)', 'screen and (device-height: -0.8px)', 'screen and (min-orientation)', 'screen and (max-orientation)', 'screen and (orientation: bogus)', '(orientation: bogus)', 'screen and (ori"entation: bogus)'); foreach ($media_queries as $media_query) { try { $this->assertFalse(Breakpoint::isValidMediaQuery($media_query), $media_query . ' is not valid.'); } catch (InvalidBreakpointMediaQueryException $e) { $this->assertTrue(TRUE, sprintf('%s is not valid.', $media_query)); } } }
/** * 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::loadMultiple(). $all_breakpoints = Breakpoint::loadMultiple(); $config_name = $breakpoint->id(); $this->assertTrue(isset($all_breakpoints[$config_name]), '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->assertNull(Breakpoint::load($config_name), 'Loading a deleted breakpoint returns null.', 'Breakpoints API'); }
/** * {@inheritdoc} */ public function getBreakpoints() { if (empty($this->breakpoints)) { foreach ($this->breakpoint_ids as $breakpoint_id) { $breakpoint = Breakpoint::load($breakpoint_id); if ($breakpoint) { $this->breakpoints[$breakpoint_id] = $breakpoint; } } } return $this->breakpoints; }