*/ 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 |
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' => ['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' => [ 'Hello
'], 'background URL with position' => ['Hello
'], 'p.margin: 10 5 30 auto (no horizontal centering)' => ['Hi
'], 'p.border: none' => ['Hi
'], 'img.border: 1px solid black' => ['Hi
'], 'span.float' => ['Hi'], 'float: none' => ['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);
}
}