View source
<?php
namespace Drupal\Tests\contact_storage_export\Kernel;
use Drupal\contact\Entity\ContactForm;
use Drupal\contact\Entity\Message;
use Drupal\Tests\BrowserTestBase;
class ContactStorageExportBrowserTest extends BrowserTestBase {
public static $modules = [
'field',
'contact_storage',
'contact_storage_export',
'csv_serialization',
'contact',
'user',
'system',
'file',
];
public function testContactStorageExportBatch() {
$contact_form_id = 'contact_storage_export_form';
$contact_form = ContactForm::create([
'id' => $contact_form_id,
]);
$contact_form
->save();
$message = Message::create([
'id' => 1,
'contact_form' => $contact_form
->id(),
'name' => 'example',
'mail' => 'admin@example.com',
'created' => '1487321550',
'ip_address' => '127.0.0.1',
'subject' => 'Test subject',
'message' => 'Test message',
]);
$message
->save();
$account = $this
->drupalCreateUser([
'access administration pages',
'access site-wide contact form',
'administer contact forms',
'export contact form messages',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/structure/contact/manage/export', [
'query' => [
'contact_form' => $contact_form_id,
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'columns[id]' => 1,
'filename' => 'test.csv',
];
$this
->drupalPostForm(NULL, [], t('Export'));
$this
->drupalGet("admin/structure/contact/manage/export-download/{$contact_form_id}/0");
$this
->assertText(t('Your export is ready for download.'));
}
}