Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CopyrightTest.php
Go to the documentation of this file.
1 <?php
10 namespace Magento\Test\Legacy;
11 
12 class CopyrightTest extends \PHPUnit\Framework\TestCase
13 {
14  public function testCopyright()
15  {
16  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
17  $invoker(
18  function ($filename) {
19  $fileText = file_get_contents($filename);
20  if (strpos($fileText, 'Copyright © Magento, Inc. All rights reserved.') === false) {
21  $this->fail('Copyright is missing or has wrong format ' . $filename);
22  }
23  },
24  $this->copyrightDataProvider()
25  );
26  }
27 
28  public function copyrightDataProvider()
29  {
30  $blackList = $this->getFilesData('blacklist*.php');
31 
32  $changedFiles = [];
33  foreach (glob(__DIR__ . '/../_files/changed_files*') as $listFile) {
34  $changedFiles = array_merge($changedFiles, file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
35  }
36  array_walk(
38  function (&$file) {
39  $file = [BP . '/' . $file];
40  }
41  );
42  $changedFiles = array_filter(
44  function ($path) use ($blackList) {
45  if (!file_exists($path[0]) || !is_readable($path[0])) {
46  return false;
47  }
48  $path[0] = realpath($path[0]);
49  foreach ($blackList as $item) {
50  if (preg_match($item, $path[0])) {
51  return false;
52  }
53  }
54  return true;
55  }
56  );
57  return $changedFiles;
58  }
59 
64  protected function getFilesData($filePattern)
65  {
66  $result = [];
67  foreach (glob(__DIR__ . '/_files/copyright/' . $filePattern) as $file) {
68  $fileData = include $file;
69  $result = array_merge($result, $fileData);
70  }
71  return $result;
72  }
73 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
const BP
Definition: autoload.php:14