SimpleSitemapViewsTestBase.php 2.19 KB
Newer Older
WalkingDexter's avatar
WalkingDexter committed
1 2 3 4 5
<?php

namespace Drupal\Tests\simple_sitemap_views\Functional;

use Drupal\Tests\simple_sitemap\Functional\SimplesitemapTestBase;
WalkingDexter's avatar
WalkingDexter committed
6
use Drupal\simple_sitemap_views\SimpleSitemapViews;
7
use Drupal\views\Views;
WalkingDexter's avatar
WalkingDexter committed
8 9 10 11 12 13 14 15 16

/**
 * Defines a base class for Simple XML Sitemap (Views) functional testing.
 */
abstract class SimpleSitemapViewsTestBase extends SimplesitemapTestBase {

  /**
   * {@inheritdoc}
   */
WalkingDexter's avatar
WalkingDexter committed
17 18 19 20
  public static $modules = [
    'simple_sitemap_views',
    'simple_sitemap_views_test',
  ];
WalkingDexter's avatar
WalkingDexter committed
21 22 23 24 25 26 27 28

  /**
   * Views sitemap data.
   *
   * @var \Drupal\simple_sitemap_views\SimpleSitemapViews
   */
  protected $sitemapViews;

WalkingDexter's avatar
WalkingDexter committed
29 30 31 32 33 34 35
  /**
   * The cron service.
   *
   * @var \Drupal\Core\CronInterface
   */
  protected $cron;

36 37 38 39 40 41 42
  /**
   * Test view.
   *
   * @var \Drupal\views\ViewExecutable
   */
  protected $testView;

WalkingDexter's avatar
WalkingDexter committed
43 44 45 46 47 48 49
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $this->sitemapViews = $this->container->get('simple_sitemap.views');
WalkingDexter's avatar
WalkingDexter committed
50 51
    $this->cron = $this->container->get('cron');

52 53
    $this->testView = Views::getView('simple_sitemap_views_test_view');
    $this->testView->setDisplay('page_1');
WalkingDexter's avatar
WalkingDexter committed
54 55
  }

WalkingDexter's avatar
WalkingDexter committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  /**
   * Asserts the size of the arguments index.
   *
   * @param int $size
   *   The expected size.
   */
  protected function assertIndexSize($size) {
    $this->assertEquals($size, $this->sitemapViews->getArgumentsFromIndexCount());
  }

  /**
   * Adds a record to the arguments index.
   *
   * @param string $view_id
   *   The view ID.
   * @param string $display_id
   *   The view display ID.
   * @param array $args_ids
   *   A set of argument IDs.
   * @param array $args_values
   *   A set of argument values.
   */
  protected function addRecordToIndex($view_id, $display_id, array $args_ids, array $args_values) {
    $args_ids = implode(SimpleSitemapViews::ARGUMENT_SEPARATOR, $args_ids);
    $args_values = implode(SimpleSitemapViews::ARGUMENT_SEPARATOR, $args_values);

    // Insert a record into the index table.
    $query = $this->database->insert('simple_sitemap_views');
    $query->fields([
      'view_id' => $view_id,
      'display_id' => $display_id,
      'arguments_ids' => $args_ids,
      'arguments_values' => $args_values,
    ]);
    $query->execute();
  }

WalkingDexter's avatar
WalkingDexter committed
93
}