PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/_build/test/Tests/Processors/Browser/DirectoryTest.php

http://github.com/modxcms/revolution
PHP | 195 lines | 115 code | 12 blank | 68 comment | 12 complexity | 7910a51db53925e8a7928293c3cbd9c9 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of the MODX Revolution package.
  4. *
  5. * Copyright (c) MODX, LLC
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. *
  10. * @package modx-test
  11. */
  12. /**
  13. * Tests related to browser/directory/ processors
  14. *
  15. * @package modx-test
  16. * @subpackage modx
  17. * @group Processors
  18. * @group BrowserProcessors
  19. */
  20. class BrowserDirectoryProcessorsTest extends MODxTestCase {
  21. const PROCESSOR_LOCATION = 'browser/directory/';
  22. public static function setUpBeforeClass() {
  23. @rmdir(MODX_BASE_PATH.'assets/test2/');
  24. @rmdir(MODX_BASE_PATH.'assets/test3/');
  25. @rmdir(MODX_BASE_PATH.'assets/test4/');
  26. }
  27. /**
  28. * Cleanup data after this test case.
  29. */
  30. public static function tearDownAfterClass() {
  31. @rmdir(MODX_BASE_PATH.'assets/test2/');
  32. @rmdir(MODX_BASE_PATH.'assets/test3/');
  33. @rmdir(MODX_BASE_PATH.'assets/test4/');
  34. }
  35. public function setUp() {
  36. parent::setUp();
  37. try {
  38. } catch (Exception $e) {
  39. $this->modx->log(modX::LOG_LEVEL_ERROR, $e->getMessage(), '', __METHOD__, __FILE__, __LINE__);
  40. }
  41. }
  42. /**
  43. * Tests the browser/directory/create processor, which creates a directory
  44. * @param string $dir
  45. * @dataProvider providerCreateDirectory
  46. */
  47. public function testCreateDirectory($dir = '') {
  48. if (empty($dir)) {
  49. $this->fail('Empty data set!');
  50. return;
  51. }
  52. $result = $this->modx->runProcessor(self::PROCESSOR_LOCATION.'create',array(
  53. 'name' => $dir,
  54. ));
  55. if (empty($result)) {
  56. $this->fail('Could not load '.self::PROCESSOR_LOCATION.'create processor');
  57. }
  58. $s = $this->checkForSuccess($result);
  59. $this->assertTrue($s,'Could not create directory '.$dir.' in browser/directory/create test: '.$result->getMessage());
  60. }
  61. /**
  62. * Data provider for create processor test.
  63. * @return array
  64. */
  65. public function providerCreateDirectory() {
  66. return array(
  67. array('assets/test2'),
  68. array('assets/test3'),
  69. );
  70. }
  71. /**
  72. * Tests the browser/directory/update processor, which renames a directory
  73. *
  74. * @TODO Fix this test.
  75. *
  76. * @param string $oldDirectory
  77. * @param string $newDirectory
  78. * @depends testCreateDirectory
  79. * @dataProvider providerUpdateDirectory
  80. */
  81. public function testUpdateDirectory($oldDirectory = '',$newDirectory = '') {
  82. $this->markTestSkipped(
  83. 'The test is skipped - testUpdateDirectory.'
  84. );
  85. return;
  86. if (empty($oldDirectory) || empty($newDirectory)) return;
  87. $adir = $this->modx->getOption('base_path').$oldDirectory;
  88. @mkdir($adir);
  89. if (!file_exists($adir)) {
  90. $this->fail('Old directory could not be created for test: '.$adir);
  91. }
  92. $result = $this->modx->runProcessor(self::PROCESSOR_LOCATION.'update',array(
  93. 'dir' => $oldDirectory,
  94. 'name' => $this->modx->getOption('base_path').$newDirectory,
  95. ));
  96. if (empty($result)) {
  97. $this->fail('Could not load '.self::PROCESSOR_LOCATION.'update processor');
  98. }
  99. $s = $this->checkForSuccess($result);
  100. $this->assertTrue($s,'Could not rename directory '.$oldDirectory.' to '.$newDirectory.' in browser/directory/update test: '.$result->getMessage());
  101. }
  102. /**
  103. * Data provider for update processor test
  104. * @return array
  105. */
  106. public function providerUpdateDirectory() {
  107. return array(
  108. array('assets/test3/','assets/test4'),
  109. );
  110. }
  111. /**
  112. * Tests the browser/directory/remove processor, which removes a directory
  113. * @param string $dir
  114. * @dataProvider providerRemoveDirectory
  115. * @depends testCreateDirectory
  116. * @depends testUpdateDirectory
  117. */
  118. public function testRemoveDirectory($dir = '') {
  119. if (empty($dir)) return;
  120. $this->modx->setOption('filemanager_path','');
  121. $this->modx->setOption('filemanager_url','');
  122. $this->modx->setOption('rb_base_dir','');
  123. $this->modx->setOption('rb_base_url','');
  124. $adir = $this->modx->getOption('base_path').$dir;
  125. @mkdir($adir);
  126. if (!file_exists($adir)) {
  127. $this->fail('Old directory could not be created for test: '.$adir);
  128. }
  129. $result = $this->modx->runProcessor(self::PROCESSOR_LOCATION.'remove',array(
  130. 'dir' => $dir,
  131. ));
  132. if (empty($result)) {
  133. $this->fail('Could not load '.self::PROCESSOR_LOCATION.'remove processor');
  134. }
  135. $s = $this->checkForSuccess($result);
  136. $this->assertTrue($s,'Could not remove directory: `'.$dir.'`: '.$result->getMessage());
  137. }
  138. /**
  139. * Data provider for remove processor test.
  140. * @return array
  141. */
  142. public function providerRemoveDirectory() {
  143. return array(
  144. array('assets/test2'),
  145. array('assets/test4'),
  146. );
  147. }
  148. /**
  149. * Tests the browser/directory/getList processor
  150. *
  151. * @dataProvider providerGetDirectoryList
  152. * @param string $dir A string path to the directory to list.
  153. * @param boolean $shouldWork True if the directory list should not be empty.
  154. */
  155. public function testGetDirectoryList($dir,$shouldWork = true) {
  156. /** @var modProcessorResponse $response */
  157. $response = $this->modx->runProcessor(self::PROCESSOR_LOCATION.'getlist',array(
  158. 'id' => $dir,
  159. ));
  160. if (empty($response)) {
  161. $this->fail('Could not load '.self::PROCESSOR_LOCATION.'getlist processor');
  162. }
  163. $dirs = $this->modx->fromJSON($response->getResponse());
  164. /* ensure correct test result */
  165. if ($shouldWork) {
  166. $success = !empty($dirs);
  167. } else {
  168. $success = empty($dirs);
  169. }
  170. $this->assertTrue($success,'Could not get list of files and dirs for '.$dir.' in browser/directory/getList test');
  171. }
  172. /**
  173. * Test data provider for getList processor
  174. * @return array
  175. */
  176. public function providerGetDirectoryList() {
  177. return array(
  178. array('manager/',true),
  179. array('manager/assets',true),
  180. array('fakedirectory/',false),
  181. );
  182. }
  183. }