public function testCreateContainerFunction() { // a config array in required format $config = array(array('type' => 'script', 'attributes' => array('path' => 'script1.js')), array('type' => 'script', 'attributes' => array('path' => 'script2.js')), array('type' => 'script', 'attributes' => array('inline' => 'alert("inline");')), array('type' => 'style', 'attributes' => array('path' => 'style1.css')), array('type' => 'style', 'attributes' => array('path' => 'style2.css', 'media' => 'screen'))); // make the object $container = Assets::createContainer($config, 'testCreateContainerFunction'); $output = $container->scripts(); $output .= $container->styles(); // we're going to do a direct compare here as there's loads to check $expected = '<script src="script1.js"></script> <script src="script2.js"></script> <script> alert("inline"); </script> <link rel="stylesheet" type="text/css" href="style1.css" /> <link rel="stylesheet" type="text/css" media="screen" href="style2.css" /> '; $this->assertEquals($output, $expected); // finally, prevent a duplicate name try { Assets::createContainer($config, 'testCreateContainerFunction'); } catch (Exception $e) { } }
<?php // includes and namespace. You'd normally autoload this via Composer include '../Assets.php'; include '../StaticAsset.php'; include '../Script.php'; include '../Style.php'; use Dmlogic\Assets\Assets; // get our config - this will differ by environment $collections = (include 'config.php'); /** * Here we create our collections by picking assets from those available * Output order is the order added */ $defaultAssets = Assets::createContainer($collections['default']); // or do this // $homeAssets = Assets::createContainer( $collections['home'], 'home' ); ?> <html> <head> <title>Assets sample</title> <?php // output collection styles echo $defaultAssets->styles(); ?> </head> <body>