['player', 'isp', 'container'], 'admin/line_activity' => ['player', 'isp', 'container'], 'admin/stream_view' => ['player', 'isp', 'container'], 'admin/server_view' => ['player', 'isp', 'container'], 'admin/asns' => ['isp', 'domain', 'type'], 'reseller/line_activity' => ['player', 'isp', 'container'], 'reseller/live_connections' => ['player', 'isp', 'container'], 'reseller/dashboard' => ['stream_name', 'player', 'isp', 'container'], ]; private function source(string $rView): string { return (string) file_get_contents(MAIN_HOME . 'Public/Views/' . $rView . '.php'); } public function testStoredTextIsWrittenToTheTablesAsText(): void { $rAsMarkup = []; foreach (self::TABLES as $rView => $rText) { // One definition: `{ data: '', ... }`, a render function's body being the only braces inside. preg_match_all('/\{\s*data: \'(\w+)\'((?:[^{}]|\{[^{}]*\})*)\}/', $this->source($rView), $rColumns, PREG_SET_ORDER); $rSeen = []; foreach ($rColumns as [, $rColumn, $rRest]) { if (in_array($rColumn, $rText, true)) { $rSeen[] = $rColumn; if (!preg_match('/render:\s*esc\b/', $rRest)) { $rAsMarkup[] = $rView . ': ' . $rColumn; } } } $this->assertSame([], array_values(array_diff($rText, $rSeen)), $rView . ' has these columns'); } $this->assertSame([], $rAsMarkup); } public function testTheHelperEncodesTheQuoteCharactersToo(): void { $rLeft = []; foreach (array_keys(self::TABLES) as $rView) { $this->assertSame(1, preg_match('/\bvar esc = function\(s\) \{(.*?)\};/s', $this->source($rView), $rHelper), $rView . ' has one helper named esc'); foreach (['"' => '/"|�?34;/', "'" => '/�?39;|'/'] as $rCharacter => $rEncoded) { if (!preg_match($rEncoded, $rHelper[1])) { $rLeft[] = $rView . ': ' . $rCharacter; } } } $this->assertSame([], $rLeft); } }