You are here

class FeedsExJsonPathLinesUnitTests in Feeds extensible parsers 7.2

Unit tests for FeedsExJsonPathLines.

Hierarchy

Expanded class hierarchy of FeedsExJsonPathLinesUnitTests

File

src/Tests/FeedsExJsonPathLines.test, line 11
Contains FeedsExJsonPathLinesUnitTests.

View source
class FeedsExJsonPathLinesUnitTests extends FeedsExUnitTestBase {

  /**
   * The mocked FeedsSource.
   *
   * @var FeedsSource
   */
  protected $source;

  /**
   * The parser being tested.
   *
   * @var FeedsParser
   */
  protected $parser;

  /**
   * The fetcher result used during parsing.
   *
   * @var FeedsFetcherResult
   */
  protected $fetcherResult;
  public static function getInfo() {
    return array(
      'name' => 'JSONPath JSON lines parser unit tests',
      'description' => 'Unit tests for FeedsExJsonPathLines.',
      'group' => 'Feeds EX',
    );
  }
  public function setUp() {
    parent::setUp();
    require_once $this->moduleDir . '/src/FeedsExJsonPath.inc';
    require_once $this->moduleDir . '/src/FeedsExJsonPathLines.inc';
    $this
      ->downloadJsonPath();
    $this->source = $this
      ->getMockFeedsSource();
    $this->parser = FeedsConfigurable::instance('FeedsExJsonPathLines', 'test_parser');
    $this->parser
      ->addConfig(array(
      'sources' => array(
        'title' => array(
          'name' => 'Title',
          'value' => 'name',
        ),
      ),
    ));
    $this->fetcherResult = new FeedsFileFetcherResult($this->moduleDir . '/tests/resources/test.jsonl');
  }

  /**
   * Tests simple parsing.
   */
  public function testSimpleParsing() {
    $result = $this->parser
      ->parse($this->source, $this->fetcherResult);
    $this
      ->assertEqual(count($result->items), 4, format_string('@count items parsed.', array(
      '@count' => count($result->items),
    )));
    foreach (array(
      'Gilbert',
      'Alexa',
      'May',
      'Deloise',
    ) as $delta => $name) {
      $this
        ->assertEqual($name, $result->items[$delta]['title']);
    }
  }

  /**
   * Tests batch parsing.
   */
  public function testBatching() {
    $this
      ->variableSet('feeds_process_limit', 1);
    foreach (array(
      'Gilbert',
      'Alexa',
      'May',
      'Deloise',
    ) as $name) {
      $result = $this->parser
        ->parse($this->source, $this->fetcherResult);
      $this
        ->assertEqual(count($result->items), 1, format_string('@count items parsed.', array(
        '@count' => count($result->items),
      )));
      $this
        ->assertEqual($result->items[0]['title'], $name);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsExJsonPathLinesUnitTests::$fetcherResult protected property The fetcher result used during parsing.
FeedsExJsonPathLinesUnitTests::$parser protected property The parser being tested.
FeedsExJsonPathLinesUnitTests::$source protected property The mocked FeedsSource.
FeedsExJsonPathLinesUnitTests::getInfo public static function 1
FeedsExJsonPathLinesUnitTests::setUp public function Overrides FeedsExUnitTestBase::setUp 1
FeedsExJsonPathLinesUnitTests::testBatching public function Tests batch parsing.
FeedsExJsonPathLinesUnitTests::testSimpleParsing public function Tests simple parsing.
FeedsExUnitTestBase::$moduleDir protected property The module directory.
FeedsExUnitTestBase::downloadJsonPath protected function Downloads JSONPath.
FeedsExUnitTestBase::getMockFeedsSource protected function Returns a mocked FeedsSource object.