Skip to content

Commit 3dd942a

Browse files
committed
fixed tests
1 parent 4943a51 commit 3dd942a

File tree

9 files changed

+4077
-6
lines changed

9 files changed

+4077
-6
lines changed

src/Embed.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ private static function process(Url $url, array $config, DispatcherInterface $di
7575
return new Adapters\Webpage($response, $config, $dispatcher);
7676
}
7777

78-
$exception = new Exceptions\InvalidUrlException(sprintf("Invalid url '%s' (Status code %s)", (string) $url, $response->getStatusCode()));
78+
if ($response->getError() === null) {
79+
$exception = new Exceptions\InvalidUrlException(sprintf("Invalid url '%s' (Status code %s)", (string) $url, $response->getStatusCode()));
80+
} else {
81+
$exception = new Exceptions\InvalidUrlException($response->getError());
82+
}
7983

8084
$exception->setResponse($response);
8185

src/Http/AbstractResponse.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ public function getInfo()
8484
return $this->info;
8585
}
8686

87+
/**
88+
* Returns dispatch error.
89+
*
90+
* @return string|null
91+
*/
92+
public function getError()
93+
{
94+
return empty($this->info['error']) ? null : $this->info['error'];
95+
}
96+
8797
/**
8898
* Get a header.
8999
*

src/Http/CurlDispatcher.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CurlDispatcher implements DispatcherInterface
1616
CURLOPT_MAXREDIRS => 10,
1717
CURLOPT_CONNECTTIMEOUT => 10,
1818
CURLOPT_TIMEOUT => 10,
19-
CURLOPT_SSL_VERIFYHOST => false,
19+
CURLOPT_SSL_VERIFYHOST => 0,
2020
CURLOPT_SSL_VERIFYPEER => false,
2121
CURLOPT_ENCODING => '',
2222
CURLOPT_AUTOREFERER => true,
@@ -89,6 +89,16 @@ public function dispatch(Url $url)
8989
return $this->exec($url, $options);
9090
}
9191

92+
//Other sites needs a certificate
93+
if ($response->getStatusCode() === 0 && strpos($response->getError(), 'SSL') !== false) {
94+
$options[CURLOPT_SSL_VERIFYHOST] = 2;
95+
$options[CURLOPT_SSL_VERIFYPEER] = true;
96+
//https://curl.haxx.se/docs/caextract.html
97+
$options[CURLOPT_CAINFO] = __DIR__.'/../resources/cacert.pem';
98+
99+
return $this->exec($url, $options);
100+
}
101+
92102
return $response;
93103
}
94104

src/Http/CurlResult.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function getResult()
3535
{
3636
$result = curl_getinfo($this->resource);
3737

38+
if (curl_errno($this->resource)) {
39+
$result['error'] = curl_error($this->resource);
40+
}
41+
3842
return [
3943
'url' => isset($result['url']) ? $result['url'] : null,
4044
'statusCode' => isset($result['http_code']) ? $result['http_code'] : null,

src/resources/cacert.pem

Lines changed: 4043 additions & 0 deletions
Large diffs are not rendered by default.

tests/ImagesBlacklistTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function testPlainText()
2222
public function testPlainUrlMatch()
2323
{
2424
$this->assertEmbed(
25-
'http://alistapart.com/article/the-rich-typefaces-get-richer',
25+
'https://alistapart.com/article/the-rich-typefaces-get-richer',
2626
[
27-
'image' => 'http://alistapart.com/d/_made/pix/authors/photos/shoaf-headshot_120_120_c1.jpg',
27+
'image' => 'https://alistapart.com/d/_made/pix/authors/photos/shoaf-headshot_120_120_c1.jpg',
2828
],
2929
[
3030
'images_blacklist' => [

tests/JsbinTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function testOne()
1313
'type' => 'rich',
1414
'providerName' => 'jsbin',
1515
'providerUrl' => 'http://jsbin.com',
16-
'code' => '<iframe src="http://output.jsbin.com/vonesu/10/embed" width="640" height="480" frameborder="0"></iframe>',
16+
'code' => '<iframe src="http://output.jsbin.com/vonesu/10/embed" width="320" height="240" frameborder="0"></iframe>',
1717
]
1818
);
1919
}

tests/WikipediaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class WikipediaTest extends AbstractTestCase
77
public function testOne()
88
{
99
$description = <<<'EOT'
10-
Albert Einstein (/ˈaɪnstaɪn/; German: [ˈalbɛɐ̯t ˈaɪnʃtaɪn]; 14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the general theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. Einstein is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed "the world's most famous equation"). He received the 1921 Nobel Prize in Physics "for his services to Theoretical Physics, and especially for his discovery of the law of the photoelectric effect", a pivotal step in the evolution of quantum theory. Near the beginning of his career, Einstein thought that Newtonian mechanics was no longer enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field. This led him to develop his special theory of relativity. He realized, however, that the principle of relativity could also be extended to gravitational fields, and...
10+
Albert Einstein (/ˈaɪnstaɪn/; German: [ˈalbɛɐ̯t ˈaɪnʃtaɪn]; 14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. Einstein is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed "the world's most famous equation"). He received the 1921 Nobel Prize in Physics "for his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect", a pivotal step in the evolution of quantum theory. Near the beginning of his career, Einstein thought that Newtonian mechanics was no longer enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field. This led him to develop his special theory of relativity. He realized, however, that the principle of relativity could also be extended to gravitational fields, and with...
1111
EOT;
1212

1313
$this->assertEmbed(

0 commit comments

Comments
 (0)