viewTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. /**
  12. * view测试
  13. * @author mahuan <mahuan@d1web.top>
  14. */
  15. namespace tests\thinkphp\library\think;
  16. class viewTest extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * 句柄测试
  20. * @return mixed
  21. * @access public
  22. */
  23. public function testGetInstance()
  24. {
  25. \think\Cookie::get('a');
  26. $view_instance = \think\View::instance();
  27. $this->assertInstanceOf('\think\view', $view_instance, 'instance方法返回错误');
  28. }
  29. /**
  30. * 测试变量赋值
  31. * @return mixed
  32. * @access public
  33. */
  34. public function testAssign()
  35. {
  36. $view_instance = \think\View::instance();
  37. $view_instance->key = 'value';
  38. $this->assertTrue(isset($view_instance->key));
  39. $this->assertEquals('value', $view_instance->key);
  40. $data = $view_instance->assign(array('key' => 'value'));
  41. $data = $view_instance->assign('key2', 'value2');
  42. //测试私有属性
  43. $expect_data = array('key' => 'value', 'key2' => 'value2');
  44. $this->assertAttributeEquals($expect_data, 'data', $view_instance);
  45. }
  46. /**
  47. * 测试引擎设置
  48. * @return mixed
  49. * @access public
  50. */
  51. public function testEngine()
  52. {
  53. $view_instance = \think\View::instance();
  54. $data = $view_instance->engine('php');
  55. $data = $view_instance->engine(['type' => 'php', 'view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]);
  56. $php_engine = new \think\view\driver\Php(['view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]);
  57. $this->assertAttributeEquals($php_engine, 'engine', $view_instance);
  58. //测试模板引擎驱动
  59. $data = $view_instance->engine(['type' => 'think', 'view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]);
  60. $think_engine = new \think\view\driver\Think(['view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]);
  61. $this->assertAttributeEquals($think_engine, 'engine', $view_instance);
  62. }
  63. public function testReplace()
  64. {
  65. $view_instance = \think\View::instance();
  66. $view_instance->replace('string', 'replace')->display('string');
  67. }
  68. }