Etemplate url widget tests

This commit is contained in:
nathangray 2017-09-07 09:08:53 -06:00
parent c656d13a4c
commit 0ead3713e2
2 changed files with 187 additions and 0 deletions

View File

@ -0,0 +1,179 @@
<?php
/**
* Test for URL widget
*
* @link http://www.egroupware.org
* @author Nathan Gray
* @package api
* @subpackage etemplate
* @copyright (c) 2017 Nathan Gray
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/
namespace EGroupware\Api\Etemplate\Widget;
require_once realpath(__DIR__.'/../../test/WidgetBaseTest.php');
use EGroupware\Api\Etemplate;
class UrlTest extends \EGroupware\Api\Etemplate\WidgetBaseTest
{
const TEST_TEMPLATE = 'api.url_test';
/**
* Test the widget's basic functionality - we put data in, it comes back
* unchanged.
*
* @dataProvider validProvider
*/
public function testBasic($content)
{
// Instanciate the template
$etemplate = new Etemplate();
$etemplate->read(static::TEST_TEMPLATE, 'test');
// Send it around
$result = $this->mockedRoundTrip($etemplate, array('widget' => $content));
// Test it
$this->validateTest($result, array('widget' => $content));
}
/**
* Test that the widget does not return a value if readonly
*/
public function testReadonly()
{
// Instanciate the template
$etemplate = new Etemplate();
$etemplate->read(static::TEST_TEMPLATE, 'test');
// Exec
$content = array(
'widget' => 'google.com',
);
$result = $this->mockedRoundTrip($etemplate, $content, array(), array('widget' => true));
// Check
$this->assertEquals(array(), $result);
}
/**
* Check validation with failing strings
*
* @param type $content
* @param type $validation_errors
*
* @dataProvider invalidProvider
*/
public function testValidation($content)
{
// Instanciate the template
$etemplate = new Etemplate();
$etemplate->read(static::TEST_TEMPLATE, 'test');
$content = array('widget' => $content);
$this->validateRoundTrip($etemplate, Array(), $content, Array(), array_flip(array_keys($content)));
}
/**
* URL samples from https://mathiasbynens.be/demo/url-regex
*/
public function validProvider()
{
return array(
array('http://foo.com/blah_blah'),
array('http://foo.com/blah_blah/'),
array('http://foo.com/blah_blah_(wikipedia)'),
array('http://foo.com/blah_blah_(wikipedia)_(again)'),
array('http://www.example.com/wpstyle/?p=364'),
array('https://www.example.com/foo/?bar=baz&inga=42&quux'),
array('http://✪df.ws/123'),
array('http://userid:password@example.com:8080'),
array('http://userid:password@example.com:8080/'),
array('http://userid@example.com'),
array('http://userid@example.com/'),
array('http://userid@example.com:8080'),
array('http://userid@example.com:8080/'),
array('http://userid:password@example.com'),
array('http://userid:password@example.com/'),
array('http://142.42.1.1/'),
array('http://142.42.1.1:8080/'),
// We use filter_var, and it can't handle these
/*
array('http://➡.ws/䨹'),
array('http://⌘.ws'),
array('http://⌘.ws/'),
array('http://foo.com/blah_(wikipedia)#cite-1'),
array('http://foo.com/blah_(wikipedia)_blah#cite-1'),
array('http://foo.com/unicode_(✪)_in_parens'),
array('http://foo.com/(something)?after=parens'),
array('http://☺.damowmow.com/'),
array('http://code.google.com/events/#&product=browser'),
array('http://j.mp'),
array('ftp://foo.bar/baz'),
array('http://foo.bar/?q=Test%20URL-encoded%20stuff'),
array('http://مثال.إختبار '),
array('http://例子.测试'),
array('http://उदाहरण.परीक्षा'),
array("http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com"),
array('http://1337.net'),
array('http://a.b-c.de'),
array('http://223.255.255.254'),
*
*/
);
}
/**
* URL samples from https://mathiasbynens.be/demo/url-regex
*/
public function invalidProvider()
{
return array(
array('http://'),
array('http://.'),
array('http://..'),
array('http://../'),
array('http://?'),
array('http://??'),
array('http://??/'),
array('http://#'),
array('http://##'),
array('http://##/'),
array('http://foo.bar?q=Spaces should be encoded'),
array('//'),
array('//a'),
array('///a'),
array('///'),
array('http:///a'),
array('foo.com'),
array('rdar://1234'),
array('h://test'),
array('http:// shouldfail.com'),
array(':// should fail'),
array('http://foo.bar/foo(bar)baz quux'),
array('ftps://foo.bar/'),
array('http://-error-.invalid/'),
array('http://a.b--c.de/'),
array('http://-a.b.co'),
array('http://a.b-.co'),
array('http://0.0.0.0'),
array('http://10.1.1.0'),
array('http://10.1.1.255'),
array('http://224.1.1.1'),
array('http://1.1.1.1.1'),
array('http://123.123.123'),
array('http://3628126748'),
array('http://.www.foo.bar/'),
array('http://www.foo.bar./'),
array('http://.www.foo.bar./'),
array('http://10.1.1.1'),
array('http://10.1.1.254'),
);
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2//EN" "http://www.egroupware.org/etemplate2.dtd">
<!-- This template is used in automated testing -->
<overlay>
<template id="api.url_test" template="test" lang="" group="0" version="16.1">
<url id="widget"/>
</template>
</overlay>