Skip to content
Snippets Groups Projects
PayfipTemplatesAbonneTest.php 52.8 KiB
Newer Older
efalcy's avatar
efalcy committed
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 52 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
<?php
/**
 * Copyright (c) 2012-2022, 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_once __DIR__ . '/PayfipFixtures.php';
require_once __DIR__ . '/PayfipMockNanookClient.php';

abstract class PayfipTemplatesAbonneTestCase extends AbstractControllerTestCase {

  use Trait_PayfipFixtures;


  protected MockMailTransport $_mail_transport;


  public function setUp() {
    parent::setUp();
    $this->_mail_transport = new MockMailTransport();
    Zend_Mail::setDefaultTransport($this->_mail_transport);

    Class_AdminVar::set(Class_AdminVar_Payfip::HIDDEN, 0);
    Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 11:21:38'));
    $this->cbOnProduction('2022-02-02 11:21:38');
    $this->transferOnProduction('2022-02-02 11:21:38');

    $gildor = $this->fixture(Class_Users::class,
                             ['id' => 42,
                              'nom' => 'Achim Noan Nini',
                              'prenom' => 'Gil Dor',
                              'login' => 'test',
                              'password' => 's2cr3t',
                              'bib' => $this->getBibAnnecy(),
                              'int_bib' => $this->getIntBibForAnnecy(),
                              'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
                              'id_sigb' => 1234,
                              'idabon' => 1234
                             ]);
    ZendAfi_Auth::getInstance()->logUser($gildor);
  }


  public function enableAndSetTemplate(){
    $this->enablePayfip();
    $this->_buildTemplateProfil(['id'=>172]);
  }
}




class PayfipTemplatesAbonneDebtsTabTest extends PayfipTemplatesAbonneTestCase {

  public function setUp() {
    parent::setUp();
    $this->enableAndSetTemplate();
  }


  /** @test */
  public function whenPayfipEnabledpageDebtsShouldBeDisplayed() {
    $this->dispatch('/abonne/debts');
    $this->assertXPathContentContains('//title', 'Mon compte / Mes prestations');
    $this->assertXPathContentContains('//h2', 'Mes prestations');
  }


  /** @test */
  public function whenPayfipEnabledAccountPageShouldDisplayTabMesPrestationsDues() {
    $this->dispatch('/abonne/fiche');
    $this->assertXPathContentContains('//li[contains(@class,"nav-item")]//a[contains(@href,"/abonne/debts")]', 'Mes prestations');
  }
}




class PayfipTestModeTemplatesAbonneDebtsTabTest extends PayfipTemplatesAbonneTestCase {
  public function setUp() {
    parent::setUp();
    $this->enableAndSetTemplate();
    $this->onTest();
  }


  /** @test */
  public function payfipTestModeDebtsTabShouldNotBeShown() {
    $this->dispatch('/abonne');
    $this->assertNotXPathContentContains('//li/a/div', 'Mes prestations');
  }
}




class PayfipDisabledTemplatesAbonneDebtsTabTest extends PayfipTemplatesAbonneTestCase {
  public function setUp() {
    parent::setUp();
    $this->enableAndSetTemplate();
    Class_AdminVar::set(Class_AdminVar_Payfip::HIDDEN, 1);
  }


  /** @test */
  public function payfipDisabledDebtsTabShouldNotBeShown() {
    $this->dispatch('/abonne');
    $this->assertNotXPathContentContains('//li/a/div', 'Mes prestations');
  }
}




class PayfipDisabledTemplatesAbonneTestDebtsTabTest extends PayfipTemplatesAbonneTestCase {
  public function setUp() {
    parent::setUp();
    $this->enableAndSetTemplate();
    Class_AdminVar::set(Class_AdminVar_Payfip::HIDDEN, 1);
    Class_AdminVar::set(Class_AdminVar_Payfip::TEST_USERS, 'test');
  }


  /** @test */
  public function debtsTabShouldBeShown() {
    $this->dispatch('/abonne');
    $this->assertXPathContentContains('//li/a/div', 'Mes prestations');
  }
}




class PayfipTemplatesAbonnePayfipDisabledTest extends PayfipTemplatesAbonneTestCase {

  public function setUp() {
    parent::setUp();
    $this->_buildTemplateProfil(['id'=> 172]);
    $this->disablePayfip();
    $this->dispatch('/abonne/fiche');
  }


  /** @test */
  public function accountPageShouldNotDisplayTabMesPrestationsDues() {
    $this->assertNotXPath('//li[contains(@class,"nav-item")]//a[contains(@href,"/abonne/debts")]');
  }
}




class PayfipTemplatesAbonneChiliDebtsTabTest extends PayfipTemplatesAbonneTestCase{
  public function setUp() {
    parent::setUp();
    $this->_buildTemplateProfil(['id'=> 172,
                                 'template' => 'CHILI']);
    $this->enablePayfip();
  }


  /** @test */
  public function whenPayfipEnabledpageDebtsShouldBeDisplayed() {
    $this->dispatch('/abonne/debts');
    $this->assertXPathContentContains('//title', 'Mon compte / Mes prestations');
    $this->assertXPathContentContains('//h2', 'Mes prestations');
  }


  /** @test */
  public function whenPayfipEnabledAccountPageShouldDisplayTabMesPrestationsDues() {
    $this->dispatch('/abonne/fiche');
    $this->assertXPathContentContains('//div[contains(@class,"card_title_Chili_Library_Wrapper_RichContentSection")]//a[contains(@href,"/abonne/debts")]',
                                      'Mes prestations');
  }
}




class PayfipTemplatesAbonneDisableDebtsTabTest extends PayfipTemplatesAbonneTestCase{
  public function setUp() {
    parent::setUp();
    $this->enablePayfip();
    $profil = $this->_buildTemplateProfil(['id'=>172]);
    (new Class_Profil_Preferences)
      ->setModulePref($profil,
                      (new Class_Profil_ModuleDefinition('abonne', 'fiche')),
                      [Intonation_Library_View_Wrapper_User_RichContent_Debts::class => 0]);
    $this->dispatch('/abonne/fiche');
  }


  /** @test */
  public function pageAbonneFicheShouldNotContainsTabDebts() {
    $this->assertNotXPathContentContains('//li[contains(@class,"nav-item")]',
                                         'Mes prestations');
  }
}




class PayfipTemplatesAbonneRefreshPayfipandIlsUpdatedTest extends PayfipTemplatesAbonneTestCase{
  public function setUp() {
    parent::setUp();

    $this->enablePayfip();
    $this->_openUrl();
    Class_Users::getIdentity()->setFicheSigb(['type_comm' => Class_IntBib::COM_NANOOK,
                                              'fiche' => ((new Class_WebService_SIGB_Emprunteur(4,
                                                                                                'Sans dettes')))]);
    $this->_buildTemplateProfil(['id' => 111])->beCurrentProfil();
    $cfg_accueil = ['modules' => [['division' => 4,
                                   'type_module' => 'LOGIN',
                                   'preferences' => []]]];

    Class_Profil::getCurrentProfil()
      ->setCfgAccueil($cfg_accueil)
      ->assertSave();

    $this->fixture(Class_Payfip::class,
                   ['id' => 260,
                    'user' =>  Class_Users::getIdentity(),
                    'reference' => '1234789',
                    'paid_on' => '0000-00-00 00:00:00',
                    'transmited_at' => '2023-02-28 10:00:00',
                    'id_op' => 'tutor',
                    'amount' => 1200,
                    'result' => Class_Payfip::RESULT_UNKNOWN,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 140,
                                                'sigb_id' => '4573',
                                                'label' => 'Bouquet numérique',
                                                'amount' => 400]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 141,
                                                'sigb_id' => '4574',
                                                'label' => 'Casse de boitier',
                                                'amount' => 800])
                    ]]);


    $response = file_get_contents(__DIR__.'/recupererDetailPaiementSecuriseCanceled.xml');
    $this->_soap_client->onActionAnswers('recupererDetailPaiementSecurise', $response);

    $this->dispatch('/index/index');
  }


  protected function _openUrl() : void {
    $web_client = new class() {
      public function open_url($url) : string {
        $map = [ '/GetPatronInfo/patronId/1234' => 'patronInfoWithDebts.xml',
                 '/EnPayment/patronId/1234' => 'endPaymentResponseSuccess.xml'];

        foreach($map as $url_part => $response_file)
          if (false !== strpos($url, $url_part))
            return file_get_contents(__DIR__ . '/' . $response_file);

        throw new RuntimeException('Unkown url ' . $url);
      }
      public function journalize( $bool) {
        return true;
      }
      public function postRawData() {
        return true;
      }

    };

    $this->setupMockNanook($web_client);
  }


  /** @test */
  public function debtsShouldBeDisplayedOnLoginWidget() {
    $this->assertXPath('//a[@href="/abonne/debts"][@class="card-link account-booking"]/div[@class="d-inline button_text text-left"][text()="3 prestations à régler"]');
  }
}




abstract class PayfipTemplatesAbonneDebtsDisplayTestCase extends PayfipTemplatesAbonneTestCase {
  protected $_nanook_client;

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

    $this->enablePayfip();
    $this->_buildTemplateProfil(['id' => 172]);

    $user = $this->createUserForSite(336, 'hubert', $this->getBibAnnecy());
    $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient);
    $this->_nanook_client
      ->onOpenUrl('/GetPatronInfo/patronId/336')->answerFile('patronInfoWithDebts.xml')
      ->onOpenUrl('/AuthenticatePatron/')->answerFile('authenticatePatronSuccess.xml');

    $this->fixture(Class_Payfip::class,
                   ['id' => 255,
                    'user' => $user,
                    'reference' => '1234781',
                    'paid_on' => '2023-02-02 10:00:00',
                    'id_op' => 'toto',
                    'amount' => 1200,
                    'result' => Class_Payfip::RESULT_PAYED_BY_CB,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 123,
                                                'sigb_id' => '4567',
                                                'label' => 'Impression',
                                                'amount' => 1000]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 124,
                                                'sigb_id' => '4568',
                                                'label' => 'Livre Abimé',
                                                'amount' => 200])
                    ]]);

    $this->fixture(Class_Payfip::class,
                   ['id' => 256,
                    'user' => $user,
                    'reference' => '1234785',
                    'paid_on' => '2023-02-03 12:00:00',
                    'id_op' => 'Johnny',
                    'amount' => 5400,
                    'result' => Class_Payfip::RESULT_UNKNOWN,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 125,
                                                'sigb_id' => '4569',
                                                'label' => 'perte carte',
                                                'amount' => 5400]),
                    ]]);

    $this->fixture(Class_Payfip::class,
                   ['id' => 257,
                    'user' => $user,
                    'reference' => '1234788',
                    'paid_on' => '2023-04-12 10:00:00',
                    'id_op' => 'tata',
                    'amount' => 6700,
                    'result' => Class_Payfip::RESULT_UNKNOWN,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 126,
                                                'sigb_id' => '4570',
                                                'label' => 'Inscription Groupe',
                                                'amount' => 4700]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 127,
                                                'sigb_id' => '4571',
                                                'label' => 'changement d\'adresse',
                                                'amount' => 2000])
                    ]]);

    $this->fixture(Class_Payfip::class,
                   ['id' => 260,
                    'user' => $user,
                    'reference' => '1234789',
                    'paid_on' => '0000-00-00 00:00:00',
                    'transmited_at' => '2023-02-28 10:00:00',
                    'id_op' => 'tutor',
                    'amount' => 1200,
                    'result' => Class_Payfip::RESULT_UNKNOWN,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 140,
                                                'sigb_id' => '4573',
                                                'label' => 'Bouquet numérique',
                                                'amount' => 400]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 141,
                                                'sigb_id' => '4574',
                                                'label' => 'Casse de boitier',
                                                'amount' => 800])
                    ]]);

    $this->fixture(Class_Payfip::class,
                   ['id' => 258,
                    'user' => $user,
                    'reference' => '1234790',
                    'paid_on' => '2023-06-02 10:00:00',
                    'id_op' => 'Gandalf',
                    'amount' => 68000,
                    'result' => Class_Payfip::RESULT_PAYED_BY_TRANSFER,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 128,
                                                'sigb_id' => '4572',
                                                'label' => 'Remplacement Carte ordinateur',
                                                'amount' => 68000]),
                    ]]);

    $this->_addHistoricDebts($user);

    ZendAfi_Auth::getInstance()->logUser($user);

    $this->_dispatch();
  }


  protected function _dispatch() : void {
    $this->dispatch('/abonne/debts');
  }


  protected function _addHistoricDebts(Class_Users $user) : void {}
}




class PayfipTemplatesAbonneDebtsHistoriqueTest extends PayfipTemplatesAbonneDebtsDisplayTestCase {

  const TABLE_PATH = '//table[contains(@class, "table")][@id="Class_Debt-historic"]/tbody/';

  protected function _addHistoricDebts(Class_Users $user) : void {
    $this->fixture(Class_Payfip::class,
                   ['id' => 259,
                    'user' => $user,
                    'reference' => '1234791',
                    'paid_on' => '2022-02-02 10:00:00',
                    'id_op' => 'toto',
                    'amount' => 500,
                    'result' => Class_Payfip::RESULT_PAYED_BY_CB,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 129,
                                                'sigb_id' => '4573',
                                                'label' => 'Reliure',
                                                'amount' => 100]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 130,
                                                'sigb_id' => '4574',
                                                'label' => 'Dégâts',
                                                'amount' => 200]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 131,
                                                'sigb_id' => '4575',
                                                'label' => 'Sortie',
                                                'amount' => 200])
                    ]]);
  }


  /** @test */
  public function contentShouldContainsTitle_H3_Historique_des_prestations() {
    $this->assertXPath('//div/h3[text()="Historique"]');
  }


  /** @test */
  public function contentTableShouldContains_5_Lines() {
    $this->assertXPathCount(static::TABLE_PATH . 'tr', 5);
  }


  /** @test */
  public function contentShouldContainsButtonVoirToutesMesPrestations() {
    $this->assertXPath('//div[@class="table-responsive"]/div[@class="col-12 text-center"]/a[@href="/abonne/debts/historic-limit/all"][contains(@class, "card-link")]/div[text()="Voir toutes mes prestations"]');
  }


  /** @test */
  public function contentTableFirstRowFirstColumnShouldContains_Impression() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[1]/td[1]', 'Remplacement Carte ordinateur');
  }


  /** @test */
  public function contentTableFirstRowSecondColumnShouldContains_BadgeDate_02_06_2023_10_00_00() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[1]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")]', '02/06/2023 10:00:00');
  }


  /** @test */
  public function contentTableFirstRowSecondColumnShouldContains_BadgeAmount_680() {
    $this->assertXPath(static::TABLE_PATH . 'tr[1]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="680€00"]');
  }


  /** @test */
  public function contentTableFirstRowThirdColumnShouldContains_Reglee_Transaction_n_1234781() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[1]/td[3]',
                                      'Réglée par Virement - Transaction n°1234790');
  }


  /** @test */
  public function contentTableSecondRowFirstColumnShouldContains_Livre_Abime() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[2]/td[1]', 'Impression');
  }


  /** @test */
  public function contentTableSecondRowSecondColumnShouldContains_BadgeDate_02_02_2023_10_00_00() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[2]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")]', '02/02/2023 10:00:00');
  }


  /** @test */
  public function contentTableSecondRowSecondColumnShouldContains_BadgeAmount_2() {
    $this->assertXPath(static::TABLE_PATH . 'tr[2]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="10€00"]');
  }


  /** @test */
  public function contentTableSecondRowThirdColumnShouldContains_Reglee_Transaction_n_1234781() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[2]/td[3]',
                                      'Réglée par CB - Transaction n°1234781');
  }


  /** @test */
  public function contentTableThirdRowFirstColumnShouldContains_Remplacement_Carte_Ordinateur() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[3]/td[1]',
                                      'Livre Abimé');
  }


  /** @test */
  public function contentTableThirdRowSecondColumnShouldContains_BadgeDate_02_06_2023_10_00_00() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[3]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")]', '02/02/2023 10:00:00');
  }


  /** @test */
  public function contentTableThirdRowSecondColumnShouldContains_BadgeAmount_680() {
    $this->assertXPath(static::TABLE_PATH . 'tr[3]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="2€00"]');
  }


  /** @test */
  public function contentTableThirdRowThirdColumnShouldContains_Reglee_Transaction_n_1234790() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[3]/td[3]',
                                      'Réglée par CB - Transaction n°1234781');
  }


  /** @test */
  public function contentTableForthRowFirstColumnShouldContains_Reluire() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[4]/td[1]', 'Reliure');
  }


  /** @test */
  public function contentTableForthRowSecondColumnShouldContains_BadgeDate_02_02_2022_10_00_00() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[4]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")]', '02/02/2022 10:00:00');
  }


  /** @test */
  public function contentTableForthRowSecondColumnShouldContains_BadgeAmount_1() {
    $this->assertXPath(static::TABLE_PATH . 'tr[4]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="1€00"]');
  }


  /** @test */
  public function contentTableForthRowThirdColumnShouldContains_Reglee_Transaction_n_1234791() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[4]/td[3]',
                                      'Réglée par CB - Transaction n°1234791');
  }


  /** @test */
  public function contentTableFifthRowFirstColumnShouldContains_Degats() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[5]/td[1]', 'Dégâts');
  }


  /** @test */
  public function contentTableFifthRowSecondColumnShouldContains_BadgeDate_02_02_2022_10_00_00() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[5]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")]', '02/02/2022 10:00:00');
  }


  /** @test */
  public function contentTableFifthRowSecondColumnShouldContains_BadgeAmount_2() {
    $this->assertXPath(static::TABLE_PATH . 'tr[5]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="2€00"]');
  }


  /** @test */
  public function contentTableFifthRowThirdColumnShouldContains_Reglee_Transaction_n_1234791() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[5]/td[3]',
                                      'Réglée par CB - Transaction n°1234791');
  }
}




class PayfipTemplatesAbonneDebtsHistoriqueWithoutLimitTest
  extends PayfipTemplatesAbonneDebtsDisplayTestCase {

  const TABLE_PATH = '//table[contains(@class, "table")][@id="Class_Debt-historic"]/tbody/';

  protected function _dispatch() : void {
    $this->dispatch('/abonne/debts/historic-limit/all');
  }


  protected function _addHistoricDebts(Class_Users $user) : void {
    $this->fixture(Class_Payfip::class,
                   ['id' => 259,
                    'user' => $user,
                    'reference' => '1234791',
                    'paid_on' => '2022-02-02 10:00:00',
                    'id_op' => 'toto',
                    'amount' => 500,
                    'result' => Class_Payfip::RESULT_PAYED_BY_CB,
                    'debts' => [$this->fixture(Class_Debt::class,
                                               ['id' => 129,
                                                'sigb_id' => '4573',
                                                'label' => 'Reliure',
                                                'amount' => 100]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 130,
                                                'sigb_id' => '4574',
                                                'label' => 'Dégâts',
                                                'amount' => 200]),
                                $this->fixture(Class_Debt::class,
                                               ['id' => 131,
                                                'sigb_id' => '4575',
                                                'label' => 'Sortie',
                                                'amount' => 200])
                    ]]);
  }


  /** @test */
  public function contentTableShouldContains_6_Lines() {
    $this->assertXPathCount(static::TABLE_PATH . 'tr', 6);
  }


  /** @test */
  public function contentTableSixthRowFirstColumnShouldContains_Sortie() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[6]/td[1]', 'Sortie');
  }


  /** @test */
  public function contentTableSixthRowSecondColumnShouldContains_BadgeDate_02_02_2022_10_00_00() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[6]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")]', '02/02/2022 10:00:00');
  }


  /** @test */
  public function contentTableSixthRowSecondColumnShouldContains_BadgeAmount_2() {
    $this->assertXPath(static::TABLE_PATH . 'tr[6]/td[2]/div[contains(@class, "badge-group")]/span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="2€00"]');
  }


  /** @test */
  public function contentTableSixthRowThirdColumnShouldContains_Reglee_Transaction_n_1234791() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[6]/td[3]',
                                      'Réglée par CB - Transaction n°1234791');
  }
}




class PayfipTemplatesAbonneDebtsHistoriqueWith3DebtsTest
  extends PayfipTemplatesAbonneDebtsDisplayTestCase {

  /** @test */
  public function contentTableShouldContains_3_Lines() {
    $this->assertXPathCount('//table[contains(@class, "table")][@id="Class_Debt-historic"]/tbody/tr', 3);
  }


  /** @test */
  public function contentShouldNotContainsButtonVoirToutesMesPrestations() {
    $this->assertNotXPath('//a[@href="/abonne/debts/historic-limit/all"]');
  }
}




class PayfipTemplatesAbonneDebtsEnCoursTest extends PayfipTemplatesAbonneDebtsDisplayTestCase {

  const TABLE_PATH = '//table[contains(@class, "table")][@id="Class_Debt-current"]/tbody/';

  /** @test */
  public function pageShouldContainsMesPrestationsEnCoursDeTraitement() {
    $this->assertXPathContentContains('//h3',
                                      'En cours de traitement');
  }


  /** @test */
  public function tableCurrentShouldContainsFourRows() {
    $this->assertXPathCount(static::TABLE_PATH . 'tr', 5);
  }


  /** @test */
  public function tableCurrentfirstRowFirstCellShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[1]/td[1]', 'perte carte');
  }


  /** @test */
  public function tableCurrentSecondRowFirstCellShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[2]/td[1]', 'Inscription Groupe');
  }


  /** @test */
  public function tableCurrentThirdRowFirstCellShouldContainsThreeRows() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[3]/td[1]', 'changement d\'adresse');
  }


  /** @test */
  public function tableCurrentfirstRowSecondCellFirstBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH .  'tr[1]/td[2]//span[contains(@class,"badge_text")]',
                                      '03/02/2023 12:00:00');
  }


  /** @test */
  public function tableCurrentFirstRowSecondCellSecondBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[1]/td[2]//span[contains(@class,"badge_text")]',
                                      '54€00');
  }


  /** @test */
  public function tableCurrentSecondRowSecondCellFirstBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[2]/td[2]//span[contains(@class,"badge_text")]',
                                      '12/04/2023 10:00:00');
  }


  /** @test */
  public function tableCurrentSecondRowSecondCellSecondBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[2]/td[2]//span[contains(@class,"badge_text")]',
                                      '47€00');
  }


  /** @test */
  public function tableCurrentThirdRowSecondCellFirstBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[3]/td[2]//span[contains(@class,"badge_text")]',
                                      '12/04/2023 10:00:00');
  }


  /** @test */
  public function tableCurrentThirdRowSecondCellSecondBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[3]/td[2]//span[contains(@class,"badge_text")]',
                                      '20€00');
  }


  /** @test */
  public function tableCurrentFirstRowThirdCellShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[1]/td[3]',
                                      'En cours - Transaction n°1234785');
  }


  /** @test */
  public function tableCurrentFourthRowSecondCellSecondBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[4]/td[1]',
                                      'Bouquet numérique');
  }


  /** @test */
  public function tableCurrentFourthRowSecondCellBadgeDateShouldContainsTransmittedAtFormattedDate() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[4]/td[2]//span[contains(@class,"badge_text")]',
                                      (new DateTime((Class_Debt::find(140))->getPayfip()->getTransmitedAt()))->format('d/m/Y H:i:s'));
  }


  /** @test */
  public function tableCurrentFourthRowSecondCellBadgePriceShouldContainsFourEuros() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[4]/td[2]//span[contains(@class,"badge_text")]',
                                      '4€00');
  }


  /** @test */
  public function tableCurrentSecondRowThirdCellBadgePriceShouldContainsEnCours() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[4]/td[3]',
                                      'En cours - Transaction n°1234789');
  }


  /** @test */
  public function tableCurrentFifthRowSecondCellSecondBadgeShouldContains() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[5]/td[1]',
                                      'Casse de boitier');
  }


  /** @test */
  public function tableCurrentFifthRowSecondCellBadgeDateShouldContainsTransmittedAtFormattedDate() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[5]/td[2]//span[contains(@class,"badge_text")]',
                                      (new DateTime((Class_Debt::find(140))->getPayfip()->getTransmitedAt()))->format('d/m/Y H:i:s'));
  }


  /** @test */
  public function tableCurrentFifthRowSecondCellBadgePriceShouldContainsFourEuros() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[5]/td[2]//span[contains(@class,"badge_text")]',
                                      '8€00');
  }


  /** @test */
  public function tableCurrentFifthRowThirdCellBadgePriceShouldContainsEnCours() {
    $this->assertXPathContentContains(static::TABLE_PATH . 'tr[5]/td[3]',
                                      'En cours - Transaction n°1234789');
  }
}




class PayfipTemplatesAbonneDebtsAPayerTest extends PayfipTemplatesAbonneDebtsDisplayTestCase {


  /** @test */
  public function pageShouldContainsSubscripberIntroMessageRegler() {
    $this->assertXPathContentContains('//div[@class="payfip_subscriber_intro_message col-12"]/p',
                                      'Cet écran vous liste les prestations ');
  }


  /** @test */
  public function pageShouldContainsH3ARegler() {
    $this->assertXPathContentContains('//div[@class="payfip_borrower_widget payfip_debts_to_pay col-12 mt-3"]/h3', 'À régler');
  }


  /** @test */
  public function pageShouldContainsH3EnCoursDeTraitement() {
    $this->assertXPathContentContains('//div[@class="payfip_borrower_widget payfip_debts_running col-12 mt-3"]/h3', 'En cours de traitement');
  }


  /** @test */
  public function pageShouldContainsH3Historique() {
    $this->assertXPathContentContains('//div[@class="payfip_borrower_widget payfip_debts_historic col-12 mt-3"]/h3', 'Historique');
  }


  /** @test */
  public function formShouldContainsThreeInputsDebtsIdsTypeCheckbox() {
    $this->assertXPathCount('//form//input[@type="checkbox"][contains(@id, "debt_id")]', 3);
  }


  /** @test */
  public function formFirstDebtShouldBeAbonnement() {
    $this->assertXPathContentContains('//form/div[1][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[1]', 'Abonnement');
  }


    /** @test */
  public function formFirstDebtAmountShouldBe10E() {
    $this->assertXPathContentContains('//form/div[1][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[2]', '10€12');
  }


  /** @test */
  public function formFirstDebtCheckboxShouldHaveDebtIdSixtyThreeSixtyThree() {
    $this->assertXPath('//form/div[1][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[3]/input[@id="debt_id_6363"]');
  }


    /** @test */
  public function formSecondDebtShouldBeBoiterCasse() {
    $this->assertXPathContentContains('//form/div[2][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[1]', 'Boitier cassé');
  }


    /** @test */
  public function formSecondDebtAmountShouldBe1E5() {
    $this->assertXPathContentContains('//form/div[2][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[2]', '1€50');
  }


  /** @test */
  public function formSecondDebtCheckboxShouldHaveDebtIdSixtyThreeSixtyFive() {
    $this->assertXPath('//form/div[2][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[3]/input[@id="debt_id_6365"]');
  }


    /** @test */
  public function formThirdDebtShouldBePhotocopies() {
    $this->assertXPathContentContains('//form/div[3][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[1]', 'Photocopies (10) (Quantité 6)');
  }


    /** @test */
  public function formThirdDebtAmountShouldBe6ETwentyTwoCents() {
    $this->assertXPathContentContains('//form/div[3][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[2]', '6€22');
  }


  /** @test */
  public function formThirdDebtCheckboxShouldHaveDebtIdSixtyThreeSixtyFour() {
    $this->assertXPath('//form/div[3][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[3]/input[@id="debt_id_6364"]');
  }


  /** @test */
  public function inputTextPayDebtsEmailShouldContainsUserMail() {
    $this->assertXPath('//input[@type="email"][@value="user@server.io"][@name="pay_debts_email"][@required]');
  }


  /** @test */
  public function labelForEmailShouldBeVerifierEmailPourRecu() {
    $this->assertXPathContentContains('//label[@for="pay_debts_email"]',
                                      'Email pour le reçu');
  }


  /** @test */
  public function formSubmitShouldContainsOnclickUrlForPayfip() {
    $this->assertXPath('//form[@action="/abonne/debts"][@method="post"]//input[@type="submit"][@value="Payer mes prestations"]');
  }


  /** @test */
  public function pageShouldBeHTML5Valid() {
    $this->assertHTML5();
  }


  /** @test */
  public function pageShouldBeAccessible() {
    $this->assertAccessible();
  }
}




class PayfipTemplatesAbonneDebtsAPayerEmptyTest
  extends PayfipTemplatesAbonneDebtsDisplayTestCase {

  protected function _dispatch() : void {
    $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient);

    $this->_nanook_client
      ->onOpenUrl('/GetPatronInfo/patronId/336')->answerFile('patronInfoWithoutDebts.xml')
      ->onOpenUrl('/AuthenticatePatron/')->answerFile('authenticatePatronSuccess.xml');

    $this->dispatch('/abonne/debts');
  }


  /** @test */
  public function contentShouldNotContainsButtonPayerMesPrestations() {
    $this->assertNotXPath('//a[contains(@href, "/abonne/pay")]');
  }
}




class PayfipTemplatesAbonneDebtsPayDispatchErrorTest
  extends PayfipTemplatesAbonneDebtsDisplayTestCase {


  /** @test */
  public function shouldNotifyRienAPayer() {
    $this->postDispatch('/abonne/debts', []);
    $this->assertFlashMessengerContentContains('Rien à payer');
  }


  /** @test */
  public function shouldNotifyErrorForPaiement() {
    $this->postDispatch('/abonne/debts',
                        ['debt_id_1' => 1]);
    $this->assertFlashMessengerContentContains('Le paiement demandé ne peut pas être effectué');
  }