Skip to content

Commit

Permalink
Merge branch 'MDL-76230-master' of https://github.com/HuongNV13/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Nov 15, 2022
2 parents c4ad566 + 0bfa6e4 commit 3eec739
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
19 changes: 17 additions & 2 deletions blocks/tag_flickr/block_tag_flickr.php
Expand Up @@ -22,9 +22,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();
define('FLICKR_DEV_KEY', '4fddbdd7ff2376beec54d7f6afad425e');
define('DEFAULT_NUMBER_OF_PHOTOS', 6);

require_once("{$CFG->libdir}/flickrclient.php");

class block_tag_flickr extends block_base {

function init() {
Expand Down Expand Up @@ -102,7 +105,11 @@ function get_content() {

$response = $this->fetch_request($request);

$search = unserialize($response);
$search = @unserialize($response);
if ($search === false && $search != serialize(false)) {
// The response didn't appear to be anything serialized, exit...
return;
}

foreach ($search['photoset']['photo'] as $p){
$p['owner'] = $search['photoset']['owner'];
Expand All @@ -123,7 +130,11 @@ function get_content() {

$response = $this->fetch_request($request);

$search = unserialize($response);
$search = @unserialize($response);
if ($search === false && $search != serialize(false)) {
// The response didn't appear to be anything serialized, exit...
return;
}
$photos = array_values($search['photos']['photo']);
}

Expand All @@ -147,6 +158,10 @@ function get_content() {

function fetch_request($request){
$c = new curl(array('cache' => true, 'module_cache'=> 'tag_flickr'));
// Set custom user agent as Flickr blocks our "MoodleBot" agent string.
$c->setopt([
'CURLOPT_USERAGENT' => flickr_client::user_agent(),
]);

$response = $c->get($request);

Expand Down
28 changes: 22 additions & 6 deletions blocks/tag_flickr/tests/behat/configuring_tag_flickr_block.feature
Expand Up @@ -4,20 +4,36 @@ Feature: Adding and configuring Flickr block
As a admin
I need to add the Flickr block to the tags site page

@javascript
Scenario: Adding Flickr block to the tags site page
Given I log in as "admin"
Background:
# We need to create a user to use tag here because the tags site page only shows the tag that currently being used.
Given the following "users" exist:
| username | interests |
| student1 | Cats |
And I log in as "admin"
And I turn editing mode on
And the following config values are set as admin:
| unaddableblocks | | theme_boost|
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| tag_flickr | System | 1 | tag-search | side-post |
| tag_flickr | System | 1 | tag-index | side-post |
# TODO MDL-57120 site "Tags" link not accessible without navigation block.
And I add the "Navigation" block if not present
And I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Tags" "link" in the "Navigation" "block"
And I add the "Flickr" block
And I configure the "Flickr" block

@javascript
Scenario: Adding Flickr block to the tags site page
Given "block_tag_flickr" "block" should exist
When I configure the "Flickr" block
Then I should see "Flickr block title"
And I set the field "Flickr block title" to "The Flickr block header"
And I press "Save changes"
And "block_tag_flickr" "block" should exist
Then "The Flickr block header" "block" should exist
And "The Flickr block header" "block" should exist

@javascript
Scenario: Adding Flickr block to a specific tag page
Given I click on "Cats" "link"
Then "block_tag_flickr" "block" should exist
And ".flickr-photos" "css_element" should exist in the "block_tag_flickr" "block"

0 comments on commit 3eec739

Please sign in to comment.