diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php index cf62bcd..a620e96 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointInterface.php @@ -15,6 +15,20 @@ interface BreakpointInterface extends ConfigEntityInterface { /** + * Checks if a mediaQuery is valid. + * + * @throws \Drupal\breakpoint\InvalidBreakpointMediaQueryException + * + * @return bool + * Returns TRUE if the media query is valid. + * + * @see http://www.w3.org/TR/css3-mediaqueries/ + * @see http://www.w3.org/Style/CSS/Test/MediaQueries/20120229/reports/implement-report.html + * @see https://github.com/adobe/webkit/blob/master/Source/WebCore/css/ + */ + public static function isValidMediaQuery($media_query); + + /** * Checks if the breakpoint is valid. * * @throws \Drupal\breakpoint\InvalidBreakpointSourceTypeException @@ -27,17 +41,87 @@ public function isValid(); /** - * Checks if a mediaQuery is valid. - * - * @throws \Drupal\breakpoint\InvalidBreakpointMediaQueryException - * - * @return bool - * Returns TRUE if the media query is valid. - * - * @see http://www.w3.org/TR/css3-mediaqueries/ - * @see http://www.w3.org/Style/CSS/Test/MediaQueries/20120229/reports/implement-report.html - * @see https://github.com/adobe/webkit/blob/master/Source/WebCore/css/ + * @param integer $weight + * The weight the breakpoint will be set with. */ - public static function isValidMediaQuery($media_query); + public function setWeight($weight); + + /** + * @return integer + * The breakpoint's weight. + */ + public function getWeight(); + + /** + * @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 string $source + * The source the breakpoint will use. + */ + public function setSource($source); + + /** + * @return string + * The breakpoint's source. + */ + public function getSource(); + + /** + * @param string $name + * A name for the breakpoint. + */ + public function setName($name); + + /** + * @return string + * The name of the breakpoint. + */ + public function getName(); + + /** + * @param array $multipliers + * An array of multipliers. + */ + public function setMultipliers($multipliers); + + /** + * @return array + * The breakpoint's multipliers. + */ + public function getMultipliers(); + + /** + * @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 $label + * The label the breakpoint will use. + */ + public function setLabel($label); + + /** + * @return string + * The breakpoint's label. + */ + public function getLabel(); } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php index a149e68..f7e185b 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php @@ -55,69 +55,69 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface { /** * The breakpoint ID (config name). * - * @var string + * @protected string */ - public $id; + protected $id; /** * The breakpoint UUID. * - * @var string + * @protected string */ - public $uuid; + protected $uuid; /** * The breakpoint name (machine name) as specified by theme or module. * - * @var string + * @protected string */ - public $name; + protected $name; /** * The breakpoint label. * - * @var string + * @protected string */ - public $label; + protected $label; /** * The breakpoint media query. * * @var string */ - public $mediaQuery = ''; + protected $mediaQuery = ''; /** * The breakpoint source. * - * @var string + * @protected string */ - public $source = 'user'; + protected $source = 'user'; /** * The breakpoint source type. * - * @var string + * @protected string * Allowed values: * Breakpoint::SOURCE_TYPE_THEME * 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 + * @protected integer */ - public $weight = 0; + protected $weight = 0; /** * The breakpoint multipliers. * - * @var multipliers + * @protected array */ - public $multipliers = array(); + protected $multipliers = array(); /** * Overrides Drupal\config\ConfigEntityBase::save(). @@ -159,8 +159,10 @@ public function isValid() { if (!in_array($this->sourceType, array( Breakpoint::SOURCE_TYPE_USER_DEFINED, Breakpoint::SOURCE_TYPE_MODULE, - Breakpoint::SOURCE_TYPE_THEME) - )) { + Breakpoint::SOURCE_TYPE_THEME + ) + ) + ) { throw new InvalidBreakpointSourceTypeException(format_string('Invalid source type @source_type', array( '@source_type' => $this->sourceType, ))); @@ -183,17 +185,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 +306,102 @@ public static function isValidMediaQuery($media_query) { } throw new InvalidBreakpointMediaQueryException('Media query is empty.'); } + + /** + * {@inheritdoc} + */ + public function getWeight() { + return $this->weight; + } + + /** + * {@inheritdoc} + */ + public function setWeight($weight) { + $this->weight = $weight; + } + + /** + * {@inheritdoc} + */ + public function getSourceType() { + return $this->sourceType; + } + + /** + * {@inheritdoc} + */ + public function setSourceType($sourceType) { + $this->sourceType = $sourceType; + } + + /** + * {@inheritdoc} + */ + public function getSource() { + return $this->source; + } + + /** + * {@inheritdoc} + */ + public function setSource($source) { + $this->source = $source; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->name = $name; + } + + /** + * {@inheritdoc} + */ + public function getMultipliers() { + return $this->multipliers; + } + + /** + * {@inheritdoc} + */ + public function setMultipliers($multipliers) { + $this->multipliers = $multipliers; + } + + /** + * {@inheritdoc} + */ + public function getMediaQuery() { + return $this->mediaQuery; + } + + /** + * {@inheritdoc} + */ + public function setMediaQuery($mediaQuery) { + $this->mediaQuery = $mediaQuery; + } + + /** + * {@inheritdoc} + */ + public function getLabel() { + return $this->label; + } + + /** + * {@inheritdoc} + */ + public function setLabel($label) { + $this->label = $label; + } } 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..2f15359 --- /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); + } + } +}