Skip to content

Commit

Permalink
Issue #19 Fix PHP docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gthomas2 committed Jul 14, 2016
1 parent 028abd1 commit 0e480cc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
22 changes: 13 additions & 9 deletions classes/service/oembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
* @package filter_embedrc
* @copyright Erich M. Wappis / Guy Thomas 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* code based on the following filter
* oEmbed filter ( Mike Churchward, James McQuillan, Vinayak (Vin) Bhalerao, Josh Gavant and Rob Dolin)
*/
namespace filter_embedrc\service;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir.'/filelib.php');

/**
* Class oembed
* @package filter_embedrc\service
* @copyright Erich M. Wappis / Guy Thomas 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* Singleton class providing function for filtering embedded content links in text.
*/
class oembed {

/**
Expand Down Expand Up @@ -278,13 +283,6 @@ protected function oembed_curlcall($www) {
return $result;
}

/**
* @return array
*/
public function get_warnings() {
return $this->warnings;
}

/**
* Get oembed html.
*
Expand Down Expand Up @@ -333,6 +331,12 @@ public function html_output($text) {
return '';
}

/**
* Magic method for getting properties.
* @param string $name
* @return mixed
* @throws \coding_exception
*/
public function __get($name) {
$allowed = ['providers', 'warnings', 'sites'];
if (in_array($name, $allowed)) {
Expand Down
5 changes: 3 additions & 2 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@

require_once($CFG->libdir.'/filelib.php');
/**
* This text filter allows the user to embed content from many external contents providers.
* The filter is using oEmbed for grabbing the external content.
* Main filter class for embedded remote content.
*
* @package filter_embedrc
* @copyright Erich M. Wappis / Guy Thomas 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_embedrc extends moodle_text_filter {

Expand Down
59 changes: 53 additions & 6 deletions tests/service_embedrc_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,45 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Filter for component 'filter_embedrc'
*
* @package filter_embedrc
* @copyright Erich M. Wappis / Guy Thomas 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use filter_embedrc\service\oembed;

defined('MOODLE_INTERNAL') || die();

/**
* Class testable_oembed.
*
* @package filter_embedrc
* @copyright Erich M. Wappis / Guy Thomas 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_oembed extends oembed {
public function get_providers() {
return $this->providers;
}

/**
* Get cached providers.
* @param bool $ignorelifespan
* @return array|mixed
*/
public function protected_get_cached_providers($ignorelifespan = false) {
return $this->get_cached_providers($ignorelifespan = false);
return $this->get_cached_providers($ignorelifespan);
}

/**
* Get sites.
* @return array
*/
public function protected_get_sites() {
return $this->get_sites();
}
/**
* Singleton
* Singleton.
*
* @return oembed
*/
Expand All @@ -53,19 +76,31 @@ public static function get_instance() {
*/
class filter_embedrc_service_oembed_testcase extends advanced_testcase {

/**
* Test instance.
*/
public function test_instance() {
$this->resetAfterTest(true);
$this->setAdminUser();
$oembed = testable_oembed::get_instance();
$this->assertNotEmpty($oembed);
}

/**
* Make sure providers array is correct.
* @param array $providers
*/
public function assert_providers_ok($providers) {
$this->assertNotEmpty($providers);
$provider = reset($providers);
$this->assertNotEmpty($provider['provider_name']);
$this->assertNotEmpty($provider['provider_url']);
$this->assertNotEmpty($provider['endpoints']);
}

/**
* Test sites.
*/
public function test_sites() {
$this->resetAfterTest(true);
$this->setAdminUser();
Expand All @@ -77,20 +112,32 @@ public function test_sites() {
$this->assertNotEmpty($site['regex']);
$this->assertNotEmpty($site['endpoint']);
}

/**
* Test providers.
*/
public function test_providers() {
$this->resetAfterTest(true);
$this->setAdminUser();
$oembed = testable_oembed::get_instance();
$providers = $oembed->get_providers();
$providers = $oembed->providers;
$this->assert_providers_ok($providers);
}

/**
* Test cached providers.
*/
public function test_get_cached_providers() {
$this->resetAfterTest(true);
$this->setAdminUser();
$oembed = testable_oembed::get_instance();
$providers = $oembed->protected_get_cached_providers();
$this->assert_providers_ok($providers);
}

/**
* Test html.
*/
public function test_html() {
$this->resetAfterTest(true);
$this->setAdminUser();
Expand Down

0 comments on commit 0e480cc

Please sign in to comment.