Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CLocalApiClientTest.php « clients « api « classes « include « unit « tests « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9403403eb4a9d173cee9e74fdc4c6d277584d0cc (plain)
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
<?php
/*
** Zabbix
** Copyright (C) 2001-2014 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


class CLocalApiClientTest extends PHPUnit_Framework_TestCase {

	/**
	 * @var CLocalApiClient
	 */
	protected $client;

	public function setUp() {
		$this->client = new CLocalApiClient();
	}

	/**
	 * Test API calls with correct parameters.
	 */
	public function testCall() {
		$this->markTestIncomplete();
	}

	public function incorrectCallProvider() {
		return array(
			// incorrect api
			array('api', 'method', array(), 'token',
				ZBX_API_ERROR_PARAMETERS, 'Incorrect API "api".'
			),
			// incorrect method
			array('user', 'incorrectMethod', array(), 'token',
				ZBX_API_ERROR_PARAMETERS, 'Incorrect method "user.incorrectMethod".'
			),
			// no auth token
			array('user', 'get', array(), null,
				ZBX_API_ERROR_NO_AUTH, 'Not authorised.'
			),
			// empty auth token
			array('user', 'get', array(), '',
				ZBX_API_ERROR_NO_AUTH, 'Not authorised.'
			),
			// unnecessary auth token
			array('apiinfo', 'version', array(), '',
				ZBX_API_ERROR_PARAMETERS, 'The "apiinfo.version" method must be called without the "auth" parameter.'
			),
		);
	}

	/**
	 * Test API calls with incorrect parameters.
	 *
	 * @dataProvider incorrectCallProvider()
	 */
	public function testCallIncorrect($api, $method, array $params, $auth, $expectedErrorCode, $expectedErrorMessage) {
		// setup a mock user API to authenticate the user
		$userMock = $this->getMock('CUser', array('checkAuthentication'));
		$userMock->expects($this->any())->method('checkAuthentication')->will($this->returnValue(array(
			'debug_mode' => false
		)));

		$this->client->setServiceFactory(new CRegistryFactory(array(
			'host' => 'CHost',
			'apiinfo' => 'CAPIInfo',
			'user' => function() use ($userMock) {
				return $userMock;
			}
		)));

		$response = $this->client->callMethod($api, $method, $params, $auth);
		$this->assertTrue($response instanceof CApiClientResponse);
		$this->assertEquals($expectedErrorCode, $response->errorCode);
		$this->assertEquals($expectedErrorMessage, $response->errorMessage);
		$this->assertNull($response->data);
		$this->assertNull($response->debug);
	}
}