From 0ead3713e2dbf424af5b3338fbe1e458d18eb7ca Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 7 Sep 2017 09:08:53 -0600 Subject: [PATCH] Etemplate url widget tests --- api/src/Etemplate/Widget/test/UrlTest.php | 179 ++++++++++++++++++++++ api/templates/test/url_test.xet | 8 + 2 files changed, 187 insertions(+) create mode 100644 api/src/Etemplate/Widget/test/UrlTest.php create mode 100644 api/templates/test/url_test.xet diff --git a/api/src/Etemplate/Widget/test/UrlTest.php b/api/src/Etemplate/Widget/test/UrlTest.php new file mode 100644 index 0000000000..abbe65e8a3 --- /dev/null +++ b/api/src/Etemplate/Widget/test/UrlTest.php @@ -0,0 +1,179 @@ +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'), + ); + } +} diff --git a/api/templates/test/url_test.xet b/api/templates/test/url_test.xet new file mode 100644 index 0000000000..e40a8d2ce6 --- /dev/null +++ b/api/templates/test/url_test.xet @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file