PhaseEndProcessTest.php 3.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
<?php
/**
 * Copyright (c) 2012-2014, 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
 */


class PhaseEndProcessTest extends Class_Cosmogramme_Integration_PhaseTestCase {
  protected $_http_client;

  protected function _getPreviousPhase() {
    return (new Class_Cosmogramme_Integration_Phase(21))->beCron();
  }


  public function setUp() {
    parent::setUp();

    $this->_http_client = $this->mock()
                               ->whenCalled('postData')
                               ->answers('');

    Class_Systeme_Report_Publication::setDefaultHttpClient($this->_http_client);
    $this->fixture('Class_Profil',  ['id' => 1, 'libelle' => 'My Bokeh']);
  }


  public function tearDown() {
    Class_Systeme_Report_Publication::resetHttpClient();
    parent::tearDown();
  }


  /** @test */
  public function reportShouldBePushedToPola() {
    $this->_phase = $this->_buildPhase('EndProcess')->run();
52
    $this->assertEquals('https://pola.afi-sa.net/smile.php',
53 54 55 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 93 94 95 96 97 98 99 100 101 102
                        $this->_http_client->getFirstAttributeForLastCallOn('postData'));
  }


  /** @test */
  public function logShouldContainsReportPublished() {
    $this->_phase = $this->_buildPhase('EndProcess')->run();
    $this->assertLogContains('Publication du rapport système');
  }


  /** @test */
  public function pushedRequestToPolaShouldIncludeReport() {
    $this->_phase = $this->_buildPhase('EndProcess')->run();
    $report = $this->_http_client->getAttributesForLastCallOn('postData')[1]['report'];
    $this->assertEquals('My Bokeh', json_decode($report, true)['portal']['label']);
  }


  /** @test */
  public function withNoPushUrlShouldNotPushReport() {
    Class_AdminVar::set('STATUS_REPORT_PUSH_URL', '0');
    $this->_phase = $this->_buildPhase('EndProcess')->run();
    $this->assertFalse($this->_http_client->methodHasBeenCalled('postData'));
  }


  /** @test */
  public function withInvalidPushUrlShouldNotPushReport() {
    Class_AdminVar::set('STATUS_REPORT_PUSH_URL', 'no');
    $this->_phase = $this->_buildPhase('EndProcess')->run();
    $this->assertFalse($this->_http_client->methodHasBeenCalled('postData'));
  }


  /** @test */
  public function withInvalidPushUrlLogShouldNotContainsReportPublished() {
    Class_AdminVar::set('STATUS_REPORT_PUSH_URL', 'no');
    $this->_phase = $this->_buildPhase('EndProcess')->run();
    $this->assertNotLogContains('Publication du rapport système');
  }


  /** @test */
  public function withExceptionShouldNotPushReport() {
    $this->_http_client
      ->whenCalled('postData')
      ->willDo(function() { throw new RunTimeException('no more paper'); });

    $this->_phase = $this->_buildPhase('EndProcess')->run();
103
    $this->assertLogContains('Echec de la publication du rapport sur https://pola.afi-sa.net/smile.php (no more paper)');
104 105 106
  }
}
?>