setRemoteDownload(true); $res = $img->isRemoteSource($source); $this->assertTrue($res, "Should be a valid remote source: '$source'."); } /** * Test * * @return void * * @dataProvider providerInvalidRemoteSource */ public function testAllowRemoteDownloadDefaultPatternInvalid($source) { $img = new CImage(); $img->setRemoteDownload(true); $res = $img->isRemoteSource($source); $this->assertFalse($res, "Should not be a valid remote source: '$source'."); } /** * Provider for hostname matching the whitelist. * * @return array */ public function providerHostnameMatch() { return [ [ "any.facebook.com", "images.ak.instagram.com", "google.com", ], ]; } /** * Test * * @param string $hostname matches the whitelist * * @return void * * @dataProvider providerHostnameMatch * */ public function testRemoteHostWhitelistMatch($hostname) { $img = new CImage(); $img->setRemoteHostWhitelist($this->remote_whitelist); $res = $img->isRemoteSourceOnWhitelist("http://$hostname/img.jpg"); $this->assertTrue($res, "Should be a valid hostname on the whitelist: '$hostname'."); } /** * Provider for hostname not matching the whitelist. * * @return array */ public function providerHostnameNoMatch() { return [ [ "example.com", ".com", "img.jpg", ], ]; } /** * Test * * @param string $hostname not matching the whitelist * * @return void * * @dataProvider providerHostnameNoMatch * */ public function testRemoteHostWhitelistNoMatch($hostname) { $img = new CImage(); $img->setRemoteHostWhitelist($this->remote_whitelist); $res = $img->isRemoteSourceOnWhitelist("http://$hostname/img.jpg"); $this->assertFalse($res, "Should not be a valid hostname on the whitelist: '$hostname'."); } }