Skip to content
Snippets Groups Projects
LogsControllerTest.php 5.13 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
 *
 * BOKEH is free software; you can redistribute it and/or modify
 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
 * the Free Software Foundation.
 *
 * There are special exceptions to the terms and conditions of the AGPL as it
 * is applied to this software (see README file).
 *
 * BOKEH is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
 * along with BOKEH; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */

require 'application/modules/cosmo/controllers/LogsController.php';

abstract class LogsControllerTestCase extends CosmoControllerTestCase {
  public function setUp() {
    parent::setUp();
    Class_CosmoVar::setValueOf('log_path','/log');

    $filesystem = (new Storm_FileSystem_Volatile())
      ->mkdir('/log')
      ->filePutContents('/log/debug_2017-05-12.log',
                        str_repeat('bugs bugs', 200))
      ->filePutContents('/log/integration_2017-05-12.log',
                        "[IntegrationTest] first line\n [IntegrationTest] second line")

      ->filePutContents('/log/integration_2017-05-13.log',
                        str_repeat('logs logs', 200000))
      ->filePutContents('/log/debug_2017-05-13.log',
                        "[LogTest]")

      ->filePutContents('/log/a_file.log', "that should not be there");

    ZendAfi_View_Helper_CosmoLogs::setFileSystem($filesystem);
    Cosmo_LogsController::setFileSystem($filesystem);

    $this->fixture('Class_Cosmogramme_Integration',
                   ['id' => 1,
                    'pointeur_reprise' => 1,
                    'traite' => '2017-05-12',
                    'nb_erreurs' => 0,
                    'nb_warnings' => 7,
                   ]);

    $this->fixture('Class_Cosmogramme_Integration',
                   ['id' => 2,
                    'pointeur_reprise' => 234,
                    'traite' => '2017-05-12',
                    'nb_erreurs' => 2,
                    'nb_warnings' => 1,
                   ]);
  }


  public function tearDown() {
    ZendAfi_View_Helper_CosmoLogs::setFileSystem(null);
    Cosmo_LogsController::setFileSystem(null);
    parent::tearDown();
  }
}


class LogsControllerIndexTest extends LogsControllerTestCase {
  public function setUp() {
    parent::setUp();
    $this->dispatch('/cosmo/logs', true);
  }


  /** @test */
  public function firstTRShouldContainsSaturdayThirteenMay2017() {
    $this->assertXPathContentContains('//table[@id="logs"]//tr[1]//td',
                                      'samedi 13 mai 2017');
  }


  /** @test */
  public function firstTRShouldContainsMagnifierIcon() {
    $this->assertXPath('//table[@id="logs"]//tr[1]//td//img[contains(@src, "loupe")]');
  }


  /** @test */
  public function firstTRReportLinkToOpenIntegrationLogShouldContaints2Mo() {
    $this->assertXPathContentContains('//tr[1]//td//a[contains(@href, "/cosmo/logs/integration/day/2017-05-13")]',
                                      '2 Mo');
  }


  /** @test */
  public function firstTRRecordProcessedShouldContainsZero() {
    $this->assertXPath('//tr[1]/td[4][text()="0"]');
  }


  /** @test */
  public function secondTRShouldContainsFridayTwelveMay2017() {
    $this->assertXPathContentContains('//table[@id="logs"]//tr[2]//td',
                                      'vendredi 12 mai 2017');
  }


  /** @test */
  public function secondTRReportShouldContaints59o() {
    $this->assertXPathContentContains('//tr[2]//td', '59 o');
  }


  /** @test */
  public function secondTRShouldContainsLinkToRunLogByDate() {
    $this->assertXPath('//table[@id="logs"]//tr[2]//td//a[contains(@href, "cosmo/run-log/by-date/date/2017-05-12")]');
  }


  /** @test */
  public function secondTRReportLinkToOpenDebugLogShouldContaints2Ko() {
    $this->assertXPathContentContains('//tr[2]//td//a[contains(@href, "/cosmo/logs/debug/day/2017-05-12")]',
                                      '2 Ko');
  }


  /** @test */
  public function secondTRRecordProcessedShouldContains235() {
    $this->assertXPath('//tr[2]/td[4][text()="235"]');
  }


  /** @test */
  public function secondTRErrorsShouldContains2() {
    $this->assertXPath('//tr[2]/td[5][text()="2"]');
  }


  /** @test */
  public function secondTRWarningsShouldContains8() {
    $this->assertXPath('//tr[2]/td[6][text()="8"]');
  }
class LogsControllerDisplayIntegrationTest extends LogsControllerTestCase {
  /** @test */
  public function withValidIntegrationLogShouldDisplayFileContent() {
    $this->dispatch('/cosmo/logs/integration/day/2017-05-12', true);
    $this->assertXPathContentContains('//div', '[IntegrationTest] first line');
  }


  /** @test */
  public function withValidDebugLogShouldDisplayFileContent() {
    $this->dispatch('/cosmo/logs/debug/day/2017-05-13', true);
    $this->assertXPathContentContains('//div', '[LogTest]');
  }