From b9ad5af2bcfed04d5ceac733a6e31c074175669a Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Mon, 11 Oct 2021 21:22:36 -0400 Subject: [PATCH 1/8] created shell for video class --- src/Rule/VideoScan.php | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/Rule/VideoScan.php diff --git a/src/Rule/VideoScan.php b/src/Rule/VideoScan.php new file mode 100644 index 0000000..ba04cf9 --- /dev/null +++ b/src/Rule/VideoScan.php @@ -0,0 +1,79 @@ +getAllElements(array('a', 'embed', 'iframe', 'script')) as $video) { + $attr = ($video->tagName == 'a') ? 'href' : 'src'; + if ($video->hasAttribute($attr)) { + $attr_val = $video->getAttribute($attr); + $provider = $this->getVideoProvider($attr_val); + $captionData = $this->getCaptionData($attr_val, $provider); + + if($captionData) { + + } + + } + } + } + + public function getCaptionData($url, $provider) + { + if ($provider === self::YOUTUBE_VIDEO) { + if (!empty($this->options['youtubeApiKey'])) { + $service = new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); + } + } elseif ($provider === self::VIMEO_VIDEO) { + if (!empty($this->options['vimeoApiKey'])) { + $service = new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); + } + } else if ($provider === self::KALTURA_VIDEO) { + if (!empty($this->options['kalturaApiKey'])) { + $service = new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); + } + } + if (isset($service)) { + // make API call + } + + return false; + } + + public function getVideoProvider($url) + { + $search_youtube = '/(youtube|youtu.be)/'; + $search_vimeo = '/(vimeo)/'; + $search_kaltura = '/(kaltura)/'; + + if (preg_match($search_youtube, $url)) { + return self::YOUTUBE_VIDEO; + } elseif (preg_match($search_vimeo, $url)) { + return self::VIMEO_VIDEO; + } else if (preg_match($search_kaltura, $url)) { + return self::KALTURA_VIDEO; + } + + return false; + } + + +} \ No newline at end of file From 66738c5cd23d0a43635d0e208cb759b2597c21a3 Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Thu, 14 Oct 2021 11:13:51 -0400 Subject: [PATCH 2/8] reworked video class structure --- src/Rule/BaseRule.php | 11 +- src/Rule/VideoScan.php | 87 ++++++--- src/{ => Video}/Kaltura.php | 6 +- .../VideoCaptionsMatchCourseLanguage.php | 2 +- .../VideosEmbeddedOrLinkedNeedCaptions.php | 2 +- .../VideosHaveAutoGeneratedCaptions.php | 4 +- src/{ => Video}/Vimeo.php | 83 ++++---- src/Video/Youtube.php | 143 ++++++++++++++ src/Youtube.php | 180 ------------------ src/rules.json | 3 +- 10 files changed, 247 insertions(+), 274 deletions(-) rename src/{ => Video}/Kaltura.php (97%) rename src/{Rule => Video}/VideoCaptionsMatchCourseLanguage.php (98%) rename src/{Rule => Video}/VideosEmbeddedOrLinkedNeedCaptions.php (98%) rename src/{Rule => Video}/VideosHaveAutoGeneratedCaptions.php (92%) rename src/{ => Video}/Vimeo.php (50%) create mode 100644 src/Video/Youtube.php delete mode 100644 src/Youtube.php diff --git a/src/Rule/BaseRule.php b/src/Rule/BaseRule.php index 356157d..a345a7b 100644 --- a/src/Rule/BaseRule.php +++ b/src/Rule/BaseRule.php @@ -242,14 +242,15 @@ public function elementContainsReadableText($element) return false; } - public function setIssue($element, $previewElement = null, $metadata = null) + public function setIssue($element, $ruleId = null, $metadata = null) { - $ruleId = str_replace(['CidiLabs\\PhpAlly\\Rule\\','App\\Rule\\'], '', $this->id()); - - if (!$previewElement) { - $previewElement = $this->previewElement; + if (!$ruleId) { + $ruleId = $this->id(); } + $ruleId = str_replace(['CidiLabs\\PhpAlly\\Rule\\','App\\Rule\\'], '', $ruleId); + $previewElement = $this->previewElement; + if ($element) { $elementClasses = $element->getAttribute('class'); if ($elementClasses && (strpos($elementClasses, 'phpally-ignore') !== false)) { diff --git a/src/Rule/VideoScan.php b/src/Rule/VideoScan.php index ba04cf9..c776fb1 100644 --- a/src/Rule/VideoScan.php +++ b/src/Rule/VideoScan.php @@ -3,6 +3,11 @@ namespace CidiLabs\PhpAlly\Rule; use DOMElement; +use CidiLabs\PhpAlly; +use CidiLabs\PhpAlly\Video\Vimeo; +use CidiLabs\PhpAlly\Video\Youtube; +use CidiLabs\PhpAlly\Video\Kaltura; +use GuzzleHttp\Client; /** * @@ -10,9 +15,11 @@ class VideoScan extends BaseRule { - const YOUTUBE_VIDEO = 2; - const VIMEO_VIDEO = 3; - CONST KALTURA_VIDEO = 4; + const YOUTUBE_VIDEO = 1; + const VIMEO_VIDEO = 2; + CONST KALTURA_VIDEO = 3; + + private $serviceType = null; public function id() { @@ -24,40 +31,59 @@ public function check() foreach ($this->getAllElements(array('a', 'embed', 'iframe', 'script')) as $video) { $attr = ($video->tagName == 'a') ? 'href' : 'src'; if ($video->hasAttribute($attr)) { + // Get URL $attr_val = $video->getAttribute($attr); + // Get provider (Youtube, Vimeo, or Kaltura class) $provider = $this->getVideoProvider($attr_val); - $captionData = $this->getCaptionData($attr_val, $provider); + // Get caption data + $captionData = $provider->getVideoData($attr_val); - if($captionData) { - + if($captionData && $provider) { + $this->checkCaptionsExist($captionData, $provider); + $this->checkCaptionsLanguage($captionData, $provider); + $this->checkCaptionsAutoGenerated($captionData, $provider); } - } } } - public function getCaptionData($url, $provider) + // Scan rule functions + + // VideosEmbeddedOrLinkedNeedCaptions + public function checkCaptionsExist($captionData, $provider) { - if ($provider === self::YOUTUBE_VIDEO) { - if (!empty($this->options['youtubeApiKey'])) { - $service = new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); - } - } elseif ($provider === self::VIMEO_VIDEO) { - if (!empty($this->options['vimeoApiKey'])) { - $service = new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); - } - } else if ($provider === self::KALTURA_VIDEO) { - if (!empty($this->options['kalturaApiKey'])) { - $service = new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); - } - } - if (isset($service)) { - // make API call - } + // Use provider to call + if (method_exists($provider, 'captionsMissing')) { + return $provider->captionsMissing($captionData); + } + + return false; + } - return false; + // VideoCaptionsMatchCourseLanguage + public function checkCaptionsLanguage($captionData, $provider) + { + // Use provider to call + if (method_exists($provider, 'captionsLanguage')) { + return $provider->captionsLanguage($captionData); + } + + return false; } + // CaptionsAutoGenerated + public function checkCaptionsAutoGenerated($captionData, $provider) + { + // Use provider to call + if (method_exists($provider, 'captionsAutoGenerated')) { + return $provider->captionsAutoGenerated($captionData); + } + + return false; + } + + // Helpers + public function getVideoProvider($url) { $search_youtube = '/(youtube|youtu.be)/'; @@ -65,15 +91,16 @@ public function getVideoProvider($url) $search_kaltura = '/(kaltura)/'; if (preg_match($search_youtube, $url)) { - return self::YOUTUBE_VIDEO; + $this->serviceType = self::YOUTUBE_VIDEO; + return new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); } elseif (preg_match($search_vimeo, $url)) { - return self::VIMEO_VIDEO; + $this->serviceType = self::VIMEO_VIDEO; + return new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); } else if (preg_match($search_kaltura, $url)) { - return self::KALTURA_VIDEO; + $this->serviceType = self::KALTURA_VIDEO; + return new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); } return false; } - - } \ No newline at end of file diff --git a/src/Kaltura.php b/src/Video/Kaltura.php similarity index 97% rename from src/Kaltura.php rename to src/Video/Kaltura.php index d9cd1c7..e1d4e3b 100644 --- a/src/Kaltura.php +++ b/src/Video/Kaltura.php @@ -1,6 +1,6 @@ search_url; + $body = json_decode($captionData->getBody()); - // If the API key is blank, flag the video for manual inspection - $key_trimmed = trim($this->api_key); - if (empty($key_trimmed)) { + // Response header code is used to determine if video exists, doesn't exist, or is unaccessible + // 400 means a video is private, 404 means a video doesn't exist, and 200 means the video exists + if ($captionData->getStatusCode() >= 400) { return self::VIMEO_FAILED_CONNECTION; + } else if (($captionData->getStatusCode() === 200) && $body->total === 0) { + return self::VIMEO_FAIL; } - - if ($vimeo_id = $this->isVimeoVideo($link_url)) { - $response = $this->getVideoData($vimeo_id); - - $body = json_decode($response->getBody()); - - // Response header code is used to determine if video exists, doesn't exist, or is unaccessible - // 400 means a video is private, 404 means a video doesn't exist, and 200 means the video exists - if ($response->getStatusCode() >= 400) { - return self::VIMEO_FAILED_CONNECTION; - } else if (($response->getStatusCode() === 200) && $body->total === 0) { - return self::VIMEO_FAIL; - } - } + return self::VIMEO_SUCCESS; } @@ -59,45 +48,31 @@ function captionsMissing($link_url) * @param string $link_url The URL to the video or video resource * @return int 0 if captions are manual and wrong language, 1 if video is private, 2 if there are no captions or if manually generated and correct language */ - function captionsLanguage($link_url) + function captionsLanguage($captionData) { - $url = $this->search_url; - // If the API key is blank, flag the video for manual inspection - $key_trimmed = trim($this->api_key); - if (empty($key_trimmed)) { - return self::VIMEO_FAILED_CONNECTION; - } - // If for whatever reason course_locale is blank, set it to English $course_locale = $this->language; if ($course_locale === '' || is_null($course_locale)) { $course_locale = 'en'; } - if ($vimeo_id = $this->isVimeoVideo($link_url)) { - $url = $url . $vimeo_id . '/texttracks'; - $response = $this->getVideoData($vimeo_id); + $body = json_decode($captionData->getBody()); - $body = json_decode($response->getBody()); + // Response header code is used to determine if video exists, doesn't exist, or is unaccessible + // 400 means a video is private, 404 means a video doesn't exist, and 200 means the video exists + if ($captionData->getStatusCode() === 400 || $captionData->getStatusCode() === 404) { + return self::VIMEO_FAILED_CONNECTION; + } else if (($captionData->getStatusCode() === 200) && $body->total === 0) { + return self::VIMEO_SUCCESS; + } - // Response header code is used to determine if video exists, doesn't exist, or is unaccessible - // 400 means a video is private, 404 means a video doesn't exist, and 200 means the video exists - if ($response->getStatusCode() === 400 || $response->getStatusCode() === 404) { - return self::VIMEO_FAILED_CONNECTION; - } else if (($response->getStatusCode() === 200) && $body->total === 0) { + foreach ($body->data as $track) { + if (substr($track->language, 0, 2) === $course_locale) { return self::VIMEO_SUCCESS; } - - foreach ($body->data as $track) { - if (substr($track->language, 0, 2) === $course_locale) { - return self::VIMEO_SUCCESS; - } - } - - return self::VIMEO_FAIL; } - return self::VIMEO_SUCCESS; + return self::VIMEO_FAIL; } /** @@ -115,12 +90,18 @@ private function isVimeoVideo($link_url) return false; } - function getVideoData($vimeo_id) + function getVideoData($link_url) { - $url = $this->search_url . $vimeo_id . '/texttracks'; + $key_trimmed = trim($this->api_key); + + if ($vimeo_id = $this->isVimeoVideo($link_url) && !empty($key_trimmed)) { + $url = $this->search_url . $vimeo_id . '/texttracks'; - return $this->client->request('GET', $url, ['headers' => [ - 'Authorization' => "Bearer $this->api_key" - ]]); + return $this->client->request('GET', $url, ['headers' => [ + 'Authorization' => "Bearer $this->api_key" + ]]); + } + + return false; } } diff --git a/src/Video/Youtube.php b/src/Video/Youtube.php new file mode 100644 index 0000000..1d6d2df --- /dev/null +++ b/src/Video/Youtube.php @@ -0,0 +1,143 @@ +client = $client; + $this->language = $language; + $this->api_key = $api_key; + } + + /** + * Checks to see if a video is missing caption information in YouTube + * @param string $link_url The URL to the video or video resource + * @return int 0 if captions are missing, 1 if video is private, 2 if captions exist or not a video + */ + public function captionsMissing($captionData) + { + if ($captionData->getStatusCode() >= 400) { + return self::YOUTUBE_NO_VIDEO; + } + + $items = json_decode($captionData->getBody())->items; + + return !(empty($items)) ? self::YOUTUBE_SUCCESS : self::YOUTUBE_FAIL; + } + + public function captionsAutoGenerated($captionData) + { + if ($captionData->getStatusCode() >= 400) { + return self::YOUTUBE_NO_VIDEO; + } + + $items = json_decode($captionData->getBody())->items; + + // Looks through the captions and checks if any were not auto-generated + foreach ($items as $track) { + if (strtolower($track->snippet->trackKind) != 'asr') { + return self::YOUTUBE_SUCCESS; + } + } + + return self::YOUTUBE_FAIL; + } + + /** + * Checks to see if a video is missing caption information in YouTube + * @param string $link_url The URL to the video or video resource + * @return int 0 if captions are manual and wrong language, 1 if video is private, 2 if captions are auto-generated or manually generated and correct language + */ + public function captionsLanguage($captionData) + { + $foundManual = false; + // If for whatever reason course_locale is blank, set it to English + $course_locale = $this->language; + if ($course_locale === '' || is_null($course_locale)) { + $course_locale = 'en'; + } + + // If the video was pulled due to copyright violations, is unlisted, or is unavailable, the reponse header will be 404 + if ($captionData->getStatusCode() >= 400) { + return self::YOUTUBE_NO_VIDEO; + } + + $items = json_decode($captionData->getBody())->items; + + // Looks through the captions and checks if they are of the correct language + foreach ($items as $track) { + $trackKind = strtolower($track->snippet->trackKind); + + //If the track was manually generated, set the flag to true + if ($trackKind != 'asr') { + $foundManual = true; + } + + if (substr($track->snippet->language, 0, 2) == $course_locale && $trackKind != 'asr') { + return self::YOUTUBE_SUCCESS; + } + } + + //If we found any manual captions and have not returned, then none are the correct language + if ($foundManual === true) { + return self::YOUTUBE_FAIL; + } + + return self::YOUTUBE_SUCCESS; + } + + /** + * Checks to see if the provided link URL is a YouTube video. If so, it returns + * the video code, if not, it returns null. + * @param string $link_url The URL to the video or video resource + * @return mixed FALSE if it's not a YouTube video, or a string video ID if it is + */ + function isYouTubeVideo($link_url) + { + $matches = null; + foreach ($this->regex as $pattern) { + if (preg_match($pattern, trim($link_url), $matches)) { + return $matches[1]; + } + } + return false; + } + + function getVideoData($link_url) + { + $key_trimmed = trim($this->api_key); + + if ($youtube_id = $this->isYouTubeVideo($link_url) && !empty($key_trimmed)) { + $url = $this->search_url . $youtube_id . '&key=' . $this->api_key; + $response = $this->client->request('GET', $url); + + return $response; + } + + return false; + } +} diff --git a/src/Youtube.php b/src/Youtube.php deleted file mode 100644 index 1bae18f..0000000 --- a/src/Youtube.php +++ /dev/null @@ -1,180 +0,0 @@ -client = $client; - $this->language = $language; - $this->api_key = $api_key; - } - - /** - * Checks to see if a video is missing caption information in YouTube - * @param string $link_url The URL to the video or video resource - * @return int 0 if captions are missing, 1 if video is private, 2 if captions exist or not a video - */ - public function captionsMissing($link_url) - { - $url = $this->search_url; - - // If the API key is blank, flag the video for manual inspection - $key_trimmed = trim($this->api_key); - if (empty($key_trimmed)) { - return self::YOUTUBE_NO_VIDEO; - } - - if ($youtube_id = $this->isYouTubeVideo($link_url)) { - $response = $this->getVideoData($youtube_id); - - if ($response->getStatusCode() >= 400) { - return self::YOUTUBE_NO_VIDEO; - } - - $items = json_decode($response->getBody())->items; - - return !(empty($items)) ? self::YOUTUBE_SUCCESS : self::YOUTUBE_FAIL; - } - - return self::YOUTUBE_SUCCESS; - } - - public function captionsAutoGenerated($link_url) - { - $url = $this->search_url; - - // If the API key is blank, flag the video for manual inspection - $key_trimmed = trim($this->api_key); - if (empty($key_trimmed)) { - return self::YOUTUBE_NO_VIDEO; - } - - if ($youtube_id = $this->isYouTubeVideo($link_url)) { - $response = $this->getVideoData($youtube_id); - - if ($response->getStatusCode() >= 400) { - return self::YOUTUBE_NO_VIDEO; - } - - $items = json_decode($response->getBody())->items; - - // Looks through the captions and checks if any were not auto-generated - foreach ($items as $track) { - if (strtolower($track->snippet->trackKind) != 'asr') { - return self::YOUTUBE_SUCCESS; - } - } - - return self::YOUTUBE_FAIL; - } - - // If we can't get to the video we will assume it passes, since we can't prove otherwise. :) - return self::YOUTUBE_SUCCESS; - } - - /** - * Checks to see if a video is missing caption information in YouTube - * @param string $link_url The URL to the video or video resource - * @return int 0 if captions are manual and wrong language, 1 if video is private, 2 if captions are auto-generated or manually generated and correct language - */ - public function captionsLanguage($link_url) - { - $url = $this->search_url; - $api_key = $this->api_key; - $foundManual = false; - - // If the API key is blank, flag the video for manual inspection - $key_trimmed = trim($api_key); - if (empty($key_trimmed)) { - return self::YOUTUBE_NO_VIDEO; - } - - // If for whatever reason course_locale is blank, set it to English - $course_locale = $this->language; - if ($course_locale === '' || is_null($course_locale)) { - $course_locale = 'en'; - } - - if ($youtube_id = $this->isYouTubeVideo($link_url)) { - $response = $this->getVideoData($youtube_id); - - // If the video was pulled due to copyright violations, is unlisted, or is unavailable, the reponse header will be 404 - if ($response->getStatusCode() >= 400) { - return self::YOUTUBE_NO_VIDEO; - } - - $items = json_decode($response->getBody())->items; - - // Looks through the captions and checks if they are of the correct language - foreach ($items as $track) { - $trackKind = strtolower($track->snippet->trackKind); - - //If the track was manually generated, set the flag to true - if ($trackKind != 'asr') { - $foundManual = true; - } - - if (substr($track->snippet->language, 0, 2) == $course_locale && $trackKind != 'asr') { - return self::YOUTUBE_SUCCESS; - } - } - - //If we found any manual captions and have not returned, then none are the correct language - if ($foundManual === true) { - return self::YOUTUBE_FAIL; - } - } - - return self::YOUTUBE_SUCCESS; - } - - /** - * Checks to see if the provided link URL is a YouTube video. If so, it returns - * the video code, if not, it returns null. - * @param string $link_url The URL to the video or video resource - * @return mixed FALSE if it's not a YouTube video, or a string video ID if it is - */ - private function isYouTubeVideo($link_url) - { - $matches = null; - foreach ($this->regex as $pattern) { - if (preg_match($pattern, trim($link_url), $matches)) { - return $matches[1]; - } - } - return false; - } - - function getVideoData($youtube_id) - { - $url = $this->search_url . $youtube_id . '&key=' . $this->api_key; - $response = $this->client->request('GET', $url); - - return $response; - } -} diff --git a/src/rules.json b/src/rules.json index 9802b43..d5a771e 100644 --- a/src/rules.json +++ b/src/rules.json @@ -35,5 +35,6 @@ "CidiLabs\\PhpAlly\\Rule\\VideoEmbedCheck", "CidiLabs\\PhpAlly\\Rule\\VideoProvidesCaptions", "CidiLabs\\PhpAlly\\Rule\\VideosEmbeddedOrLinkedNeedCaptions", - "CidiLabs\\PhpAlly\\Rule\\VideosHaveAutoGeneratedCaptions" + "CidiLabs\\PhpAlly\\Rule\\VideosHaveAutoGeneratedCaptions", + "CidiLabs\\PhpAlly\\Rule\\VideosScan" ] From e79ad3c4459ce6dba6c68a66faf65ac85a12112b Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Thu, 14 Oct 2021 11:50:51 -0400 Subject: [PATCH 3/8] fvideo class restructured, deleted redundant files --- src/Rule/VideoScan.php | 47 +++++----- src/Video/Kaltura.php | 94 +++++++++---------- .../VideoCaptionsMatchCourseLanguage.php | 60 ------------ .../VideosEmbeddedOrLinkedNeedCaptions.php | 68 -------------- src/Video/VideosHaveAutoGeneratedCaptions.php | 51 ---------- 5 files changed, 66 insertions(+), 254 deletions(-) delete mode 100644 src/Video/VideoCaptionsMatchCourseLanguage.php delete mode 100644 src/Video/VideosEmbeddedOrLinkedNeedCaptions.php delete mode 100644 src/Video/VideosHaveAutoGeneratedCaptions.php diff --git a/src/Rule/VideoScan.php b/src/Rule/VideoScan.php index c776fb1..4e70e63 100644 --- a/src/Rule/VideoScan.php +++ b/src/Rule/VideoScan.php @@ -15,11 +15,9 @@ class VideoScan extends BaseRule { - const YOUTUBE_VIDEO = 1; - const VIMEO_VIDEO = 2; - CONST KALTURA_VIDEO = 3; - - private $serviceType = null; + const FAIL = 0; + const FAILED_CONNECTION = 1; + const SUCCESS = 2; public function id() { @@ -39,9 +37,9 @@ public function check() $captionData = $provider->getVideoData($attr_val); if($captionData && $provider) { - $this->checkCaptionsExist($captionData, $provider); - $this->checkCaptionsLanguage($captionData, $provider); - $this->checkCaptionsAutoGenerated($captionData, $provider); + $this->checkCaptionsExist($captionData, $provider, $video); + $this->checkCaptionsLanguage($captionData, $provider, $video); + $this->checkCaptionsAutoGenerated($captionData, $provider, $video); } } } @@ -50,36 +48,42 @@ public function check() // Scan rule functions // VideosEmbeddedOrLinkedNeedCaptions - public function checkCaptionsExist($captionData, $provider) + public function checkCaptionsExist($captionData, $provider, $video) { // Use provider to call if (method_exists($provider, 'captionsMissing')) { - return $provider->captionsMissing($captionData); + $captionState = $provider->captionsMissing($captionData); + + if ($captionState !== self::SUCCESS) { + $this->setIssue($video, 'VideosEmbeddedOrLinkedNeedCaptions'); + } } - - return false; } // VideoCaptionsMatchCourseLanguage - public function checkCaptionsLanguage($captionData, $provider) + public function checkCaptionsLanguage($captionData, $provider, $video) { // Use provider to call if (method_exists($provider, 'captionsLanguage')) { - return $provider->captionsLanguage($captionData); - } + $captionState = $provider->captionsMissing($captionData); - return false; + if ($captionState !== self::SUCCESS) { + $this->setIssue($video, 'VideoCaptionsMatchCourseLanguage'); + } + } } // CaptionsAutoGenerated - public function checkCaptionsAutoGenerated($captionData, $provider) + public function checkCaptionsAutoGenerated($captionData, $provider, $video) { // Use provider to call if (method_exists($provider, 'captionsAutoGenerated')) { - return $provider->captionsAutoGenerated($captionData); - } + $captionState = $provider->captionsMissing($captionData); - return false; + if ($captionState !== self::SUCCESS) { + $this->setIssue($video, 'VideosHaveAutoGeneratedCaptions'); + } + } } // Helpers @@ -91,13 +95,10 @@ public function getVideoProvider($url) $search_kaltura = '/(kaltura)/'; if (preg_match($search_youtube, $url)) { - $this->serviceType = self::YOUTUBE_VIDEO; return new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); } elseif (preg_match($search_vimeo, $url)) { - $this->serviceType = self::VIMEO_VIDEO; return new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); } else if (preg_match($search_kaltura, $url)) { - $this->serviceType = self::KALTURA_VIDEO; return new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); } diff --git a/src/Video/Kaltura.php b/src/Video/Kaltura.php index e1d4e3b..dae9f19 100644 --- a/src/Video/Kaltura.php +++ b/src/Video/Kaltura.php @@ -32,22 +32,12 @@ public function __construct($language = 'en', $api_key = '', $username = '') * @param string $link_url The URL to the video or video resource * @return int 0 if captions are missing, 1 if video is private, 2 if captions exist or not a video */ - function captionsMissing($link_url) + function captionsMissing($captionData) { - // If the API key or username is blank, flag the video for manual inspection - $key_trimmed = trim($this->api_key); - $username_trimmed = trim($this->username); - if (empty($key_trimmed) || empty($username_trimmed)) { - return self::KALTURA_SUCCESS; - } - - if(($video_id = $this->isKalturaVideo($link_url)) && ($partner_id = $this->getPartnerID($link_url))) { - $result = $this->getVideoData($video_id, $partner_id); - - if($result->totalCount === 0) { - return self::KALTURA_FAIL; - } + if($result->totalCount === 0) { + return self::KALTURA_FAIL; } + return self::KALTURA_SUCCESS; } @@ -58,26 +48,14 @@ function captionsMissing($link_url) */ function captionsLanguage($link_url) { - // If the API key or username is blank, flag the video for manual inspection - $key_trimmed = trim($this->api_key); - $username_trimmed = trim($this->username); - if (empty($key_trimmed) || empty($username_trimmed)) { - return self::KALTURA_SUCCESS; - } - - if(($video_id = $this->isKalturaVideo($link_url)) && ($partner_id = $this->getPartnerID($link_url))) { - $result = $this->getVideoData($video_id, $partner_id); - $captionsArray = $result->objects; - foreach($captionsArray as $caption) - { - if(substr($caption->languageCode, 0, 2) === substr($this->language, 0, 2)) { - return self::KALTURA_SUCCESS; - } - } - return self::KALTURA_FAIL; + $captionsArray = $result->objects; + foreach($captionsArray as $caption) + { + if(substr($caption->languageCode, 0, 2) === substr($this->language, 0, 2)) { + return self::KALTURA_SUCCESS; + } } - - return self::KALTURA_SUCCESS; + return self::KALTURA_FAIL; } /** @@ -114,26 +92,38 @@ function getPartnerID($link_url) * @return mixed FALSE if the api calls fails or its not a Kaltura video, * or an array of caption objects if it is */ - function getVideoData($video_id, $partner_id) + function getVideoData($link_url) { - $config = new KalturaConfiguration($partner_id); - $config->setServiceUrl('https://www.kaltura.com'); - $this->client = new KalturaClient($config); - $ks = $this->client->generateSession( - $this->api_key, - $this->username, - SessionType::ADMIN, - $partner_id); - $this->client->setKS($ks); - - $captionPlugin = CaptionPlugin::get($this->client); - $filter = new AssetFilter(); - $filter->entryIdIn = $video_id; - $pager = new FilterPager(); - - $result = $captionPlugin->captionAsset->listAction($filter, $pager); - - return $result; + // If the API key or username is blank, flag the video for manual inspection + $key_trimmed = trim($this->api_key); + $username_trimmed = trim($this->username); + if (empty($key_trimmed) || empty($username_trimmed)) { + return false; + } + + if ($video_id = $this->isKalturaVideo($link_url) && $partner_id = $this->getPartnerID($link_url)) { + + $config = new KalturaConfiguration($partner_id); + $config->setServiceUrl('https://www.kaltura.com'); + $this->client = new KalturaClient($config); + $ks = $this->client->generateSession( + $this->api_key, + $this->username, + SessionType::ADMIN, + $partner_id); + $this->client->setKS($ks); + + $captionPlugin = CaptionPlugin::get($this->client); + $filter = new AssetFilter(); + $filter->entryIdIn = $video_id; + $pager = new FilterPager(); + + $result = $captionPlugin->captionAsset->listAction($filter, $pager); + + return $result; + } + + return false; } } \ No newline at end of file diff --git a/src/Video/VideoCaptionsMatchCourseLanguage.php b/src/Video/VideoCaptionsMatchCourseLanguage.php deleted file mode 100644 index c5a99ff..0000000 --- a/src/Video/VideoCaptionsMatchCourseLanguage.php +++ /dev/null @@ -1,60 +0,0 @@ -getAllElements(array('a', 'embed', 'iframe', 'script')) as $video) { - $attr = ($video->tagName == 'a') ? 'href' : 'src'; - if ($video->hasAttribute($attr)) { - $attr_val = $video->getAttribute($attr); - $captionState = $this->getCaptionState($attr_val); - if ($captionState != self::VIDEO_HAS_CAPTIONS) { - $this->setIssue($video); - } - } - } - - return count($this->issues); - } - - public function getCaptionState($attr_val) - { - $search_youtube = '/(youtube|youtu.be)/'; - $search_vimeo = '/(vimeo)/'; - $search_kaltura = '/(kaltura)/'; - - if (preg_match($search_youtube, $attr_val)) { - $service = new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); - } elseif (preg_match($search_vimeo, $attr_val)) { - $service = new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); - } else if (preg_match($search_kaltura, $attr_val)) { - $service = new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); - } - if (isset($service)) { - $captionState = $service->captionsLanguage($attr_val); - return $captionState; - } - - return self::VIDEO_HAS_CAPTIONS; - } -} \ No newline at end of file diff --git a/src/Video/VideosEmbeddedOrLinkedNeedCaptions.php b/src/Video/VideosEmbeddedOrLinkedNeedCaptions.php deleted file mode 100644 index 07611b5..0000000 --- a/src/Video/VideosEmbeddedOrLinkedNeedCaptions.php +++ /dev/null @@ -1,68 +0,0 @@ -getAllElements(array('a', 'embed', 'iframe', 'script')) as $video) { - $attr = ($video->tagName == 'a') ? 'href' : 'src'; - if ($video->hasAttribute($attr)) { - $attr_val = $video->getAttribute($attr); - $captionState = $this->getCaptionState($attr_val); - if ($captionState != self::VIDEO_HAS_CAPTIONS) { - $this->setIssue($video); - } - - } - } - - return count($this->issues); - } - - public function getCaptionState($attr_val) - { - $search_youtube = '/(youtube|youtu.be)/'; - $search_vimeo = '/(vimeo)/'; - $search_kaltura = '/(kaltura)/'; - - if (preg_match($search_youtube, $attr_val)) { - if (!empty($this->options['youtubeApiKey'])) { - $service = new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); - } - } elseif (preg_match($search_vimeo, $attr_val)) { - if (!empty($this->options['vimeoApiKey'])) { - $service = new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); - } - } else if (preg_match($search_kaltura, $attr_val)) { - if (!empty($this->options['kalturaApiKey'])) { - $service = new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); - } - } - if (isset($service)) { - $captionState = $service->captionsMissing($attr_val); - return $captionState; - } - - return self::VIDEO_HAS_CAPTIONS; - } -} diff --git a/src/Video/VideosHaveAutoGeneratedCaptions.php b/src/Video/VideosHaveAutoGeneratedCaptions.php deleted file mode 100644 index fc73a2a..0000000 --- a/src/Video/VideosHaveAutoGeneratedCaptions.php +++ /dev/null @@ -1,51 +0,0 @@ -getAllElements(array('a', 'embed', 'iframe')) as $video) { - $attr = ($video->tagName == 'a') ? 'href' : 'src'; - if ($video->hasAttribute($attr)) { - $attr_val = $video->getAttribute($attr); - $captionState = $this->getCaptionState($attr_val); - if ($captionState != self::VIDEO_HAS_CUSTOM_CAPTIONS) { - $this->setIssue($video); - } - } - } - - return count($this->issues); - } - - public function getCaptionState($attr_val) - { - $service = null; - $search_youtube = '/(youtube|youtu.be)/'; - - if (preg_match($search_youtube, $attr_val)) { - $service = new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); - } - - if (isset($service)) { - $captionState = $service->captionsAutoGenerated($attr_val); - return $captionState; - } - - return self::VIDEO_HAS_CUSTOM_CAPTIONS; - } -} From ba7685396139fe300ca2da52ba4213aa2799c1a6 Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Sun, 17 Oct 2021 20:28:16 -0400 Subject: [PATCH 4/8] wrapping up video class rewrite and tests --- composer.lock | 346 ++++++++++++++---- src/Rule/BaseRule.php | 2 +- src/Rule/VideoScan.php | 49 ++- src/Video/Kaltura.php | 10 +- src/Video/Vimeo.php | 2 +- src/Video/Youtube.php | 4 +- src/rules.json | 5 +- tests/KalturaTest.php | 181 ++++----- .../VideoCaptionsMatchCourseLanguageTest.php | 118 ------ tests/VideoScanTest.php | 118 ++++++ ...ideosEmbdeddedOrLinkedNeedCaptionsTest.php | 56 --- tests/VideosHaveAutoGeneratedCaptionsTest.php | 54 --- tests/VimeoTest.php | 82 +++-- tests/YoutubeTest.php | 179 ++++++--- 14 files changed, 705 insertions(+), 501 deletions(-) delete mode 100644 tests/VideoCaptionsMatchCourseLanguageTest.php create mode 100644 tests/VideoScanTest.php delete mode 100644 tests/VideosEmbdeddedOrLinkedNeedCaptionsTest.php delete mode 100644 tests/VideosHaveAutoGeneratedCaptionsTest.php diff --git a/composer.lock b/composer.lock index 8d2d759..c5dc7b2 100644 --- a/composer.lock +++ b/composer.lock @@ -85,6 +85,10 @@ "rest", "web service" ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.3.0" + }, "funding": [ { "url": "https://github.com/GrahamCampbell", @@ -107,16 +111,16 @@ }, { "name": "guzzlehttp/promises", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d" + "reference": "136a635e2b4a49b9d79e9c8fee267ffb257fdba0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d", - "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d", + "url": "https://api.github.com/repos/guzzle/promises/zipball/136a635e2b4a49b9d79e9c8fee267ffb257fdba0", + "reference": "136a635e2b4a49b9d79e9c8fee267ffb257fdba0", "shasum": "" }, "require": { @@ -128,7 +132,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.5-dev" } }, "autoload": { @@ -144,30 +148,63 @@ "MIT" ], "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" } ], "description": "Guzzle promises library", "keywords": [ "promise" ], - "time": "2021-03-07T09:25:29+00:00" + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.5.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2021-10-07T13:05:22+00:00" }, { "name": "guzzlehttp/psr7", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7" + "reference": "089edd38f5b8abba6cb01567c2a8aaa47cec4c72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", - "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/089edd38f5b8abba6cb01567c2a8aaa47cec4c72", + "reference": "089edd38f5b8abba6cb01567c2a8aaa47cec4c72", "shasum": "" }, "require": { @@ -191,7 +228,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -204,13 +241,34 @@ "MIT" ], "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, { "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", "homepage": "https://github.com/Tobion" }, { @@ -230,20 +288,38 @@ "uri", "url" ], - "time": "2021-06-30T20:03:07+00:00" + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.1.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2021-10-06T17:43:30+00:00" }, { "name": "kaltura/api-client-library", - "version": "v17.2.0", + "version": "v17.11.0", "source": { "type": "git", "url": "https://github.com/kaltura/KalturaGeneratedAPIClientsPHP53.git", - "reference": "cdb27eba2bf096306f0c458d54966cfb4c283fad" + "reference": "91b13536fde71d2f61c5ac28645e27959f8e16c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/kaltura/KalturaGeneratedAPIClientsPHP53/zipball/cdb27eba2bf096306f0c458d54966cfb4c283fad", - "reference": "cdb27eba2bf096306f0c458d54966cfb4c283fad", + "url": "https://api.github.com/repos/kaltura/KalturaGeneratedAPIClientsPHP53/zipball/91b13536fde71d2f61c5ac28645e27959f8e16c0", + "reference": "91b13536fde71d2f61c5ac28645e27959f8e16c0", "shasum": "" }, "require": { @@ -274,7 +350,11 @@ "video", "video platform" ], - "time": "2021-05-26T13:19:13+00:00" + "support": { + "issues": "https://github.com/kaltura/KalturaGeneratedAPIClientsPHP53/issues", + "source": "https://github.com/kaltura/KalturaGeneratedAPIClientsPHP53/tree/v17.11.0" + }, + "time": "2021-10-07T09:16:12+00:00" }, { "name": "psr/http-client", @@ -323,6 +403,9 @@ "psr", "psr-18" ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/master" + }, "time": "2020-06-29T06:28:15+00:00" }, { @@ -375,6 +458,9 @@ "request", "response" ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, "time": "2019-04-30T12:38:16+00:00" }, { @@ -425,6 +511,9 @@ "request", "response" ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, "time": "2016-08-06T14:39:51+00:00" }, { @@ -465,6 +554,10 @@ } ], "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, "time": "2019-03-08T08:55:37+00:00" } ], @@ -518,6 +611,10 @@ "constructor", "instantiate" ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + }, "funding": [ { "url": "https://www.doctrine-project.org/sponsorship.html", @@ -580,6 +677,10 @@ "object", "object graph" ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + }, "funding": [ { "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", @@ -590,16 +691,16 @@ }, { "name": "phar-io/manifest", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", "shasum": "" }, "require": { @@ -642,7 +743,11 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2020-06-27T14:33:11+00:00" + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.3" + }, + "time": "2021-07-20T11:28:43+00:00" }, { "name": "phar-io/version", @@ -689,6 +794,10 @@ } ], "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.1.0" + }, "time": "2021-02-23T14:00:09+00:00" }, { @@ -738,6 +847,10 @@ "reflection", "static analysis" ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, "time": "2020-06-27T09:03:43+00:00" }, { @@ -790,20 +903,24 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + }, "time": "2020-09-03T19:13:55+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.4.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" + "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae", + "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae", "shasum": "" }, "require": { @@ -811,7 +928,8 @@ "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "*" + "ext-tokenizer": "*", + "psalm/phar": "^4.8" }, "type": "library", "extra": { @@ -835,37 +953,41 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-09-17T18:55:26+00:00" + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1" + }, + "time": "2021-10-02T14:08:47+00:00" }, { "name": "phpspec/prophecy", - "version": "1.13.0", + "version": "1.14.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" + "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e", + "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2", - "php": "^7.2 || ~8.0, <8.1", + "php": "^7.2 || ~8.0, <8.2", "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0", "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^6.0", + "phpspec/phpspec": "^6.0 || ^7.0", "phpunit/phpunit": "^8.0 || ^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { @@ -898,20 +1020,24 @@ "spy", "stub" ], - "time": "2021-03-17T13:42:18+00:00" + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/1.14.0" + }, + "time": "2021-09-10T09:02:12+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "7.0.14", + "version": "7.0.15", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "bb7c9a210c72e4709cdde67f8b7362f672f2225c" + "reference": "819f92bba8b001d4363065928088de22f25a3a48" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/bb7c9a210c72e4709cdde67f8b7362f672f2225c", - "reference": "bb7c9a210c72e4709cdde67f8b7362f672f2225c", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/819f92bba8b001d4363065928088de22f25a3a48", + "reference": "819f92bba8b001d4363065928088de22f25a3a48", "shasum": "" }, "require": { @@ -920,7 +1046,7 @@ "php": ">=7.2", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.1.1 || ^4.0", + "phpunit/php-token-stream": "^3.1.3 || ^4.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/environment": "^4.2.2", "sebastian/version": "^2.0.1", @@ -961,26 +1087,30 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/7.0.15" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" } ], - "time": "2020-12-02T13:39:03+00:00" + "time": "2021-07-26T12:20:09+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "4b49fb70f067272b659ef0174ff9ca40fdaa6357" + "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/4b49fb70f067272b659ef0174ff9ca40fdaa6357", - "reference": "4b49fb70f067272b659ef0174ff9ca40fdaa6357", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/28af674ff175d0768a5a978e6de83f697d4a7f05", + "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05", "shasum": "" }, "require": { @@ -1017,13 +1147,17 @@ "filesystem", "iterator" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" } ], - "time": "2020-11-30T08:25:21+00:00" + "time": "2021-07-19T06:46:01+00:00" }, { "name": "phpunit/php-text-template", @@ -1064,6 +1198,10 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1" + }, "time": "2015-06-21T13:50:34+00:00" }, { @@ -1113,6 +1251,10 @@ "keywords": [ "timer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/2.1.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1123,29 +1265,29 @@ }, { "name": "phpunit/php-token-stream", - "version": "3.1.2", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "472b687829041c24b25f475e14c2f38a09edf1c2" + "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/472b687829041c24b25f475e14c2f38a09edf1c2", - "reference": "472b687829041c24b25f475e14c2f38a09edf1c2", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/a853a0e183b9db7eed023d7933a858fa1c8d25a3", + "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=7.1" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1168,6 +1310,10 @@ "keywords": [ "tokenizer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", + "source": "https://github.com/sebastianbergmann/php-token-stream/tree/master" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1175,20 +1321,20 @@ } ], "abandoned": true, - "time": "2020-11-30T08:38:46+00:00" + "time": "2020-08-04T08:28:15+00:00" }, { "name": "phpunit/phpunit", - "version": "8.5.17", + "version": "8.5.21", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "79067856d85421c56d413bd238d4e2cd6b0e54da" + "reference": "50a58a60b85947b0bee4c8ecfe0f4bbdcf20e984" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/79067856d85421c56d413bd238d4e2cd6b0e54da", - "reference": "79067856d85421c56d413bd238d4e2cd6b0e54da", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/50a58a60b85947b0bee4c8ecfe0f4bbdcf20e984", + "reference": "50a58a60b85947b0bee4c8ecfe0f4bbdcf20e984", "shasum": "" }, "require": { @@ -1200,12 +1346,12 @@ "ext-xml": "*", "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.10.0", - "phar-io/manifest": "^2.0.1", + "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.2", "phpspec/prophecy": "^1.10.3", "phpunit/php-code-coverage": "^7.0.12", - "phpunit/php-file-iterator": "^2.0.2", + "phpunit/php-file-iterator": "^2.0.4", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.1.2", "sebastian/comparator": "^3.0.2", @@ -1258,6 +1404,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.21" + }, "funding": [ { "url": "https://phpunit.de/donate.html", @@ -1268,7 +1418,7 @@ "type": "github" } ], - "time": "2021-06-23T05:12:43+00:00" + "time": "2021-09-25T07:37:20+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1313,6 +1463,10 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/1.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1383,6 +1537,10 @@ "compare", "equality" ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/3.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1445,6 +1603,10 @@ "unidiff", "unified diff" ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/3.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1504,6 +1666,10 @@ "environment", "hhvm" ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/4.2.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1577,6 +1743,10 @@ "export", "exporter" ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/3.1.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1637,6 +1807,10 @@ "keywords": [ "global state" ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/3.0.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1690,6 +1864,10 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/3.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1741,6 +1919,10 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/1.1.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1800,6 +1982,10 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/3.0.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1848,12 +2034,17 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/2.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" } ], + "abandoned": true, "time": "2020-11-30T07:30:19+00:00" }, { @@ -1900,6 +2091,10 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/1.1.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1949,6 +2144,10 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/master" + }, "time": "2016-10-03T07:35:21+00:00" }, { @@ -2011,6 +2210,9 @@ "polyfill", "portable" ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -2029,16 +2231,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -2065,13 +2267,17 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + }, "funding": [ { "url": "https://github.com/theseer", "type": "github" } ], - "time": "2020-07-12T23:59:07+00:00" + "time": "2021-07-28T10:34:58+00:00" }, { "name": "webmozart/assert", @@ -2125,6 +2331,10 @@ "check", "validate" ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.10.0" + }, "time": "2021-03-09T10:59:23+00:00" } ], @@ -2137,5 +2347,5 @@ "php": ">=7.2.0" }, "platform-dev": [], - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.1.0" } diff --git a/src/Rule/BaseRule.php b/src/Rule/BaseRule.php index a345a7b..cadab99 100644 --- a/src/Rule/BaseRule.php +++ b/src/Rule/BaseRule.php @@ -244,7 +244,7 @@ public function elementContainsReadableText($element) public function setIssue($element, $ruleId = null, $metadata = null) { - if (!$ruleId) { + if (!isset($ruleId)) { $ruleId = $this->id(); } diff --git a/src/Rule/VideoScan.php b/src/Rule/VideoScan.php index 4e70e63..d15cf88 100644 --- a/src/Rule/VideoScan.php +++ b/src/Rule/VideoScan.php @@ -14,11 +14,14 @@ */ class VideoScan extends BaseRule { - const FAIL = 0; const FAILED_CONNECTION = 1; const SUCCESS = 2; + public $youtube = null; + public $vimeo = null; + public $kaltura = null; + public function id() { return self::class; @@ -34,15 +37,17 @@ public function check() // Get provider (Youtube, Vimeo, or Kaltura class) $provider = $this->getVideoProvider($attr_val); // Get caption data - $captionData = $provider->getVideoData($attr_val); + $captionData = $this->getCaptionData($attr_val, $provider); - if($captionData && $provider) { + if(isset($captionData) && isset($provider)) { $this->checkCaptionsExist($captionData, $provider, $video); $this->checkCaptionsLanguage($captionData, $provider, $video); $this->checkCaptionsAutoGenerated($captionData, $provider, $video); } } } + + return count($this->issues); } // Scan rule functions @@ -54,7 +59,7 @@ public function checkCaptionsExist($captionData, $provider, $video) if (method_exists($provider, 'captionsMissing')) { $captionState = $provider->captionsMissing($captionData); - if ($captionState !== self::SUCCESS) { + if ($captionState != self::SUCCESS) { $this->setIssue($video, 'VideosEmbeddedOrLinkedNeedCaptions'); } } @@ -65,9 +70,9 @@ public function checkCaptionsLanguage($captionData, $provider, $video) { // Use provider to call if (method_exists($provider, 'captionsLanguage')) { - $captionState = $provider->captionsMissing($captionData); - - if ($captionState !== self::SUCCESS) { + $captionState = $provider->captionsLanguage($captionData); + + if ($captionState != self::SUCCESS) { $this->setIssue($video, 'VideoCaptionsMatchCourseLanguage'); } } @@ -78,9 +83,9 @@ public function checkCaptionsAutoGenerated($captionData, $provider, $video) { // Use provider to call if (method_exists($provider, 'captionsAutoGenerated')) { - $captionState = $provider->captionsMissing($captionData); + $captionState = $provider->captionsAutoGenerated($captionData); - if ($captionState !== self::SUCCESS) { + if ($captionState != self::SUCCESS) { $this->setIssue($video, 'VideosHaveAutoGeneratedCaptions'); } } @@ -95,13 +100,31 @@ public function getVideoProvider($url) $search_kaltura = '/(kaltura)/'; if (preg_match($search_youtube, $url)) { - return new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); + if (!isset($this->youtube)) { + $this->youtube = new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']); + } + return $this->youtube; } elseif (preg_match($search_vimeo, $url)) { - return new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); + if (!isset($this->vimeo)) { + $this->vimeo = new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']); + } + return $this->vimeo; } else if (preg_match($search_kaltura, $url)) { - return new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); + if (!isset($this->kaltura)) { + $this->kaltura = new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']); + } + return $this->kaltura; } - return false; + return null; + } + + public function getCaptionData($url, $provider) + { + if (isset($provider)) { + return $provider->getVideoData($url); + } + + return null; } } \ No newline at end of file diff --git a/src/Video/Kaltura.php b/src/Video/Kaltura.php index dae9f19..1c97a34 100644 --- a/src/Video/Kaltura.php +++ b/src/Video/Kaltura.php @@ -34,7 +34,7 @@ public function __construct($language = 'en', $api_key = '', $username = '') */ function captionsMissing($captionData) { - if($result->totalCount === 0) { + if($captionData->totalCount === 0) { return self::KALTURA_FAIL; } @@ -46,16 +46,16 @@ function captionsMissing($captionData) * @param string $link_url The URL to the video or video resource * @return int 0 if captions are manual and wrong language, 1 if video is private, 2 if there are no captions or if manually generated and correct language */ - function captionsLanguage($link_url) + function captionsLanguage($captionData) { - $captionsArray = $result->objects; + $captionsArray = $captionData->objects; foreach($captionsArray as $caption) { if(substr($caption->languageCode, 0, 2) === substr($this->language, 0, 2)) { return self::KALTURA_SUCCESS; } } - return self::KALTURA_FAIL; + return empty($captionsArray) ? self::KALTURA_SUCCESS : self::KALTURA_FAIL; } /** @@ -123,7 +123,7 @@ function getVideoData($link_url) return $result; } - return false; + return null; } } \ No newline at end of file diff --git a/src/Video/Vimeo.php b/src/Video/Vimeo.php index dbfebe7..93214f1 100644 --- a/src/Video/Vimeo.php +++ b/src/Video/Vimeo.php @@ -102,6 +102,6 @@ function getVideoData($link_url) ]]); } - return false; + return null; } } diff --git a/src/Video/Youtube.php b/src/Video/Youtube.php index 1d6d2df..49ea056 100644 --- a/src/Video/Youtube.php +++ b/src/Video/Youtube.php @@ -64,7 +64,7 @@ public function captionsAutoGenerated($captionData) } } - return self::YOUTUBE_FAIL; + return empty($items) ? self::YOUTUBE_SUCCESS : self::YOUTUBE_FAIL; } /** @@ -138,6 +138,6 @@ function getVideoData($link_url) return $response; } - return false; + return null; } } diff --git a/src/rules.json b/src/rules.json index d5a771e..5f9fcf4 100644 --- a/src/rules.json +++ b/src/rules.json @@ -31,10 +31,7 @@ "CidiLabs\\PhpAlly\\Rule\\PreShouldNotBeUsedForTabularValues", "CidiLabs\\PhpAlly\\Rule\\TableDataShouldHaveTableHeader", "CidiLabs\\PhpAlly\\Rule\\TableHeaderShouldHaveScope", - "CidiLabs\\PhpAlly\\Rule\\VideoCaptionsMatchCourseLanguage", "CidiLabs\\PhpAlly\\Rule\\VideoEmbedCheck", "CidiLabs\\PhpAlly\\Rule\\VideoProvidesCaptions", - "CidiLabs\\PhpAlly\\Rule\\VideosEmbeddedOrLinkedNeedCaptions", - "CidiLabs\\PhpAlly\\Rule\\VideosHaveAutoGeneratedCaptions", - "CidiLabs\\PhpAlly\\Rule\\VideosScan" + "CidiLabs\\PhpAlly\\Rule\\VideoScan" ] diff --git a/tests/KalturaTest.php b/tests/KalturaTest.php index c36bc3b..44ad4b3 100644 --- a/tests/KalturaTest.php +++ b/tests/KalturaTest.php @@ -1,28 +1,30 @@ getMockBuilder(Kaltura::class) - ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $this->assertEquals($kalturaMock->captionsMissing($link_url), 2); - } + // $this->assertEquals($kalturaMock->captionsMissing($link_url), 2); + // } public function testCaptionsMissingSuccess() { - $link_url = $this->test_url; - $json = '{ + // $link_url = $this->test_url; + + $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); + $response = json_decode('{ "objects": [ { "languageCode": "en" @@ -30,58 +32,60 @@ public function testCaptionsMissingSuccess() ], "totalCount": 1, "objectType": "KalturaCaptionAssetListResponse" - }'; + }'); - $kalturaMock = $this->getMockBuilder(Kaltura::class) - ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $kalturaMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue(json_decode($json))); + // $kalturaMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kalturaMock->captionsMissing($link_url), 2); + $this->assertEquals($kaltura->captionsMissing($response), 2); } public function testCaptionsMissingFailure() { - $link_url = $this->test_url; - $json = '{ + // $link_url = $this->test_url; + $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); + $response = json_decode('{ "objects": [], "totalCount": 0, "objectType": "KalturaCaptionAssetListResponse" - }'; + }'); - $kalturaMock = $this->getMockBuilder(Kaltura::class) - ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $kalturaMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue(json_decode($json))); + // $kalturaMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kalturaMock->captionsMissing($link_url), 0); + $this->assertEquals($kaltura->captionsMissing($response), 0); } - public function testCaptionsLanguageInvalidURL() - { - $link_url = 'fakeUrl'; - $result = false; + // public function testCaptionsLanguageInvalidURL() + // { + // // $link_url = 'fakeUrl'; + // $result = false; - $kalturaMock = $this->getMockBuilder(Kaltura::class) - ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $this->assertEquals($kalturaMock->captionsLanguage($link_url), 2); - } + // $this->assertEquals($kalturaMock->captionsLanguage($link_url), 2); + // } public function testCaptionsLanguageSuccess() { - $link_url = $this->test_url; - $json = '{ + // $link_url = $this->test_url; + $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); + $response = json_decode('{ "objects": [ { "languageCode": "en" @@ -89,45 +93,47 @@ public function testCaptionsLanguageSuccess() ], "totalCount": 1, "objectType": "KalturaCaptionAssetListResponse" - }'; + }'); - $kalturaMock = $this->getMockBuilder(Kaltura::class) - ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $kalturaMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue(json_decode($json))); + // $kalturaMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kalturaMock->captionsLanguage($link_url), 2); + $this->assertEquals($kaltura->captionsLanguage($response), 2); } public function testCaptionsLanguageFailureEmpty() { - $link_url = $this->test_url; - $json = '{ + // $link_url = $this->test_url; + $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); + $response = json_decode('{ "objects": [], "totalCount": 0, "objectType": "KalturaCaptionAssetListResponse" - }'; + }'); - $kalturaMock = $this->getMockBuilder(Kaltura::class) - ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $kalturaMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue(json_decode($json))); + // $kalturaMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kalturaMock->captionsLanguage($link_url), 0); + $this->assertEquals($kaltura->captionsLanguage($response), 2); } public function testCaptionsLanguageFailureWrongLanguage() { - $link_url = $this->test_url; - $json = '{ + // $link_url = $this->test_url; + $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); + $response = json_decode('{ "objects": [ { "languageCode": "es" @@ -135,24 +141,25 @@ public function testCaptionsLanguageFailureWrongLanguage() ], "totalCount": 0, "objectType": "KalturaCaptionAssetListResponse" - }'; + }'); - $kalturaMock = $this->getMockBuilder(Kaltura::class) - ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $kalturaMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue(json_decode($json))); + // $kalturaMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kalturaMock->captionsLanguage($link_url), 0); + $this->assertEquals($kaltura->captionsLanguage($response), 0); } public function testCaptionsLanguageFailureWrongLanguageInverse() { - $link_url = $this->test_url; - $json = '{ + // $link_url = $this->test_url; + $kaltura = new Kaltura('es', 'testApiKey', 'testEmail'); + $response = json_decode('{ "objects": [ { "languageCode": "en" @@ -160,18 +167,18 @@ public function testCaptionsLanguageFailureWrongLanguageInverse() ], "totalCount": 0, "objectType": "KalturaCaptionAssetListResponse" - }'; + }'); - $kalturaMock = $this->getMockBuilder(Kaltura::class) - ->setConstructorArgs(['es', 'testApiKey', 'testEmail']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $kalturaMock = $this->getMockBuilder(Kaltura::class) + // ->setConstructorArgs(['es', 'testApiKey', 'testEmail']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $kalturaMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue(json_decode($json))); + // $kalturaMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kalturaMock->captionsLanguage($link_url), 0); + $this->assertEquals($kaltura->captionsLanguage($response), 0); } } \ No newline at end of file diff --git a/tests/VideoCaptionsMatchCourseLanguageTest.php b/tests/VideoCaptionsMatchCourseLanguageTest.php deleted file mode 100644 index f852a34..0000000 --- a/tests/VideoCaptionsMatchCourseLanguageTest.php +++ /dev/null @@ -1,118 +0,0 @@ -Valid Link'; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'test', - 'youtubeApiKey' => 'test', - 'kalturaApiKey' => 'test', - 'kalturaUsername' => 'test' - ]; - - $ruleMock = $this->getMockBuilder(VideoCaptionsMatchCourseLanguage::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->once()) - ->method('getCaptionState') - ->will($this->returnValue(0)); - - $this->assertEquals(1, $ruleMock->check()); - } - - public function testCheckNoIssuesRightLanguage() - { - $html = '
Valid Link
'; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'test', - 'youtubeApiKey' => 'test', - 'kalturaApiKey' => 'test', - 'kalturaUsername' => 'test' - ]; - - $ruleMock = $this->getMockBuilder(VideoCaptionsMatchCourseLanguage::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->once()) - ->method('getCaptionState') - ->will($this->returnValue(2)); - - $this->assertEquals(0, $ruleMock->check()); - } - - public function testCheckNoIssuesVimeo() - { - $html = '
Valid Link
'; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'bef37736cfb26b6dc52986d8f531d0ad', - 'youtubeApiKey' => 'AIzaSyB5bTf8rbYwiM73k1rj8dDnwEalwTqdz_c' - ]; - $ruleMock = $this->getMockBuilder(VideoCaptionsMatchCourseLanguage::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->once()) - ->method('getCaptionState') - ->will($this->returnValue(2)); - - $this->assertEquals(0, $ruleMock->check()); - } - - public function testCheckNoIssuesKaltura() - { - $html = '
Valid Link
'; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'bef37736cfb26b6dc52986d8f531d0ad', - 'youtubeApiKey' => 'AIzaSyB5bTf8rbYwiM73k1rj8dDnwEalwTqdz_c' - ]; - $ruleMock = $this->getMockBuilder(VideoCaptionsMatchCourseLanguage::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->once()) - ->method('getCaptionState') - ->will($this->returnValue(2)); - - $this->assertEquals(0, $ruleMock->check()); - } - - public function testCheckNoIssuesUnsupportedSite() - { - $html = '
Valid Link
'; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'bef37736cfb26b6dc52986d8f531d0ad', - 'youtubeApiKey' => 'AIzaSyB5bTf8rbYwiM73k1rj8dDnwEalwTqdz_c' - ]; - $ruleMock = $this->getMockBuilder(VideoCaptionsMatchCourseLanguage::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->once()) - ->method('getCaptionState') - ->will($this->returnValue(2)); - - $this->assertEquals(0, $ruleMock->check()); - } - - -} \ No newline at end of file diff --git a/tests/VideoScanTest.php b/tests/VideoScanTest.php new file mode 100644 index 0000000..5452387 --- /dev/null +++ b/tests/VideoScanTest.php @@ -0,0 +1,118 @@ +'; + $dom = new \DOMDocument('1.0', 'utf-8'); + $dom->loadHTML($html); + $options = [ + 'vimeoApiKey' => 'test', + 'youtubeApiKey' => 'test', + 'kalturaApiKey' => 'test', + 'kalturaUsername' => 'test' + ]; + $string = '{ + "items": [] + }'; + $response = new Response(200, ['Content-Type' => 'application/json'], $string); + + $ruleMock = $this->getMockBuilder(VideoScan::class) + ->setConstructorArgs([$dom, $options]) + ->setMethods(array('getCaptionData')) + ->getMock(); + + $ruleMock->expects($this->once()) + ->method('getCaptionData') + ->will($this->returnValue($response)); + + $this->assertEquals(1, $ruleMock->check()); + } + + public function testCheckEmptyVimeo() + { + $html = ''; + $dom = new \DOMDocument('1.0', 'utf-8'); + $dom->loadHTML($html); + $options = [ + 'vimeoApiKey' => 'test', + 'youtubeApiKey' => 'test', + 'kalturaApiKey' => 'test', + 'kalturaUsername' => 'test' + ]; + $string = '{ + "total": 0, + "data": [] + }'; + $response = new Response(200, ['Content-Type' => 'application/json'], $string); + + $ruleMock = $this->getMockBuilder(VideoScan::class) + ->setConstructorArgs([$dom, $options]) + ->setMethods(array('getCaptionData')) + ->getMock(); + + $ruleMock->expects($this->once()) + ->method('getCaptionData') + ->will($this->returnValue($response)); + + $this->assertEquals(1, $ruleMock->check()); + } + + public function testCheckEmptyKaltura() + { + $html = ''; + $dom = new \DOMDocument('1.0', 'utf-8'); + $dom->loadHTML($html); + $options = [ + 'vimeoApiKey' => 'test', + 'youtubeApiKey' => 'test', + 'kalturaApiKey' => 'test', + 'kalturaUsername' => 'test' + ]; + $response = json_decode('{ + "objects": [], + "totalCount": 0, + "objectType": "KalturaCaptionAssetListResponse" + }'); + + $ruleMock = $this->getMockBuilder(VideoScan::class) + ->setConstructorArgs([$dom, $options]) + ->setMethods(array('getCaptionData')) + ->getMock(); + + $ruleMock->expects($this->once()) + ->method('getCaptionData') + ->will($this->returnValue($response)); + + $this->assertEquals(1, $ruleMock->check()); + } + + public function testCheckNoApiKey() + { + $html = ['', + '', '
Valid Link
']; + $options = [ + 'vimeoApiKey' => '', + 'youtubeApiKey' => '', + 'kalturaApiKey' => '', + 'kalturaUsername' => '' + ]; + foreach ($html as $video) { + $dom = new \DOMDocument('1.0', 'utf-8'); + $dom->loadHTML($video); + + $ruleMock = $this->getMockBuilder(VideoScan::class) + ->setConstructorArgs([$dom, $options]) + ->getMock(); + + $this->assertEquals(0, $ruleMock->check()); + } + } +} \ No newline at end of file diff --git a/tests/VideosEmbdeddedOrLinkedNeedCaptionsTest.php b/tests/VideosEmbdeddedOrLinkedNeedCaptionsTest.php deleted file mode 100644 index ae010e3..0000000 --- a/tests/VideosEmbdeddedOrLinkedNeedCaptionsTest.php +++ /dev/null @@ -1,56 +0,0 @@ - - '; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'test', - 'youtubeApiKey' => 'test', - 'kalturaApiKey' => 'test', - 'kalturaUsername' => 'test' - ]; - - $ruleMock = $this->getMockBuilder(VideosEmbeddedOrLinkedNeedCaptions::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->exactly(2)) - ->method('getCaptionState') - ->will($this->returnValue(0)); - - $this->assertEquals(2, $ruleMock->check()); - } - - public function testCaptionsMissingHasCaptions() - { - $html = ' - '; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'test', - 'youtubeApiKey' => 'test', - 'kalturaApiKey' => 'test', - 'kalturaUsername' => 'test' - ]; - - $ruleMock = $this->getMockBuilder(VideosEmbeddedOrLinkedNeedCaptions::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->exactly(2)) - ->method('getCaptionState') - ->will($this->returnValue(2)); - - $this->assertEquals(0, $ruleMock->check()); - } -} \ No newline at end of file diff --git a/tests/VideosHaveAutoGeneratedCaptionsTest.php b/tests/VideosHaveAutoGeneratedCaptionsTest.php deleted file mode 100644 index d317d53..0000000 --- a/tests/VideosHaveAutoGeneratedCaptionsTest.php +++ /dev/null @@ -1,54 +0,0 @@ -'; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'test', - 'youtubeApiKey' => 'test', - 'kalturaApiKey' => 'test', - 'kalturaUsername' => 'test' - ]; - - $ruleMock = $this->getMockBuilder(VideosHaveAutoGeneratedCaptions::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->once()) - ->method('getCaptionState') - ->will($this->returnValue(0)); - - $this->assertEquals(1, $ruleMock->check()); - } - - public function testCaptionsMissingHasCaptions() - { - $html = ''; - $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); - $options = [ - 'vimeoApiKey' => 'test', - 'youtubeApiKey' => 'test', - 'kalturaApiKey' => 'test', - 'kalturaUsername' => 'test' - ]; - - $ruleMock = $this->getMockBuilder(VideosHaveAutoGeneratedCaptions::class) - ->setConstructorArgs([$dom, $options]) - ->setMethods(array('getCaptionState')) - ->getMock(); - - $ruleMock->expects($this->once()) - ->method('getCaptionState') - ->will($this->returnValue(2)); - - $this->assertEquals(0, $ruleMock->check(), 'Youtube Test should return 0 failed tests to indicate no missing captions'); - } -} \ No newline at end of file diff --git a/tests/VimeoTest.php b/tests/VimeoTest.php index af101c8..2d9f894 100644 --- a/tests/VimeoTest.php +++ b/tests/VimeoTest.php @@ -1,6 +1,6 @@ link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 0, "data": [] }'; + + $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $vimeoMock = $this->getMockBuilder(Vimeo::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $vimeoMock = $this->getMockBuilder(Vimeo::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $vimeoMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $vimeoMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($vimeoMock->captionsMissing($link_url), 0); + $this->assertEquals($vimeo->captionsMissing($response), 0); } public function testCaptionsMissingHasCaptions() { - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 2, "data": [{"language": "en"}, {"language": "es"}] }'; + + $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $vimeoMock = $this->getMockBuilder(Vimeo::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $vimeoMock = $this->getMockBuilder(Vimeo::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $vimeoMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $vimeoMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($vimeoMock->captionsMissing($link_url), 2); + $this->assertEquals($vimeo->captionsMissing($response), 2); } public function testCaptionsLanguage() { - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 1, "data": [{"language": "en"}] }'; + + $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $vimeoMock = $this->getMockBuilder(Vimeo::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $vimeoMock = $this->getMockBuilder(Vimeo::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $vimeoMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $vimeoMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($vimeoMock->captionsLanguage($link_url), 2); + $this->assertEquals($vimeo->captionsLanguage($response), 2); } public function testCaptionsLanguageFailure() { - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 1, "data": [{"language": "es"}] }'; + + $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $vimeoMock = $this->getMockBuilder(Vimeo::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $vimeoMock = $this->getMockBuilder(Vimeo::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $vimeoMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $vimeoMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($vimeoMock->captionsLanguage($link_url), 0); + $this->assertEquals($vimeo->captionsLanguage($response), 0); } diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 1e3bfef..4ef4a83 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -1,6 +1,6 @@ link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [] }'; + + $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $youtubeMock = $this->getMockBuilder(Youtube::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $youtubeMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($youtubeMock->captionsMissing($link_url), 0); + $this->assertEquals($youtube->captionsMissing($response), 0); } public function testCaptionsMissingHasCaptions() { - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -49,22 +51,24 @@ public function testCaptionsMissingHasCaptions() } ] }'; + + $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $youtubeMock = $this->getMockBuilder(Youtube::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $youtubeMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($youtubeMock->captionsMissing($link_url), 2); + $this->assertEquals($youtube->captionsMissing($response), 2); } public function testCaptionsLanguageFail(){ - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -82,22 +86,24 @@ public function testCaptionsLanguageFail(){ } ] }'; + + $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $youtubeMock = $this->getMockBuilder(Youtube::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $youtubeMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($youtubeMock->captionsLanguage($link_url), 0); + $this->assertEquals($youtube->captionsLanguage($response), 0); } public function testCaptionsLanguageSuccess(){ - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -115,22 +121,81 @@ public function testCaptionsLanguageSuccess(){ } ] }'; + + $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $youtubeMock = $this->getMockBuilder(Youtube::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $youtubeMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($youtubeMock->captionsLanguage($link_url), 2); + $this->assertEquals($youtube->captionsLanguage($response), 2); + } + + public function testCaptionsLanguageEmpty(){ + // $link_url = $this->link_url; + $client = new \GuzzleHttp\Client(['http_errors' => false]); + $string = '{ + "items": [] + }'; + + $youtube = new Youtube($client, 'en', 'testApiKey'); + $response = new Response(200, ['Content-Type' => 'application/json'], $string); + + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); + + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); + + $this->assertEquals($youtube->captionsLanguage($response), 2); + } + + public function testCaptionsNoLanguage(){ + // $link_url = $this->link_url; + $client = new \GuzzleHttp\Client(['http_errors' => false]); + $string = '{ + "items": [ + { + "snippet": { + "trackKind": "standard", + "language": "en" + } + }, + { + "snippet": { + "trackKind": "standard", + "language": "es-419" + } + } + ] + }'; + + $youtube = new Youtube($client, '', 'testApiKey'); + $response = new Response(200, ['Content-Type' => 'application/json'], $string); + + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); + + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); + + $this->assertEquals($youtube->captionsLanguage($response), 2); } public function testCaptionsAutoGeneratedFailure(){ - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -142,22 +207,24 @@ public function testCaptionsAutoGeneratedFailure(){ } ] }'; + + $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $youtubeMock = $this->getMockBuilder(Youtube::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $youtubeMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($youtubeMock->captionsAutoGenerated($link_url), 0); + $this->assertEquals($youtube->captionsAutoGenerated($response), 0); } public function testCaptionsAutoGeneratedSuccess(){ - $link_url = $this->link_url; + // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -175,18 +242,20 @@ public function testCaptionsAutoGeneratedSuccess(){ } ] }'; + + $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - $youtubeMock = $this->getMockBuilder(Youtube::class) - ->setConstructorArgs([$client, 'en', 'testApiKey']) - ->onlyMethods(array('getVideoData')) - ->getMock(); + // $youtubeMock = $this->getMockBuilder(Youtube::class) + // ->setConstructorArgs([$client, 'en', 'testApiKey']) + // ->onlyMethods(array('getVideoData')) + // ->getMock(); - $youtubeMock->expects($this->once()) - ->method('getVideoData') - ->will($this->returnValue($response)); + // $youtubeMock->expects($this->once()) + // ->method('getVideoData') + // ->will($this->returnValue($response)); - $this->assertEquals($youtubeMock->captionsAutoGenerated($link_url), 2); + $this->assertEquals($youtube->captionsAutoGenerated($response), 2); } } \ No newline at end of file From b0c011bdd3046f11e3cd9c3ef7cb83ed9776382f Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Mon, 18 Oct 2021 10:31:58 -0400 Subject: [PATCH 5/8] removing/adding comments --- src/Video/Kaltura.php | 6 +-- src/Video/Vimeo.php | 5 +++ src/Video/Youtube.php | 16 ++++++-- tests/KalturaTest.php | 89 ------------------------------------------- tests/VimeoTest.php | 42 -------------------- tests/YoutubeTest.php | 82 --------------------------------------- 6 files changed, 21 insertions(+), 219 deletions(-) diff --git a/src/Video/Kaltura.php b/src/Video/Kaltura.php index 1c97a34..95a26cd 100644 --- a/src/Video/Kaltura.php +++ b/src/Video/Kaltura.php @@ -29,7 +29,7 @@ public function __construct($language = 'en', $api_key = '', $username = '') /** * Checks to see if a video is missing caption information in Kaltura - * @param string $link_url The URL to the video or video resource + * @param object $captionData The caption data for the video * @return int 0 if captions are missing, 1 if video is private, 2 if captions exist or not a video */ function captionsMissing($captionData) @@ -43,7 +43,7 @@ function captionsMissing($captionData) /** * Checks to see if a video is missing caption information in YouTube - * @param string $link_url The URL to the video or video resource + * @param object $captionData The caption data for the video * @return int 0 if captions are manual and wrong language, 1 if video is private, 2 if there are no captions or if manually generated and correct language */ function captionsLanguage($captionData) @@ -89,7 +89,7 @@ function getPartnerID($link_url) /** * Makes the api call to get the caption data for the video. * @param string $link_url The URL to the video or video resource - * @return mixed FALSE if the api calls fails or its not a Kaltura video, + * @return mixed null if the api calls fails or its not a Kaltura video, * or an array of caption objects if it is */ function getVideoData($link_url) diff --git a/src/Video/Vimeo.php b/src/Video/Vimeo.php index 93214f1..6d4124c 100644 --- a/src/Video/Vimeo.php +++ b/src/Video/Vimeo.php @@ -90,6 +90,11 @@ private function isVimeoVideo($link_url) return false; } + /** + * Gets the caption data from the youtube api + * @param string $link_url The URL to the video or video resource + * @return mixed $response Returns response object if api call can be made, null otherwise + */ function getVideoData($link_url) { $key_trimmed = trim($this->api_key); diff --git a/src/Video/Youtube.php b/src/Video/Youtube.php index 49ea056..b4f1138 100644 --- a/src/Video/Youtube.php +++ b/src/Video/Youtube.php @@ -35,7 +35,7 @@ public function __construct(Client $client, $language = 'en', $api_key) /** * Checks to see if a video is missing caption information in YouTube - * @param string $link_url The URL to the video or video resource + * @param object $captionData The caption data for the video * @return int 0 if captions are missing, 1 if video is private, 2 if captions exist or not a video */ public function captionsMissing($captionData) @@ -49,6 +49,11 @@ public function captionsMissing($captionData) return !(empty($items)) ? self::YOUTUBE_SUCCESS : self::YOUTUBE_FAIL; } + /** + * Checks to see if a video is missing caption information in YouTube + * @param object $captionData The caption data for the video + * @return int 0 if captions are missing, 1 if video is private, 2 if captions exist or not a video + */ public function captionsAutoGenerated($captionData) { if ($captionData->getStatusCode() >= 400) { @@ -69,8 +74,8 @@ public function captionsAutoGenerated($captionData) /** * Checks to see if a video is missing caption information in YouTube - * @param string $link_url The URL to the video or video resource - * @return int 0 if captions are manual and wrong language, 1 if video is private, 2 if captions are auto-generated or manually generated and correct language + * @param object $captionData The caption data for the video + * @return int 0 if captions are missing, 1 if video is private, 2 if captions exist or not a video */ public function captionsLanguage($captionData) { @@ -127,6 +132,11 @@ function isYouTubeVideo($link_url) return false; } + /** + * Gets the caption data from the youtube api + * @param string $link_url The URL to the video or video resource + * @return mixed $response Returns response object if api call can be made, null otherwise + */ function getVideoData($link_url) { $key_trimmed = trim($this->api_key); diff --git a/tests/KalturaTest.php b/tests/KalturaTest.php index 44ad4b3..ce8461b 100644 --- a/tests/KalturaTest.php +++ b/tests/KalturaTest.php @@ -4,25 +4,8 @@ class KalturaTest extends PhpAllyTestCase { - private $test_url = 'https://cdnapisec.kaltura.com/p/4183983/sp/418398300/embedIframeJs/uiconf_id/48252953/partner_id/4183983?iframeembed=true&playerId=kaltura_player_1626379517&entry_id=1_qgxxsknz" width="400" height="333'; - - // public function testCaptionsMissingIvalidURL() - // { - // $link_url = 'fakeUrl'; - // $result = false; - - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $this->assertEquals($kalturaMock->captionsMissing($link_url), 2); - // } - public function testCaptionsMissingSuccess() { - // $link_url = $this->test_url; - $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); $response = json_decode('{ "objects": [ @@ -34,21 +17,11 @@ public function testCaptionsMissingSuccess() "objectType": "KalturaCaptionAssetListResponse" }'); - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $kalturaMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kaltura->captionsMissing($response), 2); } public function testCaptionsMissingFailure() { - // $link_url = $this->test_url; $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); $response = json_decode('{ "objects": [], @@ -56,34 +29,11 @@ public function testCaptionsMissingFailure() "objectType": "KalturaCaptionAssetListResponse" }'); - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $kalturaMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kaltura->captionsMissing($response), 0); } - // public function testCaptionsLanguageInvalidURL() - // { - // // $link_url = 'fakeUrl'; - // $result = false; - - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $this->assertEquals($kalturaMock->captionsLanguage($link_url), 2); - // } - public function testCaptionsLanguageSuccess() { - // $link_url = $this->test_url; $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); $response = json_decode('{ "objects": [ @@ -95,21 +45,11 @@ public function testCaptionsLanguageSuccess() "objectType": "KalturaCaptionAssetListResponse" }'); - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $kalturaMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kaltura->captionsLanguage($response), 2); } public function testCaptionsLanguageFailureEmpty() { - // $link_url = $this->test_url; $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); $response = json_decode('{ "objects": [], @@ -117,21 +57,11 @@ public function testCaptionsLanguageFailureEmpty() "objectType": "KalturaCaptionAssetListResponse" }'); - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $kalturaMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kaltura->captionsLanguage($response), 2); } public function testCaptionsLanguageFailureWrongLanguage() { - // $link_url = $this->test_url; $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); $response = json_decode('{ "objects": [ @@ -143,21 +73,11 @@ public function testCaptionsLanguageFailureWrongLanguage() "objectType": "KalturaCaptionAssetListResponse" }'); - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['en', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $kalturaMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kaltura->captionsLanguage($response), 0); } public function testCaptionsLanguageFailureWrongLanguageInverse() { - // $link_url = $this->test_url; $kaltura = new Kaltura('es', 'testApiKey', 'testEmail'); $response = json_decode('{ "objects": [ @@ -169,15 +89,6 @@ public function testCaptionsLanguageFailureWrongLanguageInverse() "objectType": "KalturaCaptionAssetListResponse" }'); - // $kalturaMock = $this->getMockBuilder(Kaltura::class) - // ->setConstructorArgs(['es', 'testApiKey', 'testEmail']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $kalturaMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue(json_decode($json))); - $this->assertEquals($kaltura->captionsLanguage($response), 0); } diff --git a/tests/VimeoTest.php b/tests/VimeoTest.php index 2d9f894..43d10fd 100644 --- a/tests/VimeoTest.php +++ b/tests/VimeoTest.php @@ -6,11 +6,8 @@ class VimeoTest extends PhpAllyTestCase { - private $link_url = 'https://vimeo.com/205755088'; - public function testCaptionsMissing() { - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 0, @@ -20,21 +17,11 @@ public function testCaptionsMissing() $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $vimeoMock = $this->getMockBuilder(Vimeo::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $vimeoMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($vimeo->captionsMissing($response), 0); } public function testCaptionsMissingHasCaptions() { - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 2, @@ -44,21 +31,11 @@ public function testCaptionsMissingHasCaptions() $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $vimeoMock = $this->getMockBuilder(Vimeo::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $vimeoMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($vimeo->captionsMissing($response), 2); } public function testCaptionsLanguage() { - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 1, @@ -68,21 +45,11 @@ public function testCaptionsLanguage() $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $vimeoMock = $this->getMockBuilder(Vimeo::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $vimeoMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($vimeo->captionsLanguage($response), 2); } public function testCaptionsLanguageFailure() { - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "total": 1, @@ -92,15 +59,6 @@ public function testCaptionsLanguageFailure() $vimeo = new Vimeo($client, 'en', 'testApikey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $vimeoMock = $this->getMockBuilder(Vimeo::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $vimeoMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($vimeo->captionsLanguage($response), 0); } diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 4ef4a83..788b309 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -6,11 +6,8 @@ class YoutubeTest extends PhpAllyTestCase { - private $link_url = 'https://www.youtube.com/watch?v=1xZxxVlu7BM'; - public function testCaptionsMissing() { - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [] @@ -19,21 +16,11 @@ public function testCaptionsMissing() $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsMissing($response), 0); } public function testCaptionsMissingHasCaptions() { - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -55,20 +42,10 @@ public function testCaptionsMissingHasCaptions() $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsMissing($response), 2); } public function testCaptionsLanguageFail(){ - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -90,20 +67,10 @@ public function testCaptionsLanguageFail(){ $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsLanguage($response), 0); } public function testCaptionsLanguageSuccess(){ - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -125,20 +92,10 @@ public function testCaptionsLanguageSuccess(){ $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsLanguage($response), 2); } public function testCaptionsLanguageEmpty(){ - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [] @@ -147,20 +104,10 @@ public function testCaptionsLanguageEmpty(){ $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsLanguage($response), 2); } public function testCaptionsNoLanguage(){ - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -182,20 +129,10 @@ public function testCaptionsNoLanguage(){ $youtube = new Youtube($client, '', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsLanguage($response), 2); } public function testCaptionsAutoGeneratedFailure(){ - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -211,20 +148,10 @@ public function testCaptionsAutoGeneratedFailure(){ $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsAutoGenerated($response), 0); } public function testCaptionsAutoGeneratedSuccess(){ - // $link_url = $this->link_url; $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ "items": [ @@ -246,15 +173,6 @@ public function testCaptionsAutoGeneratedSuccess(){ $youtube = new Youtube($client, 'en', 'testApiKey'); $response = new Response(200, ['Content-Type' => 'application/json'], $string); - // $youtubeMock = $this->getMockBuilder(Youtube::class) - // ->setConstructorArgs([$client, 'en', 'testApiKey']) - // ->onlyMethods(array('getVideoData')) - // ->getMock(); - - // $youtubeMock->expects($this->once()) - // ->method('getVideoData') - // ->will($this->returnValue($response)); - $this->assertEquals($youtube->captionsAutoGenerated($response), 2); } From 6891457320ce9377cbaeb89892a6fbf00abe89f6 Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Mon, 18 Oct 2021 12:22:55 -0400 Subject: [PATCH 6/8] adding default locale to kaltura language function and adding some tests --- src/Video/Kaltura.php | 8 +++++++- tests/KalturaTest.php | 38 +++++++++++++++++++++++++++++++++++--- tests/VimeoTest.php | 28 ++++++++++++++++++++++++++++ tests/YoutubeTest.php | 25 +++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 4 deletions(-) diff --git a/src/Video/Kaltura.php b/src/Video/Kaltura.php index 95a26cd..8a4eda4 100644 --- a/src/Video/Kaltura.php +++ b/src/Video/Kaltura.php @@ -48,10 +48,16 @@ function captionsMissing($captionData) */ function captionsLanguage($captionData) { + // If for whatever reason course_locale is blank, set it to English + $course_locale = $this->language; + if ($course_locale === '' || is_null($course_locale)) { + $course_locale = 'en'; + } + $captionsArray = $captionData->objects; foreach($captionsArray as $caption) { - if(substr($caption->languageCode, 0, 2) === substr($this->language, 0, 2)) { + if(substr($caption->languageCode, 0, 2) === substr($course_locale, 0, 2)) { return self::KALTURA_SUCCESS; } } diff --git a/tests/KalturaTest.php b/tests/KalturaTest.php index ce8461b..e63199f 100644 --- a/tests/KalturaTest.php +++ b/tests/KalturaTest.php @@ -48,7 +48,7 @@ public function testCaptionsLanguageSuccess() $this->assertEquals($kaltura->captionsLanguage($response), 2); } - public function testCaptionsLanguageFailureEmpty() + public function testCaptionsLanguageEmpty() { $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); $response = json_decode('{ @@ -60,7 +60,7 @@ public function testCaptionsLanguageFailureEmpty() $this->assertEquals($kaltura->captionsLanguage($response), 2); } - public function testCaptionsLanguageFailureWrongLanguage() + public function testCaptionsLanguageWrongLanguage() { $kaltura = new Kaltura('en', 'testApiKey', 'testEmail'); $response = json_decode('{ @@ -76,7 +76,7 @@ public function testCaptionsLanguageFailureWrongLanguage() $this->assertEquals($kaltura->captionsLanguage($response), 0); } - public function testCaptionsLanguageFailureWrongLanguageInverse() + public function testCaptionsLanguageWrongLanguageInverse() { $kaltura = new Kaltura('es', 'testApiKey', 'testEmail'); $response = json_decode('{ @@ -92,4 +92,36 @@ public function testCaptionsLanguageFailureWrongLanguageInverse() $this->assertEquals($kaltura->captionsLanguage($response), 0); } + public function testCaptionsNoLanguage() + { + $kaltura = new Kaltura('', 'testApiKey', 'testEmail'); + $response = json_decode('{ + "objects": [ + { + "languageCode": "en" + } + ], + "totalCount": 0, + "objectType": "KalturaCaptionAssetListResponse" + }'); + + $this->assertEquals($kaltura->captionsLanguage($response), 2); + } + + public function testCaptionsNoLanguageFailure() + { + $kaltura = new Kaltura('', 'testApiKey', 'testEmail'); + $response = json_decode('{ + "objects": [ + { + "languageCode": "es" + } + ], + "totalCount": 0, + "objectType": "KalturaCaptionAssetListResponse" + }'); + + $this->assertEquals($kaltura->captionsLanguage($response), 0); + } + } \ No newline at end of file diff --git a/tests/VimeoTest.php b/tests/VimeoTest.php index 43d10fd..8525b10 100644 --- a/tests/VimeoTest.php +++ b/tests/VimeoTest.php @@ -62,5 +62,33 @@ public function testCaptionsLanguageFailure() $this->assertEquals($vimeo->captionsLanguage($response), 0); } + public function testCaptionsNoLanguage() + { + $client = new \GuzzleHttp\Client(['http_errors' => false]); + $string = '{ + "total": 1, + "data": [{"language": "en"}] + }'; + + $vimeo = new Vimeo($client, '', 'testApikey'); + $response = new Response(200, ['Content-Type' => 'application/json'], $string); + + $this->assertEquals($vimeo->captionsLanguage($response), 2); + } + + public function testCaptionsNoLanguageFailure() + { + $client = new \GuzzleHttp\Client(['http_errors' => false]); + $string = '{ + "total": 1, + "data": [{"language": "es"}] + }'; + + $vimeo = new Vimeo($client, '', 'testApikey'); + $response = new Response(200, ['Content-Type' => 'application/json'], $string); + + $this->assertEquals($vimeo->captionsLanguage($response), 0); + } + } \ No newline at end of file diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 788b309..5dbcef7 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -132,6 +132,31 @@ public function testCaptionsNoLanguage(){ $this->assertEquals($youtube->captionsLanguage($response), 2); } + public function testCaptionsNoLanguageFailure(){ + $client = new \GuzzleHttp\Client(['http_errors' => false]); + $string = '{ + "items": [ + { + "snippet": { + "trackKind": "standard", + "language": "de" + } + }, + { + "snippet": { + "trackKind": "standard", + "language": "es-419" + } + } + ] + }'; + + $youtube = new Youtube($client, '', 'testApiKey'); + $response = new Response(200, ['Content-Type' => 'application/json'], $string); + + $this->assertEquals($youtube->captionsLanguage($response), 0); + } + public function testCaptionsAutoGeneratedFailure(){ $client = new \GuzzleHttp\Client(['http_errors' => false]); $string = '{ From 862ace4840bd967f41ef4491ebf852abd02c435a Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Thu, 21 Oct 2021 12:20:12 -0400 Subject: [PATCH 7/8] fixing getVideoData bug --- src/Rule/VideoScan.php | 2 +- src/Video/Kaltura.php | 5 ++++- src/Video/Vimeo.php | 3 ++- src/Video/Youtube.php | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Rule/VideoScan.php b/src/Rule/VideoScan.php index d15cf88..cdba227 100644 --- a/src/Rule/VideoScan.php +++ b/src/Rule/VideoScan.php @@ -71,7 +71,7 @@ public function checkCaptionsLanguage($captionData, $provider, $video) // Use provider to call if (method_exists($provider, 'captionsLanguage')) { $captionState = $provider->captionsLanguage($captionData); - + if ($captionState != self::SUCCESS) { $this->setIssue($video, 'VideoCaptionsMatchCourseLanguage'); } diff --git a/src/Video/Kaltura.php b/src/Video/Kaltura.php index 8a4eda4..f24b935 100644 --- a/src/Video/Kaltura.php +++ b/src/Video/Kaltura.php @@ -107,7 +107,10 @@ function getVideoData($link_url) return false; } - if ($video_id = $this->isKalturaVideo($link_url) && $partner_id = $this->getPartnerID($link_url)) { + $video_id = $this->isKalturaVideo($link_url); + $partner_id = $this->getPartnerID($link_url); + + if ($video_id && $partner_id) { $config = new KalturaConfiguration($partner_id); $config->setServiceUrl('https://www.kaltura.com'); diff --git a/src/Video/Vimeo.php b/src/Video/Vimeo.php index 6d4124c..adc6745 100644 --- a/src/Video/Vimeo.php +++ b/src/Video/Vimeo.php @@ -98,8 +98,9 @@ private function isVimeoVideo($link_url) function getVideoData($link_url) { $key_trimmed = trim($this->api_key); + $vimeo_id = $this->isVimeoVideo($link_url); - if ($vimeo_id = $this->isVimeoVideo($link_url) && !empty($key_trimmed)) { + if ($vimeo_id && !empty($key_trimmed)) { $url = $this->search_url . $vimeo_id . '/texttracks'; return $this->client->request('GET', $url, ['headers' => [ diff --git a/src/Video/Youtube.php b/src/Video/Youtube.php index b4f1138..0e35ab1 100644 --- a/src/Video/Youtube.php +++ b/src/Video/Youtube.php @@ -140,8 +140,9 @@ function isYouTubeVideo($link_url) function getVideoData($link_url) { $key_trimmed = trim($this->api_key); + $youtube_id = $this->isYouTubeVideo($link_url); - if ($youtube_id = $this->isYouTubeVideo($link_url) && !empty($key_trimmed)) { + if ($youtube_id && !empty($key_trimmed)) { $url = $this->search_url . $youtube_id . '&key=' . $this->api_key; $response = $this->client->request('GET', $url); From dabf532ef4f932db731e7598fc3cae34cde4f9ab Mon Sep 17 00:00:00 2001 From: Ethan Finlay Date: Wed, 27 Oct 2021 20:04:00 -0400 Subject: [PATCH 8/8] added logic in checkMany to replace specific video issue names with the VideoScan class --- src/PhpAlly.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PhpAlly.php b/src/PhpAlly.php index 6f16f2e..76fed4d 100644 --- a/src/PhpAlly.php +++ b/src/PhpAlly.php @@ -22,7 +22,11 @@ public function checkMany($content, $ruleIds = [], $options = []) foreach ($ruleIds as $ruleId) { try { - $className = $ruleId; + $className = str_replace( + ['VideosEmbeddedOrLinkedNeedCaptions','VideosHaveAutoGeneratedCaptions','VideoCaptionsMatchCourseLanguage'], + 'VideoScan', + $ruleId + ); if (!class_exists($className)) { $report->setError('Rule does not exist.'); continue;