You are here

class CSVTest in Forena Reports 8

Test CSV @group Forena @require module forena @coversDefaultClass \Drupal\forena\FrxPlugin\Document\CSV

Hierarchy

Expanded class hierarchy of CSVTest

File

tests/src/Unit/Document/CSVTest.php, line 21

Namespace

Drupal\Tests\forena\Unit\Document
View source
class CSVTest extends FrxTestCase {

  /**
   * Test CSV formattting
   */
  private $table = '
  <div>
    <table>
      <thead>
        <tr>
          <th>col_1</th>
          <th>col_2</th>
        </tr>
      </thead>
      <tbody>
        <tr >
          <td>1</td>
          <td>2</td>
        </tr>
        <tr>
          <td>text, with, commas</td>
          <td>text without commas</td>
        </tr>
      </tbody>
    </table>
  </div>';

  /**
   * Table function
   */
  public function testCSV() {
    $doc = DocManager::instance()
      ->setDocument('csv');
    $doc
      ->header();
    $doc
      ->write($this->table);
    $doc
      ->footer();
    $report = $doc
      ->flush();

    // Check the headers
    $this
      ->assertContains("col_1,col_2", $report, 'Column Headers present');
    $this
      ->assertContains("1,2", $report, "Simple numbers present");
    $this
      ->assertContains('"text, with, commas",text without commas', $report);

    // Check headers
    $headers = $doc->headers;
    $this
      ->assertArrayHasKey('Content-Type', $headers);
    $this
      ->assertContains('application/csv', $headers['Content-Type']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CSVTest::$table private property Test CSV formattting
CSVTest::testCSV public function Table function
FrxAPI::app public function Returns containing application service
FrxAPI::currentDataContext public function Get the current data context.
FrxAPI::currentDataContextArray public function
FrxAPI::dataManager public function Returns the data manager service
FrxAPI::dataService public function Return Data Service
FrxAPI::documentManager public function Returns the fornea document manager
FrxAPI::error public function Report an error
FrxAPI::getDataContext public function Get the context of a specific id.
FrxAPI::getDocument public function Get the current document
FrxAPI::getReportFileContents public function Load the contents of a file in the report file system.
FrxAPI::innerXML function Enter description here... 1
FrxAPI::popData public function Pop data off of the stack.
FrxAPI::pushData public function Push data onto the Stack
FrxAPI::report public function Run a report with a particular format. 1
FrxAPI::reportFileSystem public function Get the current report file system.
FrxAPI::setDataContext public function Set Data context by id.
FrxAPI::setDocument public function Change to a specific document type.
FrxAPI::skins public function Get list of skins.
FrxTestCase::initParametersForm public function
FrxTestCase::setUp public function Mock object instantiation. Overrides UnitTestCase::setUp 2
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.