*/ class CssToAttributeConverterTest extends \PHPUnit_Framework_TestCase { /** * @test */ public function classIsAbstractHtmlProcessor() { static::assertInstanceOf(AbstractHtmlProcessor::class, new CssToAttributeConverter('')); } /** * @test */ public function renderWithoutConvertCssToVisualAttributesCallNotAddsVisuablAttributes() { $html = ''; $subject = new CssToAttributeConverter($html); static::assertContains('', $subject->render()); } /** * @test */ public function convertCssToVisualAttributesUsesFluentInterface() { $html = ''; $subject = new CssToAttributeConverter($html); static::assertSame($subject, $subject->convertCssToVisualAttributes()); } /** * @return string[][] */ public function matchingCssToHtmlMappingDataProvider() { return [ 'background-color => bgcolor' => ['

hi

', 'bgcolor="red"'], 'background-color with !important => bgcolor' => [ '

hi

', 'bgcolor="red"', ], 'p.text-align => align' => ['

hi

', 'align="left"'], 'div.text-align => align' => ['
hi
', 'align="left"'], 'td.text-align => align' => [ '
hi
', 'align="left', ], 'text-align: left => align=left' => ['

hi

', 'align="left"'], 'text-align: right => align=right' => ['

hi

', 'align="right"'], 'text-align: center => align=center' => ['

hi

', 'align="center"'], 'text-align: justify => align:justify' => ['

hi

', 'align="justify"'], 'img.float: right => align=right' => ['', 'align="right"'], 'img.float: left => align=left' => ['', 'align="left"'], 'table.float: right => align=right' => ['
', 'align="right"'], 'table.float: left => align=left' => ['
', 'align="left"'], 'table.border-spacing: 0 => cellspacing=0' => [ '
', 'cellspacing="0"', ], 'background => bgcolor' => ['

Bonjour

', 'bgcolor="red"'], 'width with px' => ['

Hi

', 'width="100"'], 'width with %' => ['

Hi

', 'width="50%"'], 'height with px' => ['

Hi

', 'height="100"'], 'height with %' => ['

Hi

', 'height="50%"'], 'img.margin: 0 auto (horizontal centering) => align=center' => [ '', 'align="center"', ], 'img.margin: auto (horizontal centering) => align=center' => [ '', 'align="center"', ], 'img.margin: 10 auto 30 auto (horizontal centering) => align=center' => [ '', 'align="center"', ], 'table.margin: 0 auto (horizontal centering) => align=center' => [ '
', 'align="center"', ], 'table.margin: auto (horizontal centering) => align=center' => [ '
', 'align="center"', ], 'table.margin: 10 auto 30 auto (horizontal centering) => align=center' => [ '
', 'align="center"', ], 'img.border: none => border=0' => ['', 'border="0"'], 'img.border: 0 => border=0' => ['', 'border="0"'], 'table.border: none => border=0' => ['
', 'border="0"'], 'table.border: 0 => border=0' => ['
', 'border="0"'], ]; } /** * @test * * @param string $body The HTML * @param string $attributes The attributes that are expected on the element * * @dataProvider matchingCssToHtmlMappingDataProvider */ public function convertCssToVisualAttributesMapsSuitableCssToHtml($body, $attributes) { $subject = new CssToAttributeConverter('' . $body . ''); $subject->convertCssToVisualAttributes(); $html = $subject->render(); static::assertContains($attributes, $html); } /** * @return string[][] */ public function notMatchingCssToHtmlMappingDataProvider() { return [ 'background URL' => ['

Hello

'], 'background URL with position' => ['

Hello

'], 'p.margin: 10 5 30 auto (no horizontal centering)' => [''], 'p.margin: auto' => ['

Hi

'], 'p.border: none' => ['

Hi

'], 'img.border: 1px solid black' => [''], 'span.text-align' => ['Hi'], 'text-align: inherit' => ['

Hi

'], 'span.float' => ['Hi'], 'float: none' => ['
'], 'p.border-spacing' => ['

Hi

'], 'height: auto' => [''], 'width: auto' => [''], ]; } /** * @test * * @param string $body the HTML * * @dataProvider notMatchingCssToHtmlMappingDataProvider */ public function convertCssToVisualAttributesNotMapsUnsuitableCssToHtml($body) { $subject = new CssToAttributeConverter('' . $body . ''); $subject->convertCssToVisualAttributes(); $html = $subject->render(); static::assertContains($body, $html); } }