Skip to content

Commit 2445f8c

Browse files
committed
added a way to detect unnecesary oembed providers
1 parent 908ff7f commit 2445f8c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/TestCaseBase.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Base class with custom utilities for testing.
55
*/
66
use Embed\Embed;
7+
use Embed\Request;
78

89
abstract class TestCaseBase extends PHPUnit_Framework_TestCase
910
{
@@ -76,5 +77,30 @@ protected function assertEmbed($url, array $info, array $config = array())
7677
throw new InvalidArgumentException("No valid {$name} assertion");
7778
}
7879
}
80+
81+
$this->assertOembedAutodiscover($i->getRequest());
82+
}
83+
84+
/**
85+
* This method allow to discover sites including the oembed endpoint in the code,
86+
* to remove the custom Oembed provider if exists.
87+
*/
88+
private function assertOembedAutodiscover(Request $request)
89+
{
90+
$className = $request->getClassNameForDomain();
91+
92+
//exceptions
93+
if (in_array($className, ['Wordpress', 'Youtube'])) {
94+
return;
95+
}
96+
97+
$class = 'Embed\\Providers\\OEmbed\\'.$className;
98+
99+
if (class_exists($class)) {
100+
$body = $request->getContent();
101+
102+
$this->assertFalse(strpos($body, '/json+oembed'), 'Autodiscovered json OEmbed');
103+
$this->assertFalse(strpos($body, '/xml+oembed'), 'Autodiscovered xml OEmbed');
104+
}
79105
}
80106
}

0 commit comments

Comments
 (0)