点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 行业软件>> 在线考试系统>> 源文件浏览
[免费版 Free] WebForm,下载次数:349 次 | 关键字: 考试 办公 高校 竞赛 企事业单位

源码截图

源码目录树

;
当前路径:vendor/topthink/framework/tests/ViewTest.php
<?php

namespace think\tests;

use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use think\App;
use think\Config;
use think\Container;
use think\contract\TemplateHandlerInterface;
use think\View;
use Mockery as m;

class ViewTest extends TestCase
{
    /** @var App|MockInterface */
    protected $app;

    /** @var View|MockInterface */
    protected $view;

    /** @var Config|MockInterface */
    protected $config;

    protected function tearDown(): void
    {
        m::close();
    }

    protected function setUp()
    {
        $this->app = m::mock(App::class)->makePartial();
        Container::setInstance($this->app);

        $this->app->shouldReceive('make')->with(App::class)->andReturn($this->app);
        $this->config = m::mock(Config::class)->makePartial();
        $this->app->shouldReceive('get')->with('config')->andReturn($this->config);

        $this->view = new View($this->app);
    }

    public function testAssignData()
    {
        $this->view->assign('foo', 'bar');
        $this->view->assign(['baz' => 'boom']);
        $this->view->qux = "corge";

        $this->assertEquals('bar', $this->view->foo);
        $this->assertEquals('boom', $this->view->baz);
        $this->assertEquals('corge', $this->view->qux);
        $this->assertTrue(isset($this->view->qux));
    }

    public function testRender()
    {
        $this->config->shouldReceive("get")->with("view.type", 'php')->andReturn(TestTemplate::class);

        $this->view->filter(function ($content) {
            return $content;
        });

        $this->assertEquals("fetch", $this->view->fetch('foo'));
        $this->assertEquals("display", $this->view->display('foo'));
    }

}

class TestTemplate implements TemplateHandlerInterface
{

    /**
     * 检测是否存在模板文件
     * @access public
     * @param string $template 模板文件或者模板规则
     * @return bool
     */
    public function exists(string $template): bool
    {
        return true;
    }

    /**
     * 渲染模板文件
     * @access public
     * @param string $template 模板文件
     * @param array  $data     模板变量
     * @return void
     */
    public function fetch(string $template, array $data = []): void
    {
        echo "fetch";
    }

    /**
     * 渲染模板内容
     * @access public
     * @param string $content 模板内容
     * @param array  $data    模板变量
     * @return void
     */
    public function display(string $content, array $data = []): void
    {
        echo "display";
    }

    /**
     * 配置模板引擎
     * @access private
     * @param array $config 参数
     * @return void
     */
    public function config(array $config): void
    {
        // TODO: Implement config() method.
    }

    /**
     * 获取模板引擎配置
     * @access public
     * @param string $name 参数名
     * @return void
     */
    public function getConfig(string $name)
    {
        // TODO: Implement getConfig() method.
    }
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号