PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / minify / tests / TestCase.php

TestCase.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/mrclay/minify/tests/TestCase.php

74 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Minify\Test;
4
5 use Minify_CacheInterface;
6
7 abstract class TestCase extends \PHPUnit\Framework\TestCase
8 {
9 /** @var string */
10 protected static $document_root;
11 /** @var string */
12 protected static $test_files;
13
14 public static function setupBeforeClass()
15 {
16 self::$document_root = __DIR__;
17 self::$test_files = __DIR__ . '/_test_files';
18 }
19
20 /**
21 * Get number of bytes in a string regardless of mbstring.func_overload
22 *
23 * @param string $str
24 * @return int
25 */
26 protected function countBytes($str)
27 {
28 return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
29 ? mb_strlen($str, '8bit')
30 : strlen($str);
31 }
32
33 /**
34 * Common assertion for cache tests.
35 *
36 * @param Minify_CacheInterface $cache
37 * @param string $id
38 * @param string $data
39 */
40 protected function assertTestCache(Minify_CacheInterface $cache, $id, $data)
41 {
42 $this->assertTrue($cache->store($id, $data), "$id store");
43 $this->assertEquals($cache->getSize($id), $this->countBytes($data), "$id getSize");
44 $this->assertTrue($cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), "$id isValid");
45
46 ob_start();
47 $cache->display($id);
48 $displayed = ob_get_contents();
49 ob_end_clean();
50
51 $this->assertSame($data, $displayed, "$id display");
52 $this->assertEquals($data, $cache->fetch($id), "$id fetch");
53 }
54
55 /**
56 * Read data file, assert that it exists and is not empty.
57 * As a side effect calls trim() to fight against different Editors that insert or strip final newline.
58 *
59 * @param string $filename
60 * @return string
61 */
62 protected function getDataFile($filename)
63 {
64 $path = self::$test_files . '/' . $filename;
65 $this->assertFileExists($path);
66 $contents = file_get_contents($path);
67 $this->assertNotEmpty($contents);
68 $contents = trim($contents);
69 $this->assertNotEmpty($contents);
70
71 return $contents;
72 }
73 }
74