PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dev/tests/integration/testsuite/MageTest.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 238 lines | 120 code | 18 blank | 100 comment | 1 complexity | e33a785bd72c385992be013607b88199 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Magento
  22. * @package Mage_Core
  23. * @subpackage integration_tests
  24. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  25. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  26. */
  27. class MageTest extends PHPUnit_Framework_TestCase
  28. {
  29. public function testIsInstalled()
  30. {
  31. $this->assertTrue(Mage::isInstalled());
  32. }
  33. /**
  34. * @param int|null $level
  35. * @param string $file
  36. * @param bool $forceLog
  37. * @param int $expectedLevel
  38. * @param string $expectedKey
  39. * @param bool $expectsAddLog
  40. * @dataProvider logDataProvider
  41. * @throws Exception
  42. */
  43. public function testLog($level, $file, $forceLog, $expectedLevel, $expectedKey, $expectsAddLog)
  44. {
  45. $message = uniqid();
  46. $objectManager = Mage::getObjectManager();
  47. /** @var $objectManager Magento_ObjectManager_Zend|PHPUnit_Framework_MockObject_MockObject */
  48. $mock = $this->getMock('Magento_ObjectManager_Zend', array('get'), array(), '', false);
  49. /** @var $logger Mage_Core_Model_Logger|PHPUnit_Framework_MockObject_MockObject */
  50. $logger = $this->getMock('Mage_Core_Model_Logger', array('log', 'addStreamLog'), array(), '', false);
  51. Mage::initializeObjectManager(null, $mock);
  52. try {
  53. $mock->expects($this->any())->method('get')->will($this->returnValue($logger));
  54. $logger->expects($this->once())->method('log')->with($message, $expectedLevel, $expectedKey);
  55. if ($expectsAddLog) {
  56. $logger->expects($this->once())->method('addStreamLog');
  57. }
  58. Mage::log($message, $level, $file, $forceLog);
  59. Mage::initializeObjectManager(null, $objectManager);
  60. } catch (Exception $e) {
  61. Mage::initializeObjectManager(null, $objectManager);
  62. throw $e;
  63. }
  64. }
  65. /**
  66. * @return array
  67. */
  68. public function logDataProvider()
  69. {
  70. return array(
  71. array(null, '', false, Zend_Log::DEBUG, Mage_Core_Model_Logger::LOGGER_SYSTEM, false),
  72. array(Zend_Log::CRIT, 'system.log', true, Zend_Log::CRIT, Mage_Core_Model_Logger::LOGGER_SYSTEM, false),
  73. array(null, 'exception.log', false, Zend_Log::DEBUG, Mage_Core_Model_Logger::LOGGER_EXCEPTION, false),
  74. array(null, 'custom.log', false, Zend_Log::DEBUG, 'custom.log', true, false),
  75. array(null, 'exception.log', true, Zend_Log::DEBUG, Mage_Core_Model_Logger::LOGGER_EXCEPTION, true),
  76. );
  77. }
  78. /**
  79. * @magentoConfigFixture current_store dev/log/active 1
  80. * @magentoConfigFixture current_store dev/log/file php://output
  81. * @link http://us3.php.net/manual/en/wrappers.php
  82. */
  83. public function testLogWrapper()
  84. {
  85. // @magentoConfigFixture is applied after initialization, so we need to do this again
  86. Magento_Test_Bootstrap::getInstance()->reinitialize();
  87. $this->expectOutputRegex('/test/');
  88. Mage::log('test');
  89. }
  90. /**
  91. * @magentoAppIsolation enabled
  92. */
  93. public function testLogWrapperDirectly()
  94. {
  95. $this->expectOutputRegex('/test/');
  96. Mage::log('test', null, 'php://output');
  97. }
  98. /**
  99. * @magentoConfigFixture current_store dev/log/active 1
  100. * @magentoConfigFixture global/log/core/writer_model Zend_Log_Writer_Mail
  101. * @magentoAppIsolation enabled
  102. */
  103. public function testLogUnsupportedWrapper()
  104. {
  105. // initialize again, because config fixture is applied after initialization
  106. Magento_Test_Bootstrap::getInstance()->reinitialize();
  107. $logEntry = microtime();
  108. Mage::log($logEntry);
  109. $logFile = Mage::getBaseDir('log') . '/system.log';
  110. $this->assertFileExists($logFile);
  111. $this->assertContains($logEntry, file_get_contents($logFile));
  112. }
  113. /**
  114. * @magentoConfigFixture current_store dev/log/active 1
  115. * @magentoConfigFixture current_store dev/log/exception_file php://output
  116. * @magentoAppIsolation enabled
  117. */
  118. public function testLogException()
  119. {
  120. // reinitialization is needed here, too
  121. Magento_Test_Bootstrap::getInstance()->reinitialize();
  122. $msg = uniqid();
  123. $exception = new Exception((string)$msg);
  124. Mage::logException($exception);
  125. $this->expectOutputRegex('/' . $msg . '/');
  126. }
  127. /**
  128. * @magentoAppIsolation enabled
  129. */
  130. public function testReset()
  131. {
  132. Mage::setRoot(dirname(__FILE__));
  133. $this->assertNotNull(Mage::getRoot());
  134. Mage::reset();
  135. $this->assertNull(Mage::getRoot());
  136. }
  137. /**
  138. * @magentoAppIsolation enabled
  139. *
  140. */
  141. public function testGetDesign()
  142. {
  143. $design = Mage::getDesign();
  144. $this->assertEquals('frontend', $design->getArea());
  145. $this->assertSame(Mage::getDesign(), $design);
  146. }
  147. /**
  148. * @param string $classId
  149. * @param string $expectedClassName
  150. * @dataProvider getModelDataProvider
  151. */
  152. public function testGetModel($classId, $expectedClassName)
  153. {
  154. $this->assertInstanceOf($expectedClassName, Mage::getModel($classId));
  155. }
  156. /**
  157. * @return array
  158. */
  159. public function getModelDataProvider()
  160. {
  161. return array(
  162. array('Mage_Core_Model_Config', 'Mage_Core_Model_Config')
  163. );
  164. }
  165. /**
  166. * @param string $classId
  167. * @param string $expectedClassName
  168. * @dataProvider getResourceModelDataProvider
  169. */
  170. public function testGetResourceModel($classId, $expectedClassName)
  171. {
  172. $this->assertInstanceOf($expectedClassName, Mage::getResourceModel($classId));
  173. }
  174. /**
  175. * @return array
  176. */
  177. public function getResourceModelDataProvider()
  178. {
  179. return array(
  180. array('Mage_Core_Model_Resource_Config', 'Mage_Core_Model_Resource_Config')
  181. );
  182. }
  183. /**
  184. * @param string $module
  185. * @param string $expectedClassName
  186. * @dataProvider getResourceHelperDataProvider
  187. */
  188. public function testGetResourceHelper($module, $expectedClassName)
  189. {
  190. $this->assertInstanceOf($expectedClassName, Mage::getResourceHelper($module));
  191. }
  192. /**
  193. * @return array
  194. */
  195. public function getResourceHelperDataProvider()
  196. {
  197. return array(
  198. array('Mage_Core', 'Mage_Core_Model_Resource_Helper_Abstract')
  199. );
  200. }
  201. /**
  202. * @param string $classId
  203. * @param string $expectedClassName
  204. * @dataProvider helperDataProvider
  205. */
  206. public function testHelper($classId, $expectedClassName)
  207. {
  208. $this->assertInstanceOf($expectedClassName, Mage::helper($classId));
  209. }
  210. /**
  211. * @return array
  212. */
  213. public function helperDataProvider()
  214. {
  215. return array(
  216. 'module name' => array('Mage_Core', 'Mage_Core_Helper_Data'),
  217. 'class name' => array('Mage_Core_Helper_Js', 'Mage_Core_Helper_Js'),
  218. );
  219. }
  220. }