View source
<?php
namespace Drupal\Tests\juicebox\Functional;
use Drupal\file\Entity\File;
use Drupal\Component\Utility\Html;
class JuiceboxViewsCase extends JuiceboxCaseTestBase {
public static $modules = [
'node',
'text',
'field',
'image',
'editor',
'juicebox',
'views',
'contextual',
'juicebox_mimic_article',
'juicebox_test_views',
];
protected $instBundle = 'article';
protected $instFieldName = 'field_image';
public function setUp() {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'access content',
'access administration pages',
'administer site configuration',
'administer content types',
'administer nodes',
'bypass node access',
'access contextual links',
'use text format basic_html',
]);
$this
->drupalLogin($this->webUser);
$this
->createNodeWithFile('image', FALSE, FALSE);
$this
->drupalLogout();
}
public function testViewsAdvanced() {
$this
->drupalLogin($this->webUser);
$node = $this->node;
$xml_path = 'juicebox/xml/viewsstyle/juicebox_views_test/page_2';
$xml_url = \Drupal::url('juicebox.xml_viewsstyle', [
'viewName' => 'juicebox_views_test',
'displayName' => 'page_2',
]);
$uri = File::load($node->{$this->instFieldName}[0]->target_id)
->getFileUri();
$test_image_url = entity_load('image_style', 'juicebox_medium')
->buildUrl($uri);
$test_thumb_url = entity_load('image_style', 'juicebox_square_thumb')
->buildUrl($uri);
$this
->drupalGet('juicebox-views-test-advanced');
$this
->assertRaw(trim(json_encode([
'configUrl' => $xml_url,
]), '{}"'), 'Gallery setting found in Drupal.settings.');
$this
->assertRaw('juicebox-views-test--page-2', 'Embed code wrapper found.');
$this
->assertRaw(Html::escape(file_url_transform_relative($test_image_url)), 'Test image found in embed code');
$this
->drupalGet($xml_path);
$this
->assertRaw('<?xml version="1.0" encoding="UTF-8"?>', 'Valid XML detected.');
$this
->assertRaw('imageURL="' . Html::escape($test_image_url), 'Test image found in XML.');
$this
->assertRaw('thumbURL="' . Html::escape($test_thumb_url), 'Test thumbnail found in XML.');
$this
->drupalLogout();
$this
->drupalGet('juicebox/xml/viewsstyle/juicebox_views_test/page_2');
$this
->assertResponse(403, 'XML access blocked for access-restricted view.');
}
}