Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Testing generator in payments API
  19   *
  20   * @package    core_payment
  21   * @category   test
  22   * @copyright  2020 Marina Glancy
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core_payment;
  27  
  28  /**
  29   * Testing generator in payments API
  30   *
  31   * @package    core_payment
  32   * @category   test
  33   * @copyright  2020 Marina Glancy
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class helper_testcase extends \advanced_testcase {
  37  
  38      public function test_create_account() {
  39          global $DB;
  40          $this->resetAfterTest();
  41          /** @var \core_payment_generator $generator */
  42          $generator = $this->getDataGenerator()->get_plugin_generator('core_payment');
  43          $this->assertTrue($generator instanceof \core_payment_generator);
  44  
  45          $account1 = $generator->create_payment_account();
  46          $account2 = $generator->create_payment_account(['name' => 'My name', 'gateways' => 'paypal']);
  47  
  48          $record1 = $DB->get_record('payment_accounts', ['id' => $account1->get('id')]);
  49          $record2 = $DB->get_record('payment_accounts', ['id' => $account2->get('id')]);
  50  
  51          $this->assertEquals(1, $record1->enabled);
  52          $this->assertEquals('My name', $record2->name);
  53  
  54          // First account does not have gateways configurations.
  55          $this->assertEmpty($DB->get_records('payment_gateways', ['accountid' => $account1->get('id')]));
  56          // Second account has.
  57          $this->assertCount(1, $DB->get_records('payment_gateways', ['accountid' => $account2->get('id')]));
  58      }
  59  
  60      public function test_create_payment() {
  61          global $DB;
  62          $this->resetAfterTest();
  63          /** @var \core_payment_generator $generator */
  64          $generator = $this->getDataGenerator()->get_plugin_generator('core_payment');
  65          $account = $generator->create_payment_account(['gateways' => 'paypal']);
  66          $user = $this->getDataGenerator()->create_user();
  67  
  68          $paymentid = $generator->create_payment(['accountid' => $account->get('id'), 'amount' => 10, 'userid' => $user->id]);
  69  
  70          $this->assertEquals('testcomponent', $DB->get_field('payments', 'component', ['id' => $paymentid]));
  71      }
  72  }