diff --git a/core/modules/breakpoint/breakpoint.module b/core/modules/breakpoint/breakpoint.module index d502691..8c7636c 100644 --- a/core/modules/breakpoint/breakpoint.module +++ b/core/modules/breakpoint/breakpoint.module @@ -197,7 +197,7 @@ function _breakpoint_delete_breakpoints($list, $source_type) { $breakpoint_groups = entity_load_multiple('breakpoint_group', $ids); foreach ($breakpoint_groups as $breakpoint_group) { - if ($breakpoint_group->sourceType == $source_type && in_array($breakpoint_group->source, $list)) { + if ($breakpoint_group->getSourceType() == $source_type && in_array($breakpoint_group->getSource(), $list)) { // Delete the automatically created breakpoint group. $breakpoint_group->delete(); @@ -213,7 +213,7 @@ function _breakpoint_delete_breakpoints($list, $source_type) { // Make sure we only delete breakpoints defined by this theme/module. foreach ($breakpoints as $breakpoint) { - if ($breakpoint->sourceType == $source_type && $breakpoint->source == $breakpoint_group->name) { + if ($breakpoint->getSourceType() == $source_type && $breakpoint->getSource() == $breakpoint_group->name) { $breakpoint->delete(); } } @@ -239,7 +239,7 @@ function _breakpoint_delete_breakpoints($list, $source_type) { function _breakpoint_delete_breakpoint_groups($group_id, $source_type) { $breakpoint_groups = entity_load_multiple('breakpoint_group'); foreach ($breakpoint_groups as $breakpoint_group) { - if ($breakpoint_group->sourceType == $source_type && $breakpoint_group->source == $group_id) { + if ($breakpoint_group->getSourceType() == $source_type && $breakpoint_group->getSource() == $group_id) { $breakpoint_group->delete(); } } @@ -330,7 +330,7 @@ function breakpoint_group_select_options() { $options = array(); $breakpoint_groups = entity_load_multiple('breakpoint_group'); foreach ($breakpoint_groups as $breakpoint_group) { - $options[$breakpoint_group->id()] = $breakpoint_group->label(); + $options[$breakpoint_group->id()] = $breakpoint_group->getLabel(); } asort($options); return $options; @@ -346,7 +346,7 @@ function breakpoint_select_options() { $options = array(); $breakpoints = entity_load_multiple('breakpoint'); foreach ($breakpoints as $breakpoint) { - $options[$breakpoint->id()] = $breakpoint->label() . ' (' . $breakpoint->source . ' - ' . $breakpoint->sourceType . ') [' . $breakpoint->mediaQuery . ']'; + $options[$breakpoint->id()] = $breakpoint->getLabel() . ' (' . $breakpoint->getSource() . ' - ' . $breakpoint->getSourceType() . ') [' . $breakpoint->getMediaQuery() . ']'; } asort($options); return $options; diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php index 59833ff..04684b0 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php @@ -45,4 +45,68 @@ public function addBreakpointFromMediaQuery($name, $media_query); */ public function addBreakpoints($breakpoints); + /** + * @param string + * The name of the breakpoint group. + */ + public function setName($name); + + /** + * @return string + * The name of the breakpoint group. + */ + public function getName(); + + /** + * @param string $label + * The label the breakpoint group will use. + */ + public function setLabel($label); + + /** + * @return string + * The breakpoint group's label. + */ + public function getLabel(); + + /** + * Sets the breakpoints the group will use. + * + * The breakpoint name is either the machine_name or the ID of a breakpoint. + * + * @param array $breakpoints + * Array containing breakpoints keyed by their ID. + */ + public function setBreakpoints($breakpoints); + + /** + * @return array \Drupal\breakpoint\Entity\Breakpoint + * Array containing breakpoints keyed by their id. + */ + public function getBreakpoints(); + + /** + * @return string + * The breakpoint group's source. + */ + public function getSource(); + + /** + * @param string $source + * The source the breakpoint will use. + */ + public function setSource($source); + + /** + * @param string $sourceType + * The source type the breakpoint group will use. + */ + public function setSourceType($sourceType); + + /** + * @return string + * The breakpoint group's source type. + */ + public function getSourceType(); + } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php index cf62bcd..e72ef66 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php @@ -40,4 +40,88 @@ public function isValid(); */ public static function isValidMediaQuery($media_query); + /** + * @param string + * The name of the breakpoint. + */ + public function setName($name); + + /** + * @return string + * The name of the breakpoint. + */ + public function getName(); + + /** + * @param string $label + * The label the breakpoint will use. + */ + public function setLabel($label); + + /** + * @return string + * The breakpoint's label. + */ + public function getLabel(); + + /** + * @param string $mediaQuery + * The media query the breakpoint will use. + */ + public function setMediaQuery($mediaQuery); + + /** + * @return string + * The breakpoint's media query. + */ + public function getMediaQuery(); + + /** + * @param string $source + * The source the breakpoint will use. + */ + public function setSource($source); + + /** + * @return string + * The breakpoint's source. + */ + public function getSource(); + + /** + * @param string $sourceType + * The source type the breakpoint will use. + */ + public function setSourceType($sourceType); + + /** + * @return string + * The breakpoint's source type. + */ + public function getSourceType(); + + /** + * @param integer $weight + * The weight the breakpoint will be set with. + */ + public function setWeight($weight); + + /** + * @return integer + * The breakpoint's weight. + */ + public function getWeight(); + + /** + * @param array $multipliers + * An array of multipliers. + */ + public function setMultipliers($multipliers); + + /** + * @return array + * The breakpoint's multipliers. + */ + public function getMultipliers(); + } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php index a149e68..ecc9b65 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php @@ -71,28 +71,28 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface { * * @var string */ - public $name; + protected $name; /** * The breakpoint label. * * @var string */ - public $label; + protected $label = ''; /** * The breakpoint media query. * * @var string */ - public $mediaQuery = ''; + protected $mediaQuery = ''; /** * The breakpoint source. * * @var string */ - public $source = 'user'; + protected $source = 'user'; /** * The breakpoint source type. @@ -103,21 +103,21 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface { * Breakpoint::SOURCE_TYPE_MODULE * Breakpoint::SOURCE_TYPE_USER_DEFINED */ - public $sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED; + protected $sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED; /** * The breakpoint weight. * * @var weight */ - public $weight = 0; + protected $weight = 0; /** * The breakpoint multipliers. * * @var multipliers */ - public $multipliers = array(); + protected $multipliers = array(); /** * Overrides Drupal\config\ConfigEntityBase::save(). @@ -131,22 +131,22 @@ public function save() { // Build an id if none is set. // Since a particular name can be used by multiple theme/modules we need // to make a unique id. - if (empty($this->id)) { - $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name; + if (!$this->id()) { + $this->id = ($this->getSourceType() . '.' . $this->getSource() . '.' . $this->getName()); } // Set the label if none is set. - if (empty($this->label)) { - $this->label = $this->name; + if (!$this->getLabel()) { + $this->setLabel($this->getName()); } // Remove unused multipliers. - $this->multipliers = array_filter($this->multipliers); + $this->setMultipliers(array_filter($this->getMultipliers())); // Always add '1x' multiplier, use array_key_exists since the value might // be NULL. - if (!array_key_exists('1x', $this->multipliers)) { - $this->multipliers = array('1x' => '1x') + $this->multipliers; + if (!array_key_exists('1x', $this->getMultipliers())) { + $this->setMultipliers(array('1x' => '1x') + $this->getMultipliers()); } return parent::save(); } @@ -156,24 +156,24 @@ public function save() { */ public function isValid() { // Check for illegal values in breakpoint source type. - if (!in_array($this->sourceType, array( + if (!in_array($this->getSourceType(), array( Breakpoint::SOURCE_TYPE_USER_DEFINED, Breakpoint::SOURCE_TYPE_MODULE, Breakpoint::SOURCE_TYPE_THEME) )) { throw new InvalidBreakpointSourceTypeException(format_string('Invalid source type @source_type', array( - '@source_type' => $this->sourceType, + '@source_type' => $this->getSourceType(), ))); } // Check for illegal characters in breakpoint source. - if (preg_match('/[^0-9a-z_]+/', $this->source)) { - throw new InvalidBreakpointSourceException(format_string("Invalid value '@source' for breakpoint source property. Breakpoint source property can only contain lowercase alphanumeric characters and underscores.", array('@source' => $this->source))); + if (preg_match('/[^0-9a-z_]+/', $this->getSource())) { + throw new InvalidBreakpointSourceException(format_string("Invalid value '@source' for breakpoint source property. Breakpoint source property can only contain lowercase alphanumeric characters and underscores.", array('@source' => $this->getSource()))); } // Check for illegal characters in breakpoint names. - if (preg_match('/[^0-9a-z_\-]/', $this->name)) { - throw new InvalidBreakpointNameException(format_string("Invalid value '@name' for breakpoint name property. Breakpoint name property can only contain lowercase alphanumeric characters, underscores (_), and hyphens (-).", array('@name' => $this->name))); + if (preg_match('/[^0-9a-z_\-]/', $this->getName())) { + throw new InvalidBreakpointNameException(format_string("Invalid value '@name' for breakpoint name property. Breakpoint name property can only contain lowercase alphanumeric characters, underscores (_), and hyphens (-).", array('@name' => $this->getName()))); } - return $this::isValidMediaQuery($this->mediaQuery); + return $this::isValidMediaQuery($this->getMediaQuery()); } /** @@ -183,17 +183,37 @@ public static function isValidMediaQuery($media_query) { // Array describing all known media features and the expected value type or // an array containing the allowed values. $media_features = array( - 'width' => 'length', 'min-width' => 'length', 'max-width' => 'length', - 'height' => 'length', 'min-height' => 'length', 'max-height' => 'length', - 'device-width' => 'length', 'min-device-width' => 'length', 'max-device-width' => 'length', - 'device-height' => 'length', 'min-device-height' => 'length', 'max-device-height' => 'length', + 'width' => 'length', + 'min-width' => 'length', + 'max-width' => 'length', + 'height' => 'length', + 'min-height' => 'length', + 'max-height' => 'length', + 'device-width' => 'length', + 'min-device-width' => 'length', + 'max-device-width' => 'length', + 'device-height' => 'length', + 'min-device-height' => 'length', + 'max-device-height' => 'length', 'orientation' => array('portrait', 'landscape'), - 'aspect-ratio' => 'ratio', 'min-aspect-ratio' => 'ratio', 'max-aspect-ratio' => 'ratio', - 'device-aspect-ratio' => 'ratio', 'min-device-aspect-ratio' => 'ratio', 'max-device-aspect-ratio' => 'ratio', - 'color' => 'integer', 'min-color' => 'integer', 'max-color' => 'integer', - 'color-index' => 'integer', 'min-color-index' => 'integer', 'max-color-index' => 'integer', - 'monochrome' => 'integer', 'min-monochrome' => 'integer', 'max-monochrome' => 'integer', - 'resolution' => 'resolution', 'min-resolution' => 'resolution', 'max-resolution' => 'resolution', + 'aspect-ratio' => 'ratio', + 'min-aspect-ratio' => 'ratio', + 'max-aspect-ratio' => 'ratio', + 'device-aspect-ratio' => 'ratio', + 'min-device-aspect-ratio' => 'ratio', + 'max-device-aspect-ratio' => 'ratio', + 'color' => 'integer', + 'min-color' => 'integer', + 'max-color' => 'integer', + 'color-index' => 'integer', + 'min-color-index' => 'integer', + 'max-color-index' => 'integer', + 'monochrome' => 'integer', + 'min-monochrome' => 'integer', + 'max-monochrome' => 'integer', + 'resolution' => 'resolution', + 'min-resolution' => 'resolution', + 'max-resolution' => 'resolution', 'scan' => array('progressive', 'interlace'), 'grid' => 'integer', ); @@ -284,4 +304,131 @@ public static function isValidMediaQuery($media_query) { } throw new InvalidBreakpointMediaQueryException('Media query is empty.'); } -} + + /** + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties(); + */ + public function getExportProperties() { + $names = array( + 'id', + 'uuid', + 'name', + 'label', + 'mediaQuery', + 'source', + 'sourceType', + 'weight', + 'multipliers', + ); + $properties = array(); + foreach ($names as $name) { + $properties[$name] = $this->get($name); + } + return $properties; + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->set('name', $name); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->get('name'); + } + + /** + * {@inheritdoc} + */ + public function setLabel($label) { + $this->set('label', $label); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getLabel() { + return $this->get('label'); + } + + /** + * {@inheritdoc} + */ + public function setMediaQuery($mediaQuery) { + $this->set('mediaQuery', $mediaQuery); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getMediaQuery() { + return $this->get('mediaQuery'); + } + + /** + * {@inheritdoc} + */ + public function setSource($source) { + $this->set('source', $source); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getSource() { + return $this->get('source'); + } + + /** + * {@inheritdoc} + */ + public function setSourceType($sourceType) { + $this->set('sourceType', $sourceType); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getSourceType() { + return $this->get('sourceType'); + } + + /** + * {@inheritdoc} + */ + public function setWeight($weight) { + $this->set('weight', $weight); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getWeight() { + return $this->get('weight'); + } + + /** + * {@inheritdoc} + */ + public function setMultipliers($multipliers) { + $this->set('multipliers', $multipliers); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getMultipliers() { + return $this->get('multipliers'); + } +} \ No newline at end of file diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php index 6a3150a..a07413c 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php @@ -53,14 +53,14 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa * * @var string */ - public $name; + protected $name; /** * The breakpoint group label. * * @var string */ - public $label; + protected $label; /** * The breakpoint group breakpoints. @@ -70,7 +70,7 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa * * @see \Drupal\breakpoint\Entity\Breakpoint */ - public $breakpoints = array(); + protected $breakpoints = array(); /** * The breakpoint group source: theme or module name. Use 'user' for @@ -78,7 +78,7 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa * * @var string */ - public $source = 'user'; + protected $source = 'user'; /** * The breakpoint group source type. @@ -91,7 +91,7 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa * * @see \Drupal\breakpoint\Entity\Breakpoint */ - public $sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED; + protected $sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED; /** * Overrides Drupal\config\ConfigEntityBase::__construct(). @@ -109,11 +109,11 @@ public function save() { if (!$this->isValid()) { throw new InvalidBreakpointException('Invalid data detected.'); } - if (empty($this->id)) { - $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name; + if (!$this->id()) { + $this->id = ($this->getSourceType() . '.' . $this->getSource() . '.' . $this->getName()); } // Only save the keys, but return the full objects. - $this->breakpoints = array_keys($this->breakpoints); + $this->setBreakpoints(array_keys($this->getBreakpoints())); parent::save(); $this->loadAllBreakpoints(); } @@ -123,22 +123,22 @@ public function save() { */ public function isValid() { // Check for illegal values in breakpoint group source type. - if (!in_array($this->sourceType, array( + if (!in_array($this->getSourceType(), array( Breakpoint::SOURCE_TYPE_USER_DEFINED, Breakpoint::SOURCE_TYPE_MODULE, Breakpoint::SOURCE_TYPE_THEME) )) { throw new InvalidBreakpointSourceTypeException(format_string('Invalid source type @source_type', array( - '@source_type' => $this->sourceType, + '@source_type' => $this->getSourceType(), ))); } // Check for illegal characters in breakpoint group source. - if (preg_match('/[^a-z_]+/', $this->source) || empty($this->source)) { - throw new InvalidBreakpointSourceException(format_string("Invalid value '@source' for breakpoint group source property. Breakpoint group source property can only contain lowercase letters and underscores.", array('@source' => $this->source))); + if (preg_match('/[^a-z_]+/', $this->getSource()) || !$this->getSource()) { + throw new InvalidBreakpointSourceException(format_string("Invalid value '@source' for breakpoint group source property. Breakpoint group source property can only contain lowercase letters and underscores.", array('@source' => $this->getSource()))); } // Check for illegal characters in breakpoint group name. - if (preg_match('/[^a-z0-9_]+/', $this->name || empty($this->name))) { - throw new InvalidBreakpointNameException(format_string("Invalid value '@name' for breakpoint group name property. Breakpoint group name property can only contain lowercase letters, numbers and underscores.", array('@name' => $this->name))); + if (preg_match('/[^a-z0-9_]+/', $this->getName() || !$this->getName())) { + throw new InvalidBreakpointNameException(format_string("Invalid value '@name' for breakpoint group name property. Breakpoint group name property can only contain lowercase letters, numbers and underscores.", array('@name' => $this->getName()))); } return TRUE; } @@ -148,7 +148,7 @@ public function isValid() { */ public function addBreakpointFromMediaQuery($name, $media_query) { // Use the existing breakpoint if it exists. - $breakpoint = entity_load('breakpoint', $this->sourceType . '.' . $this->name . '.' . $name); + $breakpoint = entity_load('breakpoint', $this->getSourceType() . '.' . $this->getSource() . '.' . $name); if (!$breakpoint) { // Build a new breakpoint. $breakpoint = entity_create('breakpoint', array( @@ -161,16 +161,19 @@ public function addBreakpointFromMediaQuery($name, $media_query) { )); $breakpoint->save(); } - $this->breakpoints[$breakpoint->id()] = $breakpoint; + $all_breakpoints = $this->getBreakpoints(); + $all_breakpoints[$breakpoint->id()] = $breakpoint; + $this->setBreakpoints($all_breakpoints); } /** * {@inheritdoc} */ public function addBreakpoints($breakpoints) { + $all_breakpoints = array(); foreach ($breakpoints as $breakpoint_name) { // Check if breakpoint exists, assume $breakpoint_name is a machine name. - $breakpoint = entity_load('breakpoint', $this->sourceType . '.' . $this->source . '.' . $breakpoint_name); + $breakpoint = entity_load('breakpoint', $this->getSourceType() . '.' . $this->getSource() . '.' . $breakpoint_name); // If the breakpoint doesn't exist, assume $breakpoint_name is an id. if (!$breakpoint) { $breakpoint = entity_load('breakpoint', $breakpoint_name); @@ -178,9 +181,10 @@ public function addBreakpoints($breakpoints) { // If the breakpoint doesn't exists, do not add it. if ($breakpoint) { // Add breakpoint to group. - $this->breakpoints[$breakpoint->id()] = $breakpoint; + $all_breakpoints[$breakpoint->id()] = $breakpoint; } } + $this->setBreakpoints($all_breakpoints); } /** @@ -190,14 +194,108 @@ public function addBreakpoints($breakpoints) { * Array containing breakpoints keyed by their id. */ protected function loadAllBreakpoints() { - $breakpoints = $this->breakpoints; - $this->breakpoints = array(); + $breakpoints = $this->getBreakpoints(); + $all_breakpoints = array(); foreach ($breakpoints as $breakpoint_id) { $breakpoint = breakpoint_load($breakpoint_id); if ($breakpoint) { - $this->breakpoints[$breakpoint_id] = $breakpoint; + $all_breakpoints[$breakpoint_id] = $breakpoint; } } + $this->setBreakpoints($all_breakpoints); } + /** + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties(); + */ + public function getExportProperties() { + $names = array( + 'id', + 'uuid', + 'name', + 'label', + 'breakpoints', + 'source', + 'sourceType', + ); + $properties = array(); + foreach ($names as $name) { + $properties[$name] = $this->get($name); + } + return $properties; + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->set('name', $name); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->get('name'); + } + + /** + * {@inheritdoc} + */ + public function setLabel($label) { + $this->set('label', $label); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getLabel() { + return $this->get('label'); + } + + /** + * {@inheritdoc} + */ + public function setBreakpoints($breakpoints) { + $this->set('breakpoints', $breakpoints); + } + + /** + * {@inheritdoc} + */ + public function getBreakpoints() { + return $this->get('breakpoints'); + } + + /** + * {@inheritdoc} + */ + public function setSource($source) { + $this->set('source', $source); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getSource() { + return $this->get('source'); + } + + /** + * {@inheritdoc} + */ + public function setSourceType($sourceType) { + $this->set('sourceType', $sourceType); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getSourceType() { + return $this->get('sourceType'); + } } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php index 85d0711..5135797 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php @@ -46,9 +46,9 @@ public function testConfigName() { $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'; + $breakpoint->enforceIsNew(); + $breakpoint->setSourceType(Breakpoint::SOURCE_TYPE_USER_DEFINED) + ->setSource('custom*_module source'); $exception = FALSE; try { @@ -60,9 +60,9 @@ public function testConfigName() { $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()); + $breakpoint->enforceIsNew(); + $breakpoint->setSource('custom_module') + ->setName(drupal_ucfirst($this->randomName())); $exception = FALSE; try { @@ -74,9 +74,9 @@ public function testConfigName() { $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'; + $breakpoint->enforceIsNew(); + $breakpoint->setName(drupal_strtolower($this->randomName())) + ->setMediaQuery('all'); $exception = FALSE; try { @@ -86,6 +86,6 @@ public function testConfigName() { $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.'); + $this->assertEqual($breakpoint->id(), Breakpoint::SOURCE_TYPE_USER_DEFINED . '.custom_module.' . $breakpoint->getName(), 'breakpoint_config_name: A id is set when a valid breakpoint is passed.'); } } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php index 4358869..ceef678 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php @@ -42,8 +42,8 @@ public function testBreakpointCRUD() { $this->verifyBreakpoint($breakpoint, $all_breakpoints[$config_name]); // Update the breakpoint. - $breakpoint->weight = 1; - $breakpoint->multipliers['2x'] = '2x'; + $breakpoint->setWeight(1) + ->setMultipliers(array('2x' => '2x')); $breakpoint->save(); $this->verifyBreakpoint($breakpoint); diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php index 3751c81..9a5412e 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php @@ -49,9 +49,9 @@ public function testConfigName() { $this->assertTrue($exception, 'An exception is thrown when an invalid sourceType is entered.'); // Try an invalid source. - $breakpoint_group->name = ''; - $breakpoint_group->sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED; - $breakpoint_group->source = 'custom*_module source'; + $breakpoint_group->setName('') + ->setSourceType(Breakpoint::SOURCE_TYPE_USER_DEFINED) + ->setSource('custom*_module source'); $exception = FALSE; try { @@ -63,8 +63,8 @@ public function testConfigName() { $this->assertTrue($exception, 'An exception is thrown when an invalid source is entered.'); // Try a valid breakpoint_group. - $breakpoint_group->name = 'test'; - $breakpoint_group->source = 'custom_module_source'; + $breakpoint_group->setName('test') + ->setSource('custom_module_source'); $exception = FALSE; try { diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupCRUDTest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupCRUDTest.php index bd5a2a8..1b7381d 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupCRUDTest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupCRUDTest.php @@ -50,7 +50,7 @@ public function testBreakpointGroupCRUD() { $this->verifyBreakpointGroup($group); // Update the breakpoint group. - $group->breakpoints = array_keys($breakpoints); + $group->setBreakpoints(array_keys($breakpoints)); $group->save(); $this->verifyBreakpointGroup($group); diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupTestBase.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupTestBase.php index 0f7e471..03c3dd9 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupTestBase.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupTestBase.php @@ -30,11 +30,11 @@ public function setUp() { */ public function verifyBreakpointGroup(BreakpointGroup $group, BreakpointGroup $compare_set = NULL) { $properties = array( - 'label', - 'id', - 'name', - 'breakpoints', - 'sourceType', + 'Label', + 'Name', + 'Breakpoints', + 'Source', + 'SourceType', ); // Verify breakpoint_group_load(). @@ -42,20 +42,20 @@ public function verifyBreakpointGroup(BreakpointGroup $group, BreakpointGroup $c foreach ($properties as $property) { $t_args = array( - '%group' => $group->label(), + '%group' => $group->getLabel(), '%property' => $property, ); - if (is_array($compare_set->{$property})) { - $this->assertEqual(array_keys($compare_set->{$property}), array_keys($group->{$property}), format_string('breakpoint_group_load: Proper %property for breakpoint group %group.', $t_args), 'Breakpoint API'); + if (is_array($compare_set->{'get' . $property}())) { + $this->assertEqual(array_keys($compare_set->{'get' . $property}()), array_keys($group->{'get' . $property}()), format_string('breakpoint_group_load: Proper %property for breakpoint group %group.', $t_args), 'Breakpoint API'); } else { $t_args = array( - '%group' => $group->label(), + '%group' => $group->getLabel(), '%property' => $property, - '%property1' => $compare_set->{$property}, - '%property2' => $group->{$property}, + '%property1' => $compare_set->{'get' . $property}(), + '%property2' => $group->{'get'. $property}(), ); - $this->assertEqual($compare_set->{$property}, $group->{$property}, format_string('breakpoint_group_load: Proper %property: %property1 == %property2 for breakpoint group %group.', $t_args), 'Breakpoint API'); + $this->assertEqual($compare_set->{'get' . $property}(), $group->{'get' . $property}(), format_string('breakpoint_group_load: Proper %property: %property1 == %property2 for breakpoint group %group.', $t_args), 'Breakpoint API'); } } } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointTestBase.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointTestBase.php index 89d0cc1..4b59d3b 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointTestBase.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointTestBase.php @@ -30,22 +30,22 @@ public function setUp() { */ public function verifyBreakpoint(Breakpoint $breakpoint, Breakpoint $compare_breakpoint = NULL) { $properties = array( - 'label', - 'mediaQuery', - 'source', - 'sourceType', - 'weight', - 'multipliers', + '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(), + '%breakpoint' => $breakpoint->getLabel(), '%property' => $property, ); - $this->assertEqual($compare_breakpoint->{$property}, $breakpoint->{$property}, format_string('breakpoint_load: Proper %property for breakpoint %breakpoint.', $t_args), 'Breakpoint API'); + $this->assertEqual($compare_breakpoint->{'get' . $property}(), $breakpoint->{'get' . $property}(), format_string('breakpoint_load: Proper %property for breakpoint %breakpoint.', $t_args), 'Breakpoint API'); } } } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php index e00af05..3e6cb39 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php @@ -47,12 +47,12 @@ public function testThemeBreakpoints() { 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, 'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.breakpoint_test_theme', )); - $breakpoint_group_obj->breakpoints = array( + $breakpoint_group_obj->setBreakpoints(array( 'theme.breakpoint_test_theme.mobile' => array(), 'theme.breakpoint_test_theme.narrow' => array(), 'theme.breakpoint_test_theme.wide' => array(), 'theme.breakpoint_test_theme.tv' => array(), - ); + )); // Verify we can load this breakpoint defined by the theme. $this->verifyBreakpointGroup($breakpoint_group_obj); @@ -74,11 +74,11 @@ public function testThemeBreakpointGroup() { 'source' => 'breakpoint_test_theme', 'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.test', )); - $breakpoint_group_obj->breakpoints = array( + $breakpoint_group_obj->setBreakpoints(array( 'theme.breakpoint_test_theme.mobile' => array('1.5x', '2.x'), 'theme.breakpoint_test_theme.narrow' => array(), 'theme.breakpoint_test_theme.wide' => array(), - ); + )); // Verify we can load this breakpoint defined by the theme. $this->verifyBreakpointGroup($breakpoint_group_obj); @@ -105,11 +105,11 @@ public function testThemeBreakpointGroupModule() { 'source' => 'breakpoint_theme_test', 'id' => Breakpoint::SOURCE_TYPE_MODULE . '.breakpoint_theme_test.module_test', )); - $breakpoint_group_obj->breakpoints = array( + $breakpoint_group_obj->setBreakpoints(array( 'theme.breakpoint_test_theme.mobile' => array(), 'theme.breakpoint_test_theme.narrow' => array(), 'theme.breakpoint_test_theme.wide' => array(), - ); + )); // Verify we can load this breakpoint defined by the theme. $this->verifyBreakpointGroup($breakpoint_group_obj); diff --git a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMethodsTest.php b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMethodsTest.php new file mode 100644 index 0000000..1e19f01 --- /dev/null +++ b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMethodsTest.php @@ -0,0 +1,51 @@ + 'Breakpoint Methods tests', + 'description' => 'Test validation of class methods.', + 'group' => 'Breakpoint', + ); + } + + /** + * Test properties setters and getters. + */ + public function testMethods() { + $breakpoint = new Breakpoint(array(), 'Breakpoint'); + + // Methods to test with some random data. + // I.e., setLabel($randomdata) and getLabel() + $methods = array( + 'Label' => $this->getRandomGenerator()->name(16), + 'MediaQuery' => $this->getRandomGenerator()->string(16), + 'Multipliers' => array($this->getRandomGenerator()->string(16),$this->getRandomGenerator()->string(16)), + 'Name' => $this->getRandomGenerator()->name(16), + 'Source' => $this->getRandomGenerator()->name(16), + 'SourceType' => $this->getRandomGenerator()->name(16), + 'Weight' => mt_rand(-40, 40), + ); + + foreach($methods as $name => $value) { + $breakpoint->{'set' . $name}($value); + $this->assertEquals($value, $breakpoint->{'get' . $name}(), 'Breakpoint methods: set' . $name . ' and get' . $name); + } + } +} diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 85bfafa..637955a 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -190,9 +190,9 @@ function toolbar_pre_render($element) { $media_queries = array(); $media_queries['toolbar']['breakpoints'] = array_map( function ($object) { - return $object->mediaQuery; + return $object->getMediaQuery(); }, - $breakpoints->breakpoints + $breakpoints->getBreakpoints() ); $element['#attached']['js'][] = array(