<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

/**
 * Generated by PHPUnit_SkeletonGenerator on 2017-04-24 at 14:25:20.
 */
class SessionOperationsTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var SessionOperations
   */
  protected $object;

  /**
   * Sets up the fixture, for example, opens a network connection.
   * This method is called before a test is executed.
   */
  protected function setUp(): void
  {
    $this->object = new SessionOperations();
  }

  /**
   * Tears down the fixture, for example, closes a network connection.
   * This method is called after a test is executed.
   */
  protected function tearDown(): void
  {
    $_COOKIE = $_ENV = $_FILES = $_GET = $_POST = $_REQUEST = $_SERVER = $_SESSION = array();
    SessionOperations::session_destroy_suchvariablen();
  }

  /**
   * @covers SessionOperations::setKursSearch
   * @test
   */
  public function setKursSearch_sonderrubrikInt_setInSession()
  {
    $_REQUEST['kfs_sonderrubrik'] = '6';
    SessionOperations::setKursSearch();
    $valInSession = SessionOperations::getVarValueSuche('kfs_sonderrubrik');
    $this->assertEquals('6', $valInSession);
  }

  /**
   * @covers SessionOperations::setKursSearch
   * @test
   */
  public function setKursSearch_sonderrubrikNoIntNoArray_setInSession()
  {
    if (!isset($_SESSION)) {
      $_SESSION = array();
    }
    $_REQUEST['kfs_sonderrubrik'] = 'lalala';
    SessionOperations::setKursSearch();
    $valInSession = SessionOperations::getVarValueSuche('kfs_sonderrubrik');
    $this->assertEquals('', $valInSession);
  }

  /**
   * @covers SessionOperations::setKursSearch
   * @test
   */
  public function setKursSearch_sonderrubrikArray_setInSession()
  {
    $value = array('3', '4');
    $_REQUEST['kfs_sonderrubrik'] = $value;
    SessionOperations::setKursSearch();
    $valInSession = SessionOperations::getVarValueSuche('kfs_sonderrubrik');
    $this->assertEquals($value, $valInSession);
  }

  /**
   * @covers SessionOperations::setKursSearch
   * @test
   */
  public function setKursSearch_sonderrubrikArrayNotOnlyInts_onlyIntsSetInSession()
  {
    $value = array('3', 'luja', '4');
    $_REQUEST['kfs_sonderrubrik'] = $value;
    SessionOperations::setKursSearch();
    $valInSession = SessionOperations::getVarValueSuche('kfs_sonderrubrik');
    $this->assertEquals(array('3', '4'), $valInSession);
  }

  /**
   * @covers SessionOperations::setKursSearch
   * @test
   */
  public function setKursSearch_sonderrubrikNotSetInRequest_notChangedInSession()
  {
    $oldValue = '6';
    SessionOperations::setVarValueSuche('kfs_sonderrubrik', $oldValue);
    SessionOperations::setKursSearch();
    $valInSession = SessionOperations::getVarValueSuche('kfs_sonderrubrik');
    $this->assertEquals($oldValue, $valInSession);
  }
}
