Further modules included.
[yaffs-website] / web / modules / contrib / libraries / tests / modules / libraries_test / src / Controller / ExampleController.php
1 <?php
2
3 namespace Drupal\libraries_test\Controller;
4
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7
8 class ExampleController implements ContainerInjectionInterface {
9
10   /**
11    * Injects BookManager Service.
12    */
13   public static function create(ContainerInterface $container) {
14     return new static();
15   }
16
17   /**
18    * Loads a specified library (variant) for testing.
19    *
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
23    * more information.
24    */
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.
29     $output = '';
30
31     // For easer debugging of JS loading, a text is shown that the JavaScript will
32     // replace.
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.';
36     $output .= '</div>';
37
38     // For easier debugging of CSS loading, the loaded CSS files will color the
39     // following text.
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:';
43     $output .= '<ul>';
44     // Do not reference the actual CSS files (i.e. including '.css'), because that
45     // breaks testing.
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>';
51     $output .= '</ul>';
52     $output .= '</div>';
53
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:';
57     $output .= '<ul>';
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>';
62       }
63     }
64     $output .= '</ul>';
65     $output .= '</div>';
66
67     return ['#markup' => $output];
68   }
69
70   public function files() {
71     return $this->buildPage('example_files');
72   }
73
74   public function integration() {
75     return $this->buildPage('example_integration_files');
76   }
77
78   public function versions() {
79     return $this->buildPage('example_versions');
80   }
81
82   public function variant() {
83     return $this->buildPage('example_variant', 'example_variant');
84   }
85
86   public function versionsAndVariants() {
87     return $this->buildPage('example_versions_and_variants', 'example_variant_2');
88   }
89
90   public function cache() {
91     return $this->buildPage('example_callback');
92   }
93
94 }