Skip to content

Commit

Permalink
Fix up unit tests for Totara 12.
Browse files Browse the repository at this point in the history
a
  • Loading branch information
danmarsden committed May 9, 2019
1 parent 9ea699b commit 898ae71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 61 deletions.
35 changes: 24 additions & 11 deletions tests/phpunit/setting_idpmetadata_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

class setting_idpmetadata_test extends advanced_testcase {
/** @var setting_idpmetadata */
private $config;
private static $config;

protected function setUp() {
parent::setUp();
$this->config = new setting_idpmetadata();
self::$config = new setting_idpmetadata();
}

private function get_test_metadata_url() {
Expand All @@ -47,7 +47,7 @@ private function get_test_metadata_url() {
public function test_it_validates_the_xml() {
$this->resetAfterTest();
$xml = file_get_contents(__DIR__ . '/../fixtures/metadata.xml');
$data = $this->config->validate($xml);
$data = self::$config->validate($xml);
self::assertTrue($data);
}

Expand All @@ -57,7 +57,7 @@ public function test_it_saves_all_idp_information() {
$this->resetAfterTest();

$xml = file_get_contents(__DIR__ . '/../fixtures/metadata.xml');
$this->config->write_setting($xml);
self::$config->write_setting($xml);
$actual = get_config('auth_saml2');

self::assertSame($xml, $actual->idpmetadata, 'Invalid config metadata.');
Expand Down Expand Up @@ -85,7 +85,7 @@ public function test_it_saves_all_idps_information_from_single_xml() {
$this->resetAfterTest();

$xml = file_get_contents(__DIR__ . '/../fixtures/dualmetadata.xml');
$this->config->write_setting($xml);
self::$config->write_setting($xml);
$actual = get_config('auth_saml2');

self::assertSame($xml, $actual->idpmetadata, 'Invalid config metadata.');
Expand All @@ -112,28 +112,28 @@ public function test_it_saves_all_idps_information_from_single_xml() {
}

public function test_it_allows_empty_values() {
self::assertTrue($this->config->validate(''), 'Validate empty string.');
self::assertTrue($this->config->validate(' '), ' Should trim spaces.');
self::assertTrue($this->config->validate("\n \n"), 'Should trim newlines.');
self::assertTrue(self::$config->validate(''), 'Validate empty string.');
self::assertTrue(self::$config->validate(' '), ' Should trim spaces.');
self::assertTrue(self::$config->validate("\n \n"), 'Should trim newlines.');
}

public function test_it_gets_idp_data_for_xml() {
$xml = file_get_contents(__DIR__ . '/../fixtures/metadata.xml');
$data = $this->config->get_idps_data($xml);
$data = self::$config->get_idps_data($xml);
self::assertCount(1, $data);
$this->validate_idp_data_array($data);
}

public function test_it_gets_idp_data_for_two_urls() {
$url = $this->get_test_metadata_url();
$url = "{$url}\n{$url}?second";
$data = $this->config->get_idps_data($url);
$data = self::$config->get_idps_data($url);
self::assertCount(2, $data);
$this->validate_idp_data_array($data);
}

public function test_it_returns_error_if_metadata_url_is_not_valid() {
$error = $this->config->validate('http://invalid.url.metadata.test');
$error = self::$config->validate('http://invalid.url.metadata.test');
self::assertContains('Invalid metadata', $error);
self::assertContains('http://invalid.url.metadata.test', $error);
}
Expand All @@ -147,4 +147,17 @@ private function validate_idp_data_array($idps) {
self::assertNotNull($idp->get_rawxml());
}
}

/**
* Cleanup after all tests are executed.
*
* @static
* @return void
*/
public static function tearDownAfterClass() { // @codingStandardsIgnoreLine - ignore case of function.
parent::tearDownAfterClass();
if (self::$config) {
self::$config = null;
}
}
}
50 changes: 0 additions & 50 deletions tests/phpunit/settings_test.php

This file was deleted.

0 comments on commit 898ae71

Please sign in to comment.