Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
WordsFinderTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class WordsFinderTest extends \PHPUnit\Framework\TestCase
11 {
18  public function testConstructorException($configFile, $baseDir)
19  {
20  new \Magento\TestFramework\Inspection\WordsFinder($configFile, $baseDir, new ComponentRegistrar());
21  }
22 
24  {
25  $fixturePath = __DIR__ . '/_files/';
26  return [
27  'non-existing config file' => [$fixturePath . 'non-existing.xml', $fixturePath],
28  'non-existing base dir' => [$fixturePath . 'config.xml', $fixturePath . 'non-existing-dir'],
29  'broken config' => [$fixturePath . 'broken_config.xml', $fixturePath],
30  'empty words config' => [$fixturePath . 'empty_words_config.xml', $fixturePath],
31  'empty whitelisted path' => [$fixturePath . 'empty_whitelisted_path.xml', $fixturePath]
32  ];
33  }
34 
41  public function testFindWords($configFiles, $file, $expected)
42  {
43  $wordsFinder = new \Magento\TestFramework\Inspection\WordsFinder(
44  $configFiles,
45  __DIR__ . '/_files/words_finder',
46  new ComponentRegistrar()
47  );
48  $actual = $wordsFinder->findWords($file);
49  $this->assertEquals($expected, $actual);
50  }
51 
55  public function findWordsDataProvider()
56  {
57  $mainConfig = __DIR__ . '/_files/config.xml';
58  $additionalConfig = __DIR__ . '/_files/config_additional.xml';
59  $basePath = __DIR__ . '/_files/words_finder/';
60  return [
61  'usual file' => [$mainConfig, $basePath . 'buffy.php', ['demon', 'vampire']],
62  'whitelisted file' => [$mainConfig, $basePath . 'twilight/eclipse.php', []],
63  'partially whitelisted file' => [$mainConfig, $basePath . 'twilight/newmoon.php', ['demon']],
64  'filename with bad word' => [
65  $mainConfig,
66  $basePath . 'interview_with_the_vampire.php',
67  ['vampire'],
68  ],
69  'binary file, having name with bad word' => [
70  $mainConfig,
71  $basePath . 'interview_with_the_vampire.zip',
72  ['vampire'],
73  ],
74  'words in multiple configs' => [
75  [$mainConfig, $additionalConfig],
76  $basePath . 'buffy.php',
77  ['demon', 'vampire', 'darkness'],
78  ],
79  'whitelisted paths in multiple configs' => [
80  [$mainConfig, $additionalConfig],
81  $basePath . 'twilight/newmoon.php',
82  ['demon'],
83  ],
84  'config must be whitelisted automatically' => [
85  $basePath . 'self_tested_config.xml',
86  $basePath . 'self_tested_config.xml',
87  [],
88  ]
89  ];
90  }
91 }
$baseDir
Definition: autoload.php:9
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
testFindWords($configFiles, $file, $expected)