MediaBrowserTest.php in Lightning Media 8.2
File
tests/src/ExistingSite/MediaBrowserTest.php
View source
<?php
namespace Drupal\Tests\lightning_media\ExistingSite;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\WebAssert;
use weitzman\DrupalTestTraits\ExistingSiteBase;
class MediaBrowserTest extends ExistingSiteBase {
private $assert;
public function setUp() {
parent::setUp();
$this->assert = new WebAssert($this
->getSession());
}
private function logIn(AccountInterface $account) {
$this
->assertNotEmpty($account->passRaw);
$this
->visit('/user/login');
$this->assert
->fieldExists('name')
->setValue($account
->getAccountName());
$this->assert
->fieldExists('pass')
->setValue($account->passRaw);
$this->assert
->buttonExists('Log in')
->press();
}
public function testUploadValidation() {
$account = $this
->createUser();
$account
->addRole('media_creator');
$account
->save();
$this
->logIn($account);
$this
->visit('/entity-browser/iframe/media_browser');
$this->assert
->statusCodeEquals(200);
$this->assert
->buttonExists('Upload')
->press();
$this->assert
->buttonExists('Place')
->press();
$this->assert
->pageTextContains('You must upload a file.');
$this->assert
->fieldExists('File')
->attachFile(__DIR__ . '/../../files/test.php');
$wrapper = $this->assert
->elementExists('css', '.js-form-managed-file');
$this->assert
->elementExists('named', [
'button',
'Upload',
], $wrapper)
->press();
$this->assert
->pageTextContains('Only files with the following extensions are allowed:');
$this->assert
->responseNotContains('<em class="placeholder">');
}
public function testEmbedCodeValidation() {
$account = $this
->createUser([
'access media_browser entity browser pages',
]);
$this
->logIn($account);
$this
->visit('/entity-browser/iframe/media_browser');
$this->assert
->statusCodeEquals(200);
$this->assert
->buttonExists('Create embed')
->press();
$this->assert
->buttonExists('Place')
->press();
$this->assert
->pageTextContains('You must enter a URL or embed code.');
$this->assert
->fieldExists('input')
->setValue('The quick brown fox gets eaten by hungry lions.');
$this->assert
->buttonExists('Update')
->press();
$this->assert
->buttonExists('Place')
->press();
$this->assert
->pageTextContains('Could not match any bundles to input:');
$this->assert
->fieldExists('input')
->setValue('https://twitter.com/webchick/status/824051274353999872');
$this->assert
->buttonExists('Update')
->press();
$entity = trim($this->assert
->elementExists('css', '#entity')
->getText());
$this
->assertEmpty($entity);
}
}