<?php
/*
* tad-php
*
* (The MIT License)
*
* Copyright (c) 2015 Jorge Cobis <jcobis@gmail.com / http://twitter.com/cobisja>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace Test;
use TADPHP\TADResponse;
class TADResponseTest extends \PHPUnit_Framework_TestCase
{
public function testTADResponseIsInstantiatedCorrectly()
{
$header = '<?xml version="1.0" encoding="utf-8" standalone="no"?>';
$response = '<FooResponse><value_1>Bar</value_1><value_2>Taz</value_2></FooResponse>';
$encoding = 'utf-8';
$tr = new TADResponse($header . $response, $encoding);
$this->assertInstanceOf('TADPHP\TADResponse', $tr);
$this->assertEquals($encoding, $tr->get_encoding());
$this->assertEquals($header, $tr->get_header());
$this->assertEquals($response, $tr->get_response_body());
$this->assertEquals($header . $response, $tr->get_response());
return $tr;
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
*/
public function testGetResponseInDifferentFormats(TADResponse $tr)
{
$xml_response = $tr->get_response(['format'=>'xml']);
libxml_use_internal_errors(true);
$valid_xml = simplexml_load_string($xml_response);
libxml_use_internal_errors(false);
$this->assertNotFalse($valid_xml);
$json_response = $tr->get_response(['format'=>'json']);
$this->assertNotNull(json_decode($json_response));
$array_response = $tr->get_response(['format'=>'array']);
$this->assertTrue(is_array($array_response) && 0 !== count($array_response));
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
*/
public function testSetEmptyResponse(TADResponse $tr)
{
$tr->set_response('');
$expected_empty_response = ''
. '<?xml version="1.0" encoding="utf-8" standalone="no"?>'
. '<Response>'
. '<Row><Result>0</Result><Information>No data!</Information></Row>'
. '</Response>';
$this->assertEquals(1, $tr->count());
$this->assertTrue($tr->is_empty_response());
$this->assertEquals($expected_empty_response, $tr->get_response());
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
*/
public function testChangeAnAlreadySetResponse(TADResponse $tr)
{
$tr = new TADResponse('<Response><data>Foo</data></Response>', 'iso8859-1');
$first_response = $tr->to_xml();
$tr->set_response(''
. '<?xml version="1.0" encoding="utf-8" standalone="no"?>'
. '<Response><data>Foo</data></Response>'
);
$last_response = $tr->to_xml();
$this->assertNotEquals($last_response, $first_response);
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
*/
public function testGetHeader(TADResponse $tr)
{
$expected_header = '<?xml version="1.0" encoding="utf-8" standalone="no"?>';
$this->assertEquals($expected_header, $tr->get_header());
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
*/
public function testSetHeader(TADResponse $tr)
{
$expected_header = '<?xml version="1.1" encoding="iso8859-1" standalone="yes"?>';
$tr->set_header($expected_header);
$this->assertEquals($expected_header, $tr->get_header());
}
public function testGetResponseBody()
{
$tr = new TADResponse('<Response><data>Foo</data></Response>', 'iso8859-1');
$response_body = '<Response><data>Foo</data></Response>';
$this->assertEquals($response_body, $tr->get_response_body());
}
public function testIsEmptyResponse()
{
$tr = new TADResponse('<Response></Response>', 'iso8859-1');
$this->assertTrue($tr->is_empty_response());
}
public function testCount()
{
$tr = new TADResponse('<Response></Response>', 'iso8859-1');
$this->assertTrue(0 === $tr->count()-1);
}
/**
* @expectedException \Exception
*/
public function testExceptionIsThrownWhenUnknownMethodIsInvoked()
{
$tr = new TADResponse('<Response></Response>', 'iso8859-1');
$tr->foo();
}
/**
* @expectedException TADPHP\Exceptions\FilterArgumentError
*/
public function testFilterArgumentExecptionisThrownWhenWrongArgumentNumber()
{
$tr = new TADResponse('<Response></Response>', 'iso8859-1');
$tr->filter_by_date_and_pin(123);
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
* @dataProvider xmlAttLogFixture
* @expectedException TADPHP\Exceptions\FilterArgumentError
*/
public function testFilterResponseByDateThrowsFilterArgumentExceptionWithInvalidRangeKey($xml, TADResponse $tr)
{
$tr->set_response($xml);
$date_range = ['foo'=>'2014-01-01', 'end'=>'2014-11-29'];
$tr->filter_by_date($date_range);
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
* @dataProvider xmlAttLogFixture
*/
public function testFilterResponseByDate($xml, TADResponse $tr)
{
$tr->set_response($xml);
$this->assertEquals(9, $tr->filter_by_date(['start'=>'2014-01-01'])->count());
$this->assertEquals(1, $tr->filter_by_date(['start'=>'2014-12-04'])->count());
$this->assertTrue($tr->filter_by_date(['start'=>'2014-12-05'])->is_empty_response());
$tr->set_response($xml);
$this->assertEquals(9, $tr->filter_by_date(['end'=>'2014-12-31'])->count());
// $this->assertEquals(1, $tr->filter_by_date(['end'=>'2014-11-30'])->count());
$this->assertTrue($tr->filter_by_date(['end'=>'2014-11-29'])->is_empty_response());
$tr->set_response($xml);
$this->assertEquals(9, $tr->filter_by_date(['start'=>'2014-11-01', 'end'=>'2014-12-31'])->count());
$this->assertTrue($tr->filter_by_date(['start'=>'2015-01-01', 'end'=>'2015-12-31'])->is_empty_response());
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
* @dataProvider xmlAttLogFixture
*/
public function testFilterResponseByTime($xml, TADResponse $tr)
{
$tr->set_response($xml);
$this->assertEquals(5, $tr->filter_by_time(['start'=>'18:00:00'])->count());
$this->assertEquals(2, $tr->filter_by_time(['end'=>'19:00:00'])->count());
$this->assertEquals(1, $tr->filter_by_time(['start'=>'00:00:00', 'end'=>'02:00:00'])->count());
$this->assertTrue($tr->filter_by_date(['start'=>'00:00:00', 'end'=>'01:00:00'])->is_empty_response());
}
/**
* @depends testTADResponseIsInstantiatedCorrectly
* @dataProvider xmlAttLogFixture
*/
public function testFilterResponseByDateTime($xml, TADResponse $tr)
{
$tr->set_response($xml);
$this->assertEquals(9, $tr->filter_by_datetime(['start'=>'2014-11-30 18:00:00'])->count()
lib-test-tad-php.zip_TAD_statement2bd_zk attendance
版权申诉
105 浏览量
2022-09-21
01:16:08
上传
评论
收藏 17KB ZIP 举报
朱moyimi
- 粉丝: 61
- 资源: 1万+
最新资源
- 物模块模型代码,前往设计物模块所属
- Java面试手册,助力大家面试过五关斩六将,面试成功
- HITK0303MP-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- mybatis动态sql之xml增删改查批量操作示例EmpMapper.xml
- C/C++内存检测工具Sanitizers
- HITK0302MP-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 宝塔批量建站工具,很优秀的宝塔管理工具,基于宝塔api
- HITK0204MP-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- azeryhgtfxhj
- 操作系统实验页面置换算法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0