3 namespace Drupal\libraries_test\Controller;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
8 class ExampleController implements ContainerInjectionInterface {
11 * Injects BookManager Service.
13 public static function create(ContainerInterface $container) {
18 * Loads a specified library (variant) for testing.
20 * JavaScript and CSS files can be checked directly by SimpleTest, so we only
21 * need to manually check for PHP files. We provide information about the loaded
22 * JavaScript and CSS files for easier debugging. See example/README.txt for
25 private function buildPage($library, $variant = NULL) {
26 libraries_load($library, $variant);
27 // JavaScript and CSS files can be checked directly by SimpleTest, so we only
28 // need to manually check for PHP files.
31 // For easer debugging of JS loading, a text is shown that the JavaScript will
33 $output .= '<h2>JavaScript</h2>';
34 $output .= '<div class="libraries-test-javascript">';
35 $output .= 'If this text shows up, no JavaScript test file was loaded.';
38 // For easier debugging of CSS loading, the loaded CSS files will color the
40 $output .= '<h2>CSS</h2>';
41 $output .= '<div class="libraries-test-css">';
42 $output .= 'If one of the CSS test files has been loaded, this text will be colored:';
44 // Do not reference the actual CSS files (i.e. including '.css'), because that
46 $output .= '<li>example_1: red</li>';
47 $output .= '<li>example_2: green</li>';
48 $output .= '<li>example_3: orange</li>';
49 $output .= '<li>example_4: blue</li>';
50 $output .= '<li>libraries_test: purple</li>';
54 $output .= '<h2>PHP</h2>';
55 $output .= '<div class="libraries-test-php">';
56 $output .= 'The following is a list of all loaded test PHP files:';
58 $files = get_included_files();
59 foreach ($files as $file) {
60 if ((strpos($file, 'libraries/test') || strpos($file, 'libraries_test')) && !strpos($file, 'libraries_test.module') && !strpos($file, 'lib/Drupal/libraries_test')) {
61 $output .= '<li>' . str_replace(DRUPAL_ROOT . '/', '', $file) . '</li>';
67 return ['#markup' => $output];
70 public function files() {
71 return $this->buildPage('example_files');
74 public function integration() {
75 return $this->buildPage('example_integration_files');
78 public function versions() {
79 return $this->buildPage('example_versions');
82 public function variant() {
83 return $this->buildPage('example_variant', 'example_variant');
86 public function versionsAndVariants() {
87 return $this->buildPage('example_versions_and_variants', 'example_variant_2');
90 public function cache() {
91 return $this->buildPage('example_callback');