+ * Test the download callback with valid value, and retrieve_description option enabled.
+ */
+ public function testCurlDownloadCallbackOkWithDesc()
+ {
+ $callback = get_curl_download_callback(
+ $charset,
+ $title,
+ $desc,
+ $keywords,
+ true,
+ 'ut_curl_getinfo_ok'
+ );
+ $data = [
+ 'HTTP/1.1 200 OK',
+ 'Server: GitHub.com',
+ 'Date: Sat, 28 Oct 2017 12:01:33 GMT',
+ 'Content-Type: text/html; charset=utf-8',
+ 'Status: 200 OK',
+ 'th=device-width">'
+ . '<title>Refactoring · GitHub</title>'
+ . '<link rel="search" type="application/opensea',
+ 'end' => '<title>ignored</title>'
+ . '<meta name="description" content="link desc" />'
+ . '<meta name="keywords" content="key1,key2" />',
+ ];
+ foreach ($data as $key => $line) {
+ $ignore = null;
+ $expected = $key !== 'end' ? strlen($line) : false;
+ $this->assertEquals($expected, $callback($ignore, $line));
+ if ($expected === false) {
+ break;
+ }
+ }
+ $this->assertEquals('utf-8', $charset);
+ $this->assertEquals('Refactoring · GitHub', $title);
+ $this->assertEquals('link desc', $desc);
+ $this->assertEquals('key1 key2', $keywords);
+ }
+
+ /**
+ * Test the download callback with valid value, and retrieve_description option enabled,
+ * but no desc or keyword defined in the page.