Beispiel #1
0
    /**
     * Test the css_is_width function
     */
    public function test_css_is_width() {

        $this->assertTrue(css_is_width('0'));
        $this->assertTrue(css_is_width('0px'));
        $this->assertTrue(css_is_width('0em'));
        $this->assertTrue(css_is_width('199px'));
        $this->assertTrue(css_is_width('199em'));
        $this->assertTrue(css_is_width('199%'));
        $this->assertTrue(css_is_width('-1'));
        $this->assertTrue(css_is_width('-1px'));
        $this->assertTrue(css_is_width('auto'));
        $this->assertTrue(css_is_width('inherit'));

        $this->assertFalse(css_is_width('-'));
        $this->assertFalse(css_is_width('bananas'));
        $this->assertFalse(css_is_width(''));
        $this->assertFalse(css_is_width('top'));
    }
Beispiel #2
0
 /**
  * Initialises a background style
  *
  * @param type $value The value of the style
  * @return array An array of background component.
  */
 public static function init($value)
 {
     // colour - image - repeat - attachment - position
     $imageurl = null;
     if (preg_match('#url\\(([^\\)]+)\\)#', $value, $matches)) {
         $imageurl = trim($matches[1]);
         $value = str_replace($matches[1], '', $value);
     }
     $value = preg_replace('#\\s+#', ' ', $value);
     $bits = explode(' ', $value);
     $repeats = array('repeat', 'repeat-x', 'repeat-y', 'no-repeat', 'inherit');
     $attachments = array('scroll', 'fixed', 'inherit');
     $return = array();
     $unknownbits = array();
     if (count($bits) > 0 && css_is_colour(reset($bits))) {
         $return[] = new css_style_backgroundcolor('background-color', array_shift($bits));
     }
     if (count($bits) > 0 && preg_match('#(none|inherit|url\\(\\))#', reset($bits))) {
         $image = array_shift($bits);
         if ($image == 'url()') {
             $image = "url({$imageurl})";
         }
         $return[] = new css_style_backgroundimage('background-image', $image);
     }
     if (count($bits) > 0 && in_array(reset($bits), $repeats)) {
         $return[] = new css_style_backgroundrepeat('background-repeat', array_shift($bits));
     }
     if (count($bits) > 0 && in_array(reset($bits), $attachments)) {
         // scroll , fixed, inherit
         $return[] = new css_style_backgroundattachment('background-attachment', array_shift($bits));
     }
     if (count($bits) > 0) {
         $widthbits = array();
         foreach ($bits as $bit) {
             if (in_array($bit, array('top', 'left', 'bottom', 'right', 'center')) || css_is_width($bit)) {
                 $widthbits[] = $bit;
             } else {
                 $unknownbits[] = $bit;
             }
         }
         $return[] = new css_style_backgroundposition('background-position', join(' ', $widthbits));
     }
     if (count($unknownbits)) {
         foreach ($unknownbits as $bit) {
             if (css_is_colour($bit)) {
                 $return[] = new css_style_backgroundcolor('background-color', $bit);
             } else {
                 if (in_array($bit, $repeats)) {
                     $return[] = new css_style_backgroundrepeat('background-repeat', $bit);
                 } else {
                     if (in_array($bit, $attachments)) {
                         $return[] = new css_style_backgroundattachment('background-attachment', $bit);
                     }
                 }
             }
         }
     }
     return $return;
 }
Beispiel #3
0
 /**
  * Cleans the given value and returns it.
  *
  * @param string $value
  * @return string
  */
 protected function clean_value($value)
 {
     $allowed = array('left', 'right', 'none', 'inherit');
     if (!css_is_width($value) && !in_array($value, $allowed)) {
         $this->set_error('Invalid float value specified: ' . $value);
     }
     return trim($value);
 }
 /**
  * Test the css_is_width function.
  */
 public function test_css_is_width()
 {
     $this->assertTrue(css_is_width('0'));
     $this->assertTrue(css_is_width('0px'));
     $this->assertTrue(css_is_width('0em'));
     $this->assertTrue(css_is_width('199px'));
     $this->assertTrue(css_is_width('199em'));
     $this->assertTrue(css_is_width('199%'));
     $this->assertTrue(css_is_width('-1px'));
     $this->assertTrue(css_is_width('auto'));
     $this->assertTrue(css_is_width('inherit'));
     // Valid widths but missing their unit specifier.
     $this->assertFalse(css_is_width('0.75'));
     $this->assertFalse(css_is_width('3'));
     $this->assertFalse(css_is_width('-1'));
     // Totally invalid widths.
     $this->assertFalse(css_is_width('-'));
     $this->assertFalse(css_is_width('bananas'));
     $this->assertFalse(css_is_width(''));
     $this->assertFalse(css_is_width('top'));
 }
Beispiel #5
0
 /**
  * Test the css_is_width function.
  */
 public function test_css_is_width()
 {
     $debugstr = 'css_is_width() is deprecated without a replacement. Please copy the implementation ' . 'into your plugin if you need this functionality.';
     $this->assertTrue(css_is_width('0'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('0px'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('0em'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('199px'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('199em'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('199%'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('-1px'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('auto'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertTrue(css_is_width('inherit'));
     $this->assertDebuggingCalled($debugstr);
     // Valid widths but missing their unit specifier.
     $this->assertFalse(css_is_width('0.75'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertFalse(css_is_width('3'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertFalse(css_is_width('-1'));
     $this->assertDebuggingCalled($debugstr);
     // Totally invalid widths.
     $this->assertFalse(css_is_width('-'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertFalse(css_is_width('bananas'));
     $this->assertDebuggingCalled($debugstr);
     $this->assertFalse(css_is_width(''));
     $this->assertDebuggingCalled($debugstr);
     $this->assertFalse(css_is_width('top'));
     $this->assertDebuggingCalled($debugstr);
 }