uwdoem / test-suite

0.0.4 2016-11-03 16:33 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:06 UTC


README

Build Status Code Climate Test Coverage Latest Stable Version

TestSuite

PHPUnit 网页测试用例类,用于 UWDOEM 项目,采用 Athens 网页框架。

用法

此库已在 Packagist 上发布。要使用 Composer 安装,请在 "require-dev" 依赖中添加 "uwdoem/test-suite": "0.*"

{
    "require-dev": {
        ...
        "uwdoem/test-suite": "0.*",
        ...
    }
}

示例

以下是一个示例测试文件,它使用了 WebTestCase 类

<?php

use UWDOEM\TestSuite\WebTestCase;

class WebTest extends WebTestCase
{

    /**
     * Initialize the browser window
     *
     * @return void
     */
    protected function setUp()
    {
        $this->setBrowser('firefox');
        $this->setBrowserUrl('http://localhost:8001/');
    }

    /**
     * A test class using WebTestCase shall be able to visit a page and retrieve
     * the title.
     *
     * @return void
     */
    public function testTitle()
    {
        $this->url('/form.php');
        $this->assertEquals('Form', $this->title());
    }
    
    /**
     * A test class using WebTestCase shall be able to fill a form with random
     * data, and submit.
     *
     * @return void
     */
    public function testFormFill()
    {
        $this->url('/form.php');
        $this->assertEquals('Form', $this->title());

        $values = $this->fillForm();

        $this->element($this->using('css selector')->value('input[type=submit]'))->click();

        $body = $this->element($this->using('css selector')->value('body'))->attribute('innerHTML');

        foreach ($values as $value) {
            $this->assertContains($value, $body);
        }
    }
    
}