@@ -50,6 +50,22 @@ public function validateSuccessProvider() {
50
50
);
51
51
}
52
52
53
+ /**
54
+ * Provide data to test autoshortening feature
55
+ *
56
+ * @return array
57
+ */
58
+ public function generateAutoTitleProvider () {
59
+ return [
60
+ ['https://foobar.com ' , 'foobar.com ' ],
61
+ ['https://foobar.com/ ' , 'foobar.com ' ],
62
+ ['https://www.foobar.com/ ' , 'foobar.com ' ],
63
+ ['https://www.foobar.com/test ' , 'foobar.com/… ' ],
64
+ ['https://www.foobar.com/?test ' , 'foobar.com/… ' ],
65
+ ['https://www.foobar.com/#hash ' , 'foobar.com/… ' ],
66
+ ];
67
+ }
68
+
53
69
/**
54
70
* @expectedException \dokuwiki\plugin\struct\meta\ValidationException
55
71
* @dataProvider validateFailProvider
@@ -67,4 +83,26 @@ public function test_validate_success($value, $prefix, $postfix, $autoscheme) {
67
83
$ url ->validate ($ value );
68
84
$ this ->assertTrue (true ); // we simply check that no exceptions are thrown
69
85
}
86
+
87
+ /**
88
+ * @dataProvider generateAutoTitleProvider
89
+ */
90
+ public function test_generateAutoTitle ($ input , $ title ) {
91
+ $ url = new Url (['autoshorten ' => true ]);
92
+ $ result = $ this ->callInaccessibleMethod ($ url , 'generateTitle ' , [$ input ]);
93
+ $ this ->assertSame ($ title , $ result );
94
+
95
+ $ url = new Url (['autoshorten ' => false ]);
96
+ $ result = $ this ->callInaccessibleMethod ($ url , 'generateTitle ' , [$ input ]);
97
+ $ this ->assertSame ($ input , $ result );
98
+ }
99
+
100
+ public function test_generateFixedTitle () {
101
+ $ input = 'https://www.foobar.com/long ' ;
102
+ $ title = 'oink ' ;
103
+
104
+ $ url = new Url (['fixedtitle ' => $ title ]);
105
+ $ result = $ this ->callInaccessibleMethod ($ url , 'generateTitle ' , [$ input ]);
106
+ $ this ->assertSame ($ title , $ result );
107
+ }
70
108
}
0 commit comments