Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ReleaseCheckListTest.php « Integration « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a54c8be82032404594d14037fca5dcf54a1164a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Tests\Integration;

use Exception;
use Matomo\Ini\IniReader;
use PHPUnit\Framework\TestCase;
use Piwik\AssetManager\UIAssetFetcher;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Filesystem;
use Piwik\Http;
use Piwik\Plugin;
use Piwik\Plugin\Manager;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tracker;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
 * @group Core
 * @group ReleaseCheckListTest
 */
class ReleaseCheckListTest extends \PHPUnit\Framework\TestCase
{
    private $globalConfig;

    const MINIMUM_PHP_VERSION = '7.2.5';

    public function setUp(): void
    {
        $iniReader = new IniReader();
        $this->globalConfig = $iniReader->readFile(PIWIK_PATH_TEST_TO_ROOT . '/config/global.ini.php');

        parent::setUp();
    }

    public function test_CustomVariablesAndProviderPluginCanBeUninstalledOnceNoLongerIncludedInPackage()
    {
        $pluginsToTest = ['CustomVariables', 'Provider'];

        $pluginManager = Plugin\Manager::getInstance();

        $package = Http::sendHttpRequest('https://raw.githubusercontent.com/matomo-org/matomo-package/master/scripts/build-package.sh', 20);

        foreach ($pluginsToTest as $pluginToTest) {
            $isPluginBundledWithCore = $pluginManager->isPluginBundledWithCore($pluginToTest);
            $isPluginIncludedInBuildZip = strpos($package, 'plugins/' . $pluginToTest) !== false;

            if ($isPluginBundledWithCore xor $isPluginIncludedInBuildZip) {
                throw new Exception('Expected that when plugin can be uninstalled (is not included in core), then the plugin is also included in the build-package.sh so it is included in the release zip. Once we no longer include this plugin in build.zip then we need to allow uninstalling these plugins by changing isPluginBundledWithCore method. Plugin is ' . $pluginToTest);
            }
        }

        $this->assertNotEmpty($isPluginBundledWithCore, 'We expect at least one plugin to be checked in this test, otherwise we can remove this test once they are no longer included in core');
    }

    public function test_TestCaseHasSetGroupsMethod()
    {
        // refs https://github.com/matomo-org/matomo/pull/16615 ensures setGroups method still exists in phpunit
        // checking this way as it is not an official API
        $this->assertTrue(method_exists(TestCase::class,'setGroups'));
    }

    public function test_woff2_fileIsUpToDate()
    {
        link(PIWIK_INCLUDE_PATH . "/plugins/Morpheus/fonts/matomo.ttf", "temp.ttf");
        $command = PIWIK_INCLUDE_PATH . "/../travis_woff2/woff2_compress 'temp.ttf'";
        $log = shell_exec($command);

        $this->assertFileEquals('temp.woff2', PIWIK_INCLUDE_PATH . "/plugins/Morpheus/fonts/matomo.woff2", "woff2 file is out of date.\nCommand output:\n" . $log);
    }

    public function test_minimumPHPVersion_isEnforced()
    {
        global $piwik_minimumPHPVersion;
        $this->assertEquals(self::MINIMUM_PHP_VERSION, $piwik_minimumPHPVersion, 'minimum PHP version global variable correctly defined');
    }

    public function test_minimumPhpVersion_isDefinedInComposerJson()
    {
        $composerJson = $this->getComposerJsonAsArray();
        // platform value is currently higher than minimum required php version to circumvent minimum requirement of wikimedia/less.php
        $this->assertEquals('7.2.9' /*self::MINIMUM_PHP_VERSION*/, $composerJson['config']['platform']['php']);

        $expectedRequirePhp = '>=' . self::MINIMUM_PHP_VERSION;
        $this->assertEquals($expectedRequirePhp, $composerJson['require']['php']);
    }

    public function test_icoFilesIconsShouldBeInPngFormat()
    {
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.ico');

        // filter favicon.ico as it may not be in PNG format which is fine
        $files = array_filter($files, function($value) { return !preg_match('/favicon.ico/', $value); });

        // filter source files for icon creation as they can be favicons
        $files = array_filter($files, function($value) { return !preg_match('~icons/src~', $value); });

        $this->checkFilesAreInPngFormat($files);
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/core', '*.ico');
        $this->checkFilesAreInPngFormat($files);
    }

    public function test_pngFilesIconsShouldBeInPngFormat()
    {
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.png');
        // filter expected screenshots as they might not be checked out and downloaded when stored in git-lfs
        $files = array_filter($files, function($value) {
            return !preg_match('/expected-screenshots/', $value) && !preg_match('~icons/src~', $value);
        });
        $this->checkFilesAreInPngFormat($files);
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/core', '*.png');
        $this->checkFilesAreInPngFormat($files);
    }

    public function test_gifFilesIconsShouldBeInGifFormat()
    {
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.gif');
        $this->checkFilesAreInGifFormat($files);
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/core', '*.gif');
        $this->checkFilesAreInGifFormat($files);
    }

    public function test_jpgImagesShouldBeInJpgFormat()
    {
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.jpg');
        $this->checkFilesAreInJpgFormat($files);
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/core', '*.jpg');
        $this->checkFilesAreInJpgFormat($files);
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.jpeg');
        $this->checkFilesAreInJpgFormat($files);
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/core', '*.jpeg');
        $this->checkFilesAreInJpgFormat($files);
    }

    public function test_screenshotsStoredInLfs()
    {
        $screenshots = Filesystem::globr(PIWIK_INCLUDE_PATH . '/tests/UI/expected-screenshots', '*.png');
        $screenshotsPlugins = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins/*/tests/UI/expected-screenshots', '*.png');
        $screenshots = array_merge($screenshots, $screenshotsPlugins);
        $cleanPath   = function ($value) {
            return str_replace(PIWIK_INCLUDE_PATH . '/', '', $value);
        };
        $screenshots = array_map($cleanPath, $screenshots);

        $lfsFiles = `git lfs ls-files`;
        if (empty($lfsFiles)) {
            $lfsFiles = `git lfs ls-files --exclude=`;
        }
        $submodules = `git submodule | awk '{ print $2 }'`;
        $submodules = explode("\n", $submodules);
        $storedLfsFiles = explode("\n", $lfsFiles);
        $cleanRevision  = function ($value) {
            $parts = explode(' ', $value);
            return array_pop($parts);
        };
        $storedLfsFiles = array_map($cleanRevision, $storedLfsFiles);

        foreach ($submodules as $submodule) {
            $submodule = trim(trim($submodule), './');
            if ($submodule === 'travis') {
                continue; // avoid error output for travis submodule
            }
            $pluginLfsFiles = shell_exec('cd ' . PIWIK_DOCUMENT_ROOT.'/'.$submodule . ' && git lfs ls-files');
            if (!empty($pluginLfsFiles)) {
                $pluginLfsFiles = explode("\n", $pluginLfsFiles);
                $pluginLfsFiles = array_map($cleanRevision, $pluginLfsFiles);
                $pluginLfsFiles = array_map(function ($val) use ($submodule) {
                    return $submodule . '/' . $val;
                }, $pluginLfsFiles);
                $storedLfsFiles = array_merge($storedLfsFiles, $pluginLfsFiles);
            }
        }

        $diff = array_diff($screenshots, $storedLfsFiles);
        $this->assertEmpty($diff, 'Some Screenshots are not stored in LFS: ' . implode("\n", $diff));
    }

    public function testCheckThatConfigurationValuesAreProductionValues()
    {
        $this->_checkEqual(array('Debug' => 'always_archive_data_day'), '0');
        $this->_checkEqual(array('Debug' => 'always_archive_data_period'), '0');
        $this->_checkEqual(array('Debug' => 'enable_sql_profiler'), '0');
        $this->_checkEqual(array('General' => 'time_before_today_archive_considered_outdated'), '900');
        $this->_checkEqual(array('General' => 'enable_browser_archiving_triggering'), '1');
        $this->_checkEqual(array('General' => 'default_language'), 'en');
        $this->_checkEqual(array('Tracker' => 'record_statistics'), '1');
        $this->_checkEqual(array('Tracker' => 'visit_standard_length'), '1800');
        $this->_checkEqual(array('Tracker' => 'trust_visitors_cookies'), '0');
        $this->_checkEqual(array('log' => 'log_level'), 'WARN');
        $this->_checkEqual(array('log' => 'log_writers'), array('screen'));
        $this->_checkEqual(array('log' => 'logger_api_call'), null);

        $this->assertFalse(defined('DEBUG_FORCE_SCHEDULED_TASKS'));

        // Check the index.php has "backtrace disabled"
        $content = file_get_contents(PIWIK_INCLUDE_PATH . "/index.php");
        $expected = "define('PIWIK_PRINT_ERROR_BACKTRACE', false);";
        $this->assertTrue( false !== strpos($content, $expected), 'index.php should contain: ' . $expected);
    }

    private function _checkEqual($key, $valueExpected)
    {
        $section = key($key);
        $optionName = current($key);
        $value = null;
        if (isset($this->globalConfig[$section][$optionName])) {
            $value = $this->globalConfig[$section][$optionName];
        }
        $this->assertEquals($valueExpected, $value, "$section -> $optionName was '" . var_export($value, true) . "', expected '" . var_export($valueExpected, true) . "'");
    }

    public function testTemplatesDontContainDebug()
    {
        $patternFailIfFound = 'dump(';
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.twig');
        foreach ($files as $file) {
            if ($file == PIWIK_INCLUDE_PATH . '/plugins/TestRunner/templates/travis.yml.twig') {
                continue;
            }

            $content = file_get_contents($file);
            $this->assertFalse(strpos($content, $patternFailIfFound), 'found in ' . $file);
        }
    }

    public function getTemplateFileExtensions()
    {
        $extensions = array(
            array('htm'),
            array('html'),
            array('twig'),
            array('tpl'),
        );
        return $extensions;
    }

    /**
     * @dataProvider getTemplateFileExtensions
     */
    public function testTemplatesDontContainJquery($extension)
    {
        $patternFailIfFound = 'jquery';

        // known files that will for sure not contain a "buggy" $patternFailIfFound
        $allowedFiles = array(
            PIWIK_INCLUDE_PATH . '/plugins/TestRunner/templates/travis.yml.twig',
            PIWIK_INCLUDE_PATH . '/plugins/CoreUpdater/templates/layout.twig',
            PIWIK_INCLUDE_PATH . '/plugins/Installation/templates/layout.twig',
            PIWIK_INCLUDE_PATH . '/plugins/Login/templates/loginLayout.twig',
            PIWIK_INCLUDE_PATH . '/plugins/SEO/tests/resources/whois_response.html',
            PIWIK_INCLUDE_PATH . '/plugins/SEO/tests/resources/whoiscom_response.html',
            PIWIK_INCLUDE_PATH . '/tests/UI/screenshot-diffs/singlediff.html',

            // Note: entries below are paths and any file within these paths will be automatically allowed
            PIWIK_INCLUDE_PATH . '/tests/resources/overlay-test-site-real/',
            PIWIK_INCLUDE_PATH . '/tests/resources/overlay-test-site/',
            PIWIK_INCLUDE_PATH . '/vendor/lox/xhprof/xhprof_html/docs/',
            PIWIK_INCLUDE_PATH . '/vendor/phpunit/php-code-coverage/tests',
            PIWIK_INCLUDE_PATH . '/plugins/Morpheus/icons/',
            PIWIK_INCLUDE_PATH . '/node_modules/',
        );

        $files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.' . $extension);
        $this->assertFilesDoNotContain($files, $patternFailIfFound, $allowedFiles);
    }

    /**
     * @param $files
     * @param $patternFailIfFound
     * @param $allowedFiles
     */
    private function assertFilesDoNotContain($files, $patternFailIfFound, $allowedFiles)
    {
        $foundPatterns = array();
        foreach ($files as $file) {
            if($this->isFileOrPathAllowed($allowedFiles, $file)) {
                continue;
            }
            $content = file_get_contents($file);
            $foundPattern = strpos($content, $patternFailIfFound) !== false;

            if($foundPattern) {
                $foundPatterns[] = $file;
            }
        }

        $this->assertEmpty($foundPatterns,
                sprintf("Forbidden pattern \"%s\" was found in the following files ---> please manually delete these files from Git. \n\n\t%s",
                    $patternFailIfFound,
                    implode("\n\t", $foundPatterns)
                )
        );
    }

    /**
     * @param $allowedFiles
     * @param $file
     * @return bool
     */
    private function isFileOrPathAllowed($allowedFiles, $file)
    {
        foreach ($allowedFiles as $allowedFile) {
            if (strpos($file, $allowedFile) === 0) {
                return true;
            }
        }
        return false;
    }


    public function testCheckThatGivenPluginsAreDisabledByDefault()
    {
        $pluginsShouldBeDisabled = array(
            'DBStats'
        );
        foreach ($pluginsShouldBeDisabled as $pluginName) {
            $this->assertNotContains($pluginName, $this->globalConfig['Plugins']['Plugins'],
                "Plugin $pluginName is enabled by default but shouldn't.");
        }
    }

    /**
     * test that the profiler is disabled (mandatory on a production server)
     */
    public function testProfilingDisabledInProduction()
    {
        require_once 'Tracker/Db.php';
        $this->assertTrue(\Piwik\Tracker\Db::isProfilingEnabled() === false, 'SQL profiler should be disabled in production! See Db::$profiling');
    }

    public function testPiwikTrackerDebugIsOff()
    {
        $this->assertTrue(!isset($GLOBALS['PIWIK_TRACKER_DEBUG']));
        $this->assertEquals(0, $this->globalConfig['Tracker']['debug']);

        $tracker = new Tracker();
        $this->assertFalse($tracker->isDebugModeEnabled());
    }

    /**
     * This tests that all PHP files start with <?php
     * This would help detect errors such as a php file starting with spaces
     */
    public function test_phpFilesStartWithRightCharacter()
    {
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.php');

        $tested = 0;
        foreach($files as $file) {
            // skip files in these folders
            if (strpos($file, '/libs/') !== false) {
                continue;
            }

            $handle = fopen($file, "r");
            $expectedStart = "<?php";

            $isIniFile = strpos($file, ".ini.php") !== false || strpos($file, ".ini.travis.php") !== false;
            if($isIniFile) {
                $expectedStart = "; <?php exit;";
            }

            $skipStartFileTest = $this->isSkipPhpFileStartWithPhpBlock($file, $isIniFile);

            if($skipStartFileTest) {
                continue;
            }

            $start = fgets($handle, strlen($expectedStart) + 1 );
            $this->assertEquals($start, $expectedStart, "File $file does not start with $expectedStart");
            $tested++;
        }

        $this->assertGreaterThan(2000, $tested, 'should have tested at least thousand of  php files');
    }

    public function test_jsfilesDoNotContainFakeSpaces()
    {
        $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.js');
        $this->checkFilesDoNotHaveWeirdSpaces($js);
    }

    public function test_phpfilesDoNotContainFakeSpaces()
    {
        $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.php');
        $this->checkFilesDoNotHaveWeirdSpaces($js);
    }

    public function test_twigfilesDoNotContainFakeSpaces()
    {
        $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.twig');
        $this->checkFilesDoNotHaveWeirdSpaces($js);
    }

    public function test_htmlfilesDoNotContainFakeSpaces()
    {
        $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.html');
        $this->checkFilesDoNotHaveWeirdSpaces($js);
    }

    public function test_directoriesShouldBeChmod755()
    {
        $pluginsPath = realpath(PIWIK_INCLUDE_PATH . '/plugins/');

        $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pluginsPath), RecursiveIteratorIterator::SELF_FIRST);
        $paths = array();
        foreach($objects as $name => $object){
            if (is_dir($name)
                && strpos($name, "/.") === false) {
                $paths[] = $name;
            }
        }

        $this->assertGreaterThan(50, count($paths), 'test at latest 50 directories, got ' . count($paths));

        // to prevent errors with un-readable assets,
        // we ensure all directories in plugins/* are added to git with CHMOD 755
        foreach($paths as $pathToTest) {

            $chmod = substr(decoct(fileperms($pathToTest)), -3);
            $valid = array('777', '775', '755');
            $command = "find $pluginsPath -type d -exec chmod 755 {} +";
            $this->assertTrue(in_array($chmod, $valid),
                    "Some directories within plugins/ are not chmod 755 \n\nGot: $chmod for : $pathToTest \n\n".
                    "Run this command to set all directories to 755: \n$command\n");;
        }
    }

    /**
     * Check that directories in plugins/ folder are specifically either enabled or disabled.
     *
     * This fails when a new folder is added to plugins/* and forgot to enable or mark as disabled in Manager.php.
     */
    public function test_DirectoriesInPluginsFolder_areKnown()
    {
        $pluginsBundledWithPiwik = Config::getInstance()->getFromGlobalConfig('Plugins');
        $pluginsBundledWithPiwik = $pluginsBundledWithPiwik['Plugins'];
        $magicPlugins = 42;
        $this->assertTrue(count($pluginsBundledWithPiwik) > $magicPlugins);

        $plugins = _glob(Manager::getPluginsDirectory() . '*', GLOB_ONLYDIR);
        $count = 1;
        foreach($plugins as $pluginPath) {
            $pluginName = basename($pluginPath);

            $addedToGit = $this->isPathAddedToGit($pluginPath);

            if(!$addedToGit) {
                // if not added to git, then it is not part of the release checklist.
                continue;
            }
            $manager = Manager::getInstance();
            $isGitSubmodule = $manager->isPluginOfficialAndNotBundledWithCore($pluginName);

            $pluginList = StaticContainer::get('Piwik\Application\Kernel\PluginList');

            $disabled = in_array($pluginName, $pluginList->getCorePluginsDisabledByDefault())  || $isGitSubmodule;

            $enabled = in_array($pluginName, $pluginsBundledWithPiwik);

            $this->assertTrue( $enabled + $disabled === 1,
                "Plugin $pluginName should be either enabled (in global.ini.php) or disabled (in Piwik\\Application\\Kernel\\PluginList).
                It is currently (enabled=".(int)$enabled. ", disabled=" . (int)$disabled . ")"
            );
            $count++;
        }
        $this->assertTrue($count > $magicPlugins);
    }

    public function testEndOfLines()
    {
        foreach (Filesystem::globr(PIWIK_DOCUMENT_ROOT, '*') as $file) {
            // skip files in these folders
            if (strpos($file, '/.git/') !== false ||
                strpos($file, '/documentation/') !== false ||
                strpos($file, '/tests/') !== false ||
                strpos($file, '/lang/') !== false ||
                strpos($file, 'yuicompressor') !== false ||
                (strpos($file, '/vendor') !== false && strpos($file, '/vendor/piwik') === false) ||
                strpos($file, '/tmp/') !== false ||
                strpos($file, '/node_modules/') !== false ||
                strpos($file, '/Morpheus/icons/src/') !== false ||
                strpos($file, '/phantomjs/') !== false
            ) {
                continue;
            }

            // skip files with these file extensions
            if (preg_match('/\.(bmp|fdf|gif|deb|deflate|exe|gz|ico|jar|jpg|p12|pdf|png|rar|swf|vsd|z|zip|ttf|so|dat|eps|phar|pyc|gzip|eot|woff|svg)$/', $file)) {
                continue;
            }

            if (!is_dir($file)) {
                $contents = file_get_contents($file);

                // expect CRLF
                if (preg_match('/\.(bat|ps1)$/', $file)) {
                    $contents = str_replace("\r\n", '', $contents);
                    $this->assertTrue(strpos($contents, "\n") === false, 'Incorrect line endings in ' . $file);
                } else {
                    // expect native
                    $hasWindowsEOL = strpos($contents, "\r\n");

                    // overwrite translations files with incorrect line endings
                    $this->assertTrue($hasWindowsEOL === false, 'Incorrect line endings \r\n found in ' . $file);
                }
            }
        }
    }

    public function testPiwikJavaScript()
    {
        // check source against Snort rule 8443
        // @see https://github.com/piwik/piwik/issues/2203
        $pattern = '/\x5b\x5c{2}.*\x5c{2}[\x22\x27]/';
        $contents = file_get_contents(PIWIK_DOCUMENT_ROOT . '/js/piwik.js');

        $this->assertTrue(preg_match($pattern, $contents) == 0);

        $contents = file_get_contents(PIWIK_DOCUMENT_ROOT . '/piwik.js');
        $this->assertTrue(preg_match($pattern, $contents) == 0);
    }

    public function test_piwikJs_minified_isUpToDate()
    {
        shell_exec("sed '/<DEBUG>/,/<\/DEBUG>/d' < ". PIWIK_DOCUMENT_ROOT ."/js/piwik.js | sed 's/eval/replacedEvilString/' | java -jar ". PIWIK_DOCUMENT_ROOT ."/tests/resources/yuicompressor/yuicompressor-2.4.8.jar --type js --line-break 1000 | sed 's/replacedEvilString/eval/' | sed 's/^[/][*]/\/*!/' > " . PIWIK_DOCUMENT_ROOT ."/piwik-minified.js");

        $this->assertFileEquals(PIWIK_DOCUMENT_ROOT . '/piwik-minified.js',
            PIWIK_DOCUMENT_ROOT . '/piwik.js',
            'minified /piwik.js is out of date, please re-generate the minified files using instructions in /js/README'
        );
        $this->assertFileEquals(PIWIK_DOCUMENT_ROOT . '/piwik-minified.js',
            PIWIK_DOCUMENT_ROOT . '/js/piwik.min.js',
            'minified /js/piwik.min.js is out of date, please re-generate the minified files using instructions in /js/README'
        );
    }

    public function test_piwikJs_SameAsMatomoJs()
    {
        $this->assertFileEquals(
            PIWIK_DOCUMENT_ROOT . '/matomo.js',
            PIWIK_DOCUMENT_ROOT . '/piwik.js',
            '/piwik.js does not match /matomo.js, please re-generate the minified files using instructions in /js/README'
        );
    }

    public function testTmpDirectoryContainsGitKeep()
    {
        $this->assertFileExists(PIWIK_DOCUMENT_ROOT . '/tmp/.gitkeep');
    }

    private function checkFilesAreInPngFormat($files)
    {
        $this->checkFilesAreInFormat($files, "png");
    }
    private function checkFilesAreInJpgFormat($files)
    {
        $this->checkFilesAreInFormat($files, "jpeg");
    }

    private function checkFilesAreInGifFormat($files)
    {
        $this->checkFilesAreInFormat($files, "gif");
    }

    private function checkFilesAreInFormat($files, $format)
    {
        $errors = array();
        foreach ($files as $file) {
            // skip files in these folders
            if (strpos($file, '/libs/') !== false) {
                continue;
            }

            $function = "imagecreatefrom" . $format;
            if (!function_exists($function)) {
                throw new \Exception("Unexpected error: $function function does not exist!");
            }

            $handle = @$function($file);
            if (empty($handle)) {
                $errors[] = $file;
            }
        }

        if (!empty($errors)) {
            $icons = implode(" ", $errors);
            $this->fail("$format format failed for following icons $icons \n");
        }

        $this->assertTrue(true); // pass
    }

    /**
     * @return bool
     */
    protected function isSkipPhpFileStartWithPhpBlock($file, $isIniFile)
    {
        $isIniFileInTests = strpos($file, "/tests/") !== false;
        $isTestResultFile = strpos($file, "/System/expected") !== false
            || strpos($file, "tests/resources/Updater/") !== false
            || strpos($file, "Twig/Tests/") !== false
            || strpos($file, "processed/") !== false
            || strpos($file, "/vendor/") !== false
            || (strpos($file, "tmp/") !== false && strpos($file, 'index.php') !== false);
        $isLib = strpos($file, "lib/xhprof") !== false || strpos($file, "phpunit/phpunit") !== false;

        return ($isIniFile && $isIniFileInTests) || $isTestResultFile || $isLib;
    }

    /**
     * @return bool
     */
    protected function isPathAddedToGit($pluginPath)
    {
        $gitOutput = shell_exec('git ls-files ' . $pluginPath . ' --error-unmatch 2>&1');
        $addedToGit = (strlen($gitOutput) > 0) && strpos($gitOutput, 'error: pathspec') === false;
        return $addedToGit;
    }


    /**
     * Tests that the Piwik files are not too big, to ensure the downloadable ZIP package is not too large
     */
    public function test_TotalPiwikFilesSize_isWithinReasonnableSize()
    {
        if(!SystemTestCase::isTravisCI()) {
            // Don't run the test on local dev machine, as we may have other files (not in GIT) that would fail this test
            $this->markTestSkipped("Skipped this test on local dev environment.");
        }
        $maximumTotalFilesizesExpectedInMb = 54;
        $minimumTotalFilesizesExpectedInMb = 38;
        $minimumExpectedFilesCount = 7000;

        $filesizes = $this->getAllFilesizes();
        $sumFilesizes = array_sum($filesizes);

        $filesOrderedBySize = $filesizes;
        arsort($filesOrderedBySize);

        $this->assertLessThan(
            $maximumTotalFilesizesExpectedInMb * 1024 * 1024,
            $sumFilesizes,
            sprintf("Sum of all files should be less than $maximumTotalFilesizesExpectedInMb Mb.
                    \nGot total file sizes of: %d Mb.
                    \nBiggest files: %s",
                $sumFilesizes / 1024 / 1024,
                var_export(array_slice($filesOrderedBySize, 0, 100, $preserveKeys = true), true)
            )
        );

        $this->assertGreaterThan($minimumExpectedFilesCount, count($filesizes), "Expected at least $minimumExpectedFilesCount files should be included in Piwik.");
        $this->assertGreaterThan($minimumTotalFilesizesExpectedInMb * 1024 * 1024, $sumFilesizes, "expected to have at least $minimumTotalFilesizesExpectedInMb Mb of files in Piwik codebase.");
    }

    public function test_noUpdatesInCorePlugins()
    {
        $manager = Manager::getInstance();
        $plugins = $manager->loadAllPluginsAndGetTheirInfo();

        $pluginsWithUnexpectedUpdates = array();
        $pluginsWithUpdates = array();
        $numTestedCorePlugins = 0;

        // eg these plugins are managed in a submodule and they are installing all tables/columns as part of their plugin install method etc.
        $corePluginsThatAreIndependent = array('TagManager', 'Provider', 'CustomVariables');

        foreach ($plugins as $pluginName => $info) {
            if ($manager->isPluginBundledWithCore($pluginName) && !in_array($pluginName, $corePluginsThatAreIndependent)) {
                $numTestedCorePlugins++;
                $pathToUpdates = Manager::getPluginDirectory($pluginName) . '/Updates/*.php';
                $files = _glob($pathToUpdates);
                if (empty($files)) {
                    $files = array();
                }

                foreach ($files as $file) {
                    $fileVersion = basename($file, '.php');
                    if (
                        version_compare('3.13.0', $fileVersion) != 1
                    ) {
                        // since matomo 3.13.0 we basically don't want to see any plugin specific updates for core plugins
                        // they should be instead in core/Updates/*
                        $pluginsWithUnexpectedUpdates[$pluginName] = $file;
                    } else {
                        $pluginsWithUpdates[] = $pluginName;
                    }
                }
            }
        }

        $this->assertSame(array(), $pluginsWithUnexpectedUpdates);

        // some assertions below to make sure we're actually doing valid tests and there is no bug in above code
        $this->assertGreaterThan(50, $numTestedCorePlugins);
        // eg this here shows the plugins that have update files but from older matomo versions.
        $this->assertSame(array('CustomDimensions', 'DevicesDetection', 'ExamplePlugin', 'Goals', 'LanguagesManager'), array_values(array_unique($pluginsWithUpdates)));
    }

    public function test_bowerComponentsBc_referencesFilesThatExists()
    {
        $filesThatDoNotExist = [];
        foreach (UIAssetFetcher::$bowerComponentFileMappings as $oldFile => $newFile) {
            if ($newFile && !file_exists(PIWIK_DOCUMENT_ROOT . '/' . $newFile)) {
                $filesThatDoNotExist[] = $newFile;
            }
        }

        $this->assertEmpty($filesThatDoNotExist, 'The following asset files in UIAssetFetcher::$bowerComponentFileMappings do not exist: '
            . implode(', ', $filesThatDoNotExist));
    }

    /**
     * @param $file
     * @return bool
     */
    private function isFileIncludedInFinalRelease($file)
    {
        if(is_dir($file)) {
            return false;
        }

        // in build-package.sh we have: `find ./ -iname 'tests' -type d -prune -exec rm -rf {} \;`
        if($this->isFileBelongToTests($file)) {
            return false;
        }
        if(strpos($file, PIWIK_INCLUDE_PATH . "/tmp/") !== false) {
            return false;
        }

        // ignore downloaded geoip files
        if((strpos($file, 'GeoIP') !== false || strpos($file, 'DBIP') !== false) && strpos($file, '.mmdb') !== false) {
            return false;
        }

        if($this->isFileIsAnIconButDoesNotBelongToDistribution($file)) {
            return false;
        }


        if($this->isPluginSubmoduleAndThereforeNotFoundInFinalRelease($file)) {
            return false;
        }

        if($this->isFileBelongToComposerDevelopmentPackage($file)) {
            return false;
        }

        if($this->isFileDeletedFromPackage($file)) {
            return false;
        }

        return true;
    }

    /**
     * Plugins Submodule in Piwik codebase are not there in the release package,
     * (the plugins are released on the Marketplace.)
     *
     * @param $file
     * @return bool
     */
    private function isPluginSubmoduleAndThereforeNotFoundInFinalRelease($file)
    {
        if(strpos($file, PIWIK_INCLUDE_PATH . "/plugins/") === false) {
            return false;
        }

        $pluginName = str_replace(PIWIK_INCLUDE_PATH . "/plugins/", "", $file);
        $pluginName = substr($pluginName, 0, strpos($pluginName, "/"));

        $this->assertNotEmpty($pluginName, "Detected an empty plugin name from path: $file ");

        $pluginManager = Manager::getInstance();
        $notInPackagedRelease = $pluginManager->isPluginOfficialAndNotBundledWithCore($pluginName);

        // test that the submodule check works
        if($pluginName == 'VisitorGenerator') {
            $this->assertTrue($notInPackagedRelease, "Expected isPluginOfficialAndNotBundledWithCore to return true for VisitorGenerator plugin");
        }
        return $notInPackagedRelease;
    }

    /**
     * @param $file
     * @return bool
     */
    private function isFileBelongToComposerDevelopmentPackage($file)
    {
        $composerDependencyDevOnly = $this->getComposerRequireDevPackages();

        return $this->isFilePathFoundInArray($file, $composerDependencyDevOnly);
    }

    /**
     * @return array
     */
    private function getComposerRequireDevPackages()
    {
        $composerJson = $this->getComposerJsonAsArray();
        $composerDependencyDevOnly = array_keys($composerJson["require-dev"]);
        return $composerDependencyDevOnly;
    }

    /**
     * return true if $file is found within any sub-string in $filesToMatchAgainst,
     *
     * @param $file
     * @param $filesToMatchAgainst array
     * @return bool
     */
    private function isFilePathFoundInArray($file, $filesToMatchAgainst)
    {
        foreach ($filesToMatchAgainst as $devPackageName) {
            if (strpos($file, $devPackageName) !== false || fnmatch(PIWIK_INCLUDE_PATH.'/'.$devPackageName, $file)) {
                return true;
            }
        }
        return false;
    }

    /**
     * @param $file
     * @return bool
     */
    private function isFileDeletedFromPackage($file)
    {
        $filesAndFoldersToDeleteFromPackage = [
            # Should stay synchronised with: https://github.com/matomo/matomo-package/blob/master/scripts/build-package.sh#L104-L116
            'composer.phar',
            'vendor/bin/',
            'vendor/twig/twig/test/',
            'vendor/twig/twig/doc/',
            'vendor/symfony/console/Symfony/Component/Console/Resources/bin',
            'vendor/tecnickcom/tcpdf/examples',
            'vendor/tecnickcom/tcpdf/CHANGELOG.TXT',
            'vendor/guzzle/guzzle/docs/',
            'vendor/davaxi/sparkline/tests',
            'vendor/php-di/php-di/benchmarks/',
            'vendor/geoip2/geoip2/.gitmodules',
            'vendor/geoip2/geoip2/.php_cs',
            'vendor/maxmind-db/reader/ext/',
            'vendor/maxmind-db/reader/autoload.php',
            'vendor/maxmind-db/reader/CHANGELOG.md',
            'vendor/maxmind/web-service-common/dev-bin/',
            'vendor/maxmind/web-service-common/CHANGELOG.md',
            'vendor/php-di/invoker/doc/',
            'vendor/szymach/c-pchart/doc',
            'vendor/leafo/lessphp/docs',
            'vendor/container-interop/container-interop/docs',
            'vendor/pear/archive_tar/docs',

            # Delete un-used files from the matomo-icons repository
            'plugins/Morpheus/icons/src*',
            'plugins/Morpheus/icons/tools*',
            'plugins/Morpheus/icons/flag-icon-css*',
            'plugins/Morpheus/icons/submodules*',
            'plugins/Morpheus/icons/.git*',
            'plugins/Morpheus/icons/.travis.yml',
            'plugins/Morpheus/icons/*.py',
            'plugins/Morpheus/icons/*.sh',
            'plugins/Morpheus/icons/*.json',
            'plugins/Morpheus/icons/*.lock',
            'plugins/Morpheus/icons/*.svg',
            'plugins/Morpheus/icons/*.txt',
            'plugins/Morpheus/icons/*.php',
            'plugins/Morpheus/icons/*.yml',

            'plugins/Example*',

            # Delete un-used fonts
            'vendor/tecnickcom/tcpdf/fonts/ae_fonts_2.0',
            'vendor/tecnickcom/tcpdf/fonts/dejavu-fonts-ttf-2.33',
            'vendor/tecnickcom/tcpdf/fonts/dejavu-fonts-ttf-2.34',
            'vendor/tecnickcom/tcpdf/fonts/freefont-20100919',
            'vendor/tecnickcom/tcpdf/fonts/freefont-20120503',
            'vendor/tecnickcom/tcpdf/fonts/freemon*',
            'vendor/tecnickcom/tcpdf/fonts/cid*',
            'vendor/tecnickcom/tcpdf/fonts/courier*',
            'vendor/tecnickcom/tcpdf/fonts/aefurat*',
            'vendor/tecnickcom/tcpdf/fonts/dejavusansb*',
            'vendor/tecnickcom/tcpdf/fonts/dejavusansi*',
            'vendor/tecnickcom/tcpdf/fonts/dejavusansmono*',
            'vendor/tecnickcom/tcpdf/fonts/dejavusanscondensed*',
            'vendor/tecnickcom/tcpdf/fonts/dejavusansextralight*',
            'vendor/tecnickcom/tcpdf/fonts/dejavuserif*',
            'vendor/tecnickcom/tcpdf/fonts/freesansi*',
            'vendor/tecnickcom/tcpdf/fonts/freesansb*',
            'vendor/tecnickcom/tcpdf/fonts/freeserifb*',
            'vendor/tecnickcom/tcpdf/fonts/freeserifi*',
            'vendor/tecnickcom/tcpdf/fonts/pdf*',
            'vendor/tecnickcom/tcpdf/fonts/times*',
            'vendor/tecnickcom/tcpdf/fonts/uni2cid*',

            'vendor/szymach/c-pchart/src/Resources/fonts/advent_light*',
            'vendor/szymach/c-pchart/src/Resources/fonts/Bedizen*',
            'vendor/szymach/c-pchart/src/Resources/fonts/calibri*',
            'vendor/szymach/c-pchart/src/Resources/fonts/Forgotte*',
            'vendor/szymach/c-pchart/src/Resources/fonts/MankSans*',
            'vendor/szymach/c-pchart/src/Resources/fonts/pf_arma_five*',
            'vendor/szymach/c-pchart/src/Resources/fonts/Silkscreen*',
            'vendor/szymach/c-pchart/src/Resources/fonts/verdana*',

            # not needed js files
            'node_modules/angular/angular.min.js.gzip',
            'node_modules/angular/angular.js',
            'node_modules/angular/bower.json',

            'node_modules/angular-animate/angular-animate.min.js.gzip',
            'node_modules/angular-animate/angular-animate.js',
            'node_modules/angular-animate/bower.json',

            'node_modules/angular-sanitize/angular-sanitize.min.js.gzip',
            'node_modules/angular-sanitize/angular-sanitize.js',
            'node_modules/angular-sanitize/bower.json',

            'node_modules/angular-cookies/angular-cookies.min.js.gzip',
            'node_modules/angular-cookies/angular-cookies.js',
            'node_modules/angular-cookies/bower.json',

            'node_modules/chroma-js/Makefile',
            'node_modules/chroma-js/bower.json',
            'node_modules/chroma-js/chroma.js',
            'node_modules/chroma-js/doc',
            'node_modules/chroma-js/readme.md',
            'node_modules/chroma-js/src',
            'node_modules/chroma-js/test',

            'node_modules/iframe-resizer/js/iframeResizer.contentWindow.js',
            'node_modules/iframe-resizer/js/iframeResizer.js',
            'node_modules/iframe-resizer/src/ie8.polyfils.js',
            'node_modules/iframe-resizer/src/iframeResizer.contentWindow.js',
            'node_modules/iframe-resizer/src/iframeResizer.js',
            'node_modules/iframe-resizer/test-main.js',
            'node_modules/iframe-resizer/bower.json',
            'node_modules/iframe-resizer/gruntfile.js',
            'node_modules/iframe-resizer/karma-conf.js',

            'node_modules/jquery/dist/jquery.js',
            'node_modules/jquery/bower.json',
            'node_modules/jquery/src',
            'node_modules/jquery/external/sizzle/dist/sizzle.js',

            'node_modules/jquery-ui-dist/component.json',
            'node_modules/jquery-ui-dist/external',
            'node_modules/jquery-ui-dist/images',
            'node_modules/jquery-ui-dist/index.html',
            'node_modules/jquery-ui-dist/jquery-ui.css',
            'node_modules/jquery-ui-dist/jquery-ui.js',
            'node_modules/jquery-ui-dist/jquery-ui.structure.css',
            'node_modules/jquery-ui-dist/jquery-ui.theme.css',

            'node_modules/jquery.browser/Gruntfile.js',
            'node_modules/jquery.browser/bower.json',
            'node_modules/jquery.browser/test',
            'node_modules/jquery.browser/dist/jquery.browser.js',

            'node_modules/jquery.dotdotdot/bower.json',
            'node_modules/jquery.dotdotdot/gulpfile.js',
            'node_modules/jquery.dotdotdot/index.html',
            'node_modules/jquery.dotdotdot/dotdotdot.jquery.json',
            'node_modules/jquery.dotdotdot/src/jquery.dotdotdot.js',
            'node_modules/jquery.dotdotdot/src/jquery.dotdotdot.min.umd.js',

            'node_modules/jquery.scrollto/jquery.scrollTo.js',
            'node_modules/jquery.scrollto/scrollTo.jquery.json',
            'node_modules/jquery.scrollto/bower.json',
            'node_modules/jquery.scrollto/changes.txt',
            'node_modules/jquery.scrollto/demo',
            'node_modules/jquery.scrollto/tests',

            'node_modules/materialize-css/Gruntfile.js',
            'node_modules/materialize-css/extras',
            'node_modules/materialize-css/js',
            'node_modules/materialize-css/sass',
            'node_modules/materialize-css/dist/js/materialize.js',
            'node_modules/materialize-css/dist/css/materialize.css',

            'node_modules/mousetrap/Gruntfile.js',
            'node_modules/mousetrap/mousetrap.js',
            'node_modules/mousetrap/tests',
            'node_modules/mousetrap/plugins',

            'node_modules/ng-dialog/CONTRIBUTING.md',
            'node_modules/ng-dialog/Gruntfile.js',
            'node_modules/ng-dialog/bower.json',
            'node_modules/ng-dialog/css',
            'node_modules/ng-dialog/example',
            'node_modules/ng-dialog/karma.conf.js',
            'node_modules/ng-dialog/protractor.conf.js',
            'node_modules/ng-dialog/server.js',
            'node_modules/ng-dialog/tests',

            'node_modules/qrcodejs2/bower.json',
            'node_modules/qrcodejs2/index-svg.html',
            'node_modules/qrcodejs2/index.html',
            'node_modules/qrcodejs2/index.svg',
            'node_modules/qrcodejs2/jquery.min.js',
            'node_modules/qrcodejs2/qrcode.js',

            'node_modules/sprintf-js/CONTRIBUTORS.MD',
            'node_modules/sprintf-js/README.md',
            'node_modules/sprintf-js/src',

            'node_modules/visibilityjs/ChangeLog.md',
            'node_modules/visibilityjs/component.json',
            'node_modules/visibilityjs/index.d.ts',
            'node_modules/visibilityjs/index.js',
            'node_modules/visibilityjs/README.md',

            'libs/jqplot/jqplot.core.js',
            'libs/jqplot/jqplot.lineRenderer.js',
            'libs/jqplot/jqplot.linearAxisRenderer.js',
            'libs/jqplot/jqplot.themeEngine.js',
            'libs/jqplot/plugins/jqplot.barRenderer.js',
            'libs/jqplot/plugins/jqplot.pieRenderer.js',

            'config/config.php',

            'libs/PhpDocumentor-1.3.2/',
            'libs/FirePHPCore/',
            'libs/open-flash-chart/php-ofc-library/ofc_upload_image.php',

            'tmp/*',
            'misc/updateLanguageFiles.sh',
            'misc/others/db-schema*',
            'misc/others/diagram_general_request*',
            '.coveralls.yml',
            '.scrutinizer.yml',
            '.phpstorm.meta.php',
            '.lfsconfig',
            'HIRING.md',
            '.github/',

        ];

        return $this->isFilePathFoundInArray($file, $filesAndFoldersToDeleteFromPackage);
    }

    /**
     * @return array
     * @throws Exception
     */
    private function getAllFilesizes()
    {
        $files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*');

        $filesizes = array();
        foreach ($files as $file) {

            if (!$this->isFileIncludedInFinalRelease($file)) {
                continue;
            }

            $filesize = filesize($file);

            if ($filesize === false) {
                throw new Exception("Error getting filesize for file: $file");
            }
            $filesizes[$file] = $filesize;
        }
        return $filesizes;
    }

    /**
     * @param $files
     * @throws Exception
     */
    protected function checkFilesDoNotHaveWeirdSpaces($files)
    {
        $weirdSpace = ' ';
        $this->assertEquals('c2a0', bin2hex($weirdSpace), "Checking that this test file was not tampered with");
        $this->assertEquals('20', bin2hex(' '), "Checking that this test file was not tampered with");

        $errors = array();
        $countFileChecked = 0;
        foreach ($files as $file) {

            if($this->isFileBelongToTests($file) || is_dir($file)) {
                continue;
            }

            if(strpos($file, 'vendor/php-di/php-di/website/') !== false
                || strpos($file, 'vendor/phpmailer/phpmailer/language/') !== false
                || strpos($file, 'vendor/wikimedia/less.php/') !== false
                || strpos($file, 'node_modules/') !== false
                || strpos($file, 'vendor/mayflower/mo4-coding-standard/') !== false
                || strpos($file, 'vendor/symfony/polyfill-iconv/') !== false
                || strpos($file, 'plugins/VisitorGenerator/vendor/fzaninotto/faker/src/Faker/Provider/') !== false) {
                continue;
            }

            $content = file_get_contents($file);
            $posWeirdSpace = strpos($content, $weirdSpace);
            if ($posWeirdSpace !== false) {
                $around = substr($content, $posWeirdSpace - 20, 40);
                $around = trim($around);
                $errors[] = "File $file contains an unusual space character, please remove it from here: ...$around...";
            }

            $countFileChecked++;
        }
        $this->assertTrue($countFileChecked > 42, "expected to test at least 100 files, but tested only " . $countFileChecked);

        if (!empty($errors)) {
            throw new Exception(implode(",\n\n ", $errors));
        }
    }

    /**
     * @param $file
     * @return bool
     */
    private function isFileBelongToTests($file)
    {
        return stripos($file, "/tests/") !== false || stripos($file, "/phantomjs/") !== false;
    }

    /**
     * @return mixed
     */
    private function getComposerJsonAsArray()
    {
        $composer = file_get_contents(PIWIK_INCLUDE_PATH . '/composer.json');
        $composerJson = json_decode($composer, $assoc = true);
        return $composerJson;
    }

    /**
     * ignore icon source files as they are large, but not included in the final package
     *
     */
    private function isFileIsAnIconButDoesNotBelongToDistribution($file)
    {
        return preg_match('~Morpheus/icons/(?!dist)~', $file);
    }

}