/** * Test the repair() method. * * @see \Jyxo\Css::repair() */ public function testRepair() { // In the form: expected css, given css $tests = []; // Converts property names to lowercase $tests[] = ['html { margin : 10px 20px 10px; color: black}', 'html { MARGIN : 10px 20px 10px; COLOR: black}']; $tests[] = ['margin: 10px 20px 10px; color: black;', 'MARGIN: 10px 20px 10px; COLOR: black;']; // Converts rgb() and url() to lowercase $tests[] = ['background: url (\'background.png\') #ffffff;', 'background: URL (\'background.png\') RGB (255, 255, 255);']; // Remove properties without definitions $tests[] = ['border: solid 1px black;', 'border: solid 1px black; color:; color:; color:']; $tests[] = ['border: solid 1px black;', 'border: solid 1px black; color: ;']; $tests[] = ['border: solid 1px black;', 'border: solid 1px black; color:']; $tests[] = ['{border: solid 1px black;}', '{border: solid 1px black; color: }']; $tests[] = ['{border: solid 1px black; } ', '{border: solid 1px black; color : ; } ']; // Remove MS Word properties $tests[] = ['{}', '{mso-bidi-font-weight: normal; mso-bidi-font-weight: normal; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-ansi-language: CS; mso-hansi-theme-font: minor-latin;}']; $tests[] = ['{color: black;}', '{color: black; mso-bidi-font-weight: normal}']; $tests[] = ['{color: black;}', '{color: black; mso-bidi-font-weight : }']; $tests[] = ['color: black;', 'color: black; mso-bidi-font-weight:']; // Converts colors to lowercase $tests[] = ['color: #aabbcc;', 'color: #aaBBcc;']; $tests[] = ['color: #aabbcc', 'color: #aabbcc']; $tests[] = ['color:#aa00cc;', 'color:#Aa00Cc;']; // Converts color from RGB to HEX $tests[] = ['color: #ffffff;', 'color: rgb(255, 255, 255);']; $tests[] = ['color:#000000', 'color:rgb (0,0,0)']; $tests[] = ['color: #a4a2a3;', 'color: RGB( 164 , 162 , 163 );']; foreach ($tests as $no => $test) { $this->assertEquals($test[0], Css::repair($test[1]), sprintf('Test %s', $no + 1)); } }