-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* This file is part of the Zimbra API in PHP library. | ||
* | ||
* © Nguyen Van Nguyen <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zimbra\Admin\Request; | ||
|
||
use Zimbra\Admin\Struct\ServerSelector; | ||
use Zimbra\Struct\AttributeSelectorTrait; | ||
use Zimbra\Struct\AttributeSelector; | ||
|
||
/** | ||
* SetServerOffline request class | ||
* Get Server. | ||
* | ||
* @package Zimbra | ||
* @subpackage Admin | ||
* @category Request | ||
* @author Nguyen Van Nguyen - [email protected] | ||
* @copyright Copyright © 2013 by Nguyen Van Nguyen. | ||
*/ | ||
class SetServerOffline extends Base implements AttributeSelector | ||
{ | ||
use AttributeSelectorTrait; | ||
|
||
/** | ||
* Constructor method for SetServerOffline | ||
* @param ServerSelector $server Server | ||
* @param array $attrs A list of attributes | ||
* @return self | ||
*/ | ||
public function __construct(ServerSelector $server, array $attrs = []) | ||
{ | ||
parent::__construct(); | ||
$this->setChild('server', $server); | ||
|
||
$this->setAttrs($attrs); | ||
$this->on('before', function(Base $sender) | ||
{ | ||
$attrs = $sender->getAttrs(); | ||
if(!empty($attrs)) | ||
{ | ||
$sender->setProperty('attrs', $attrs); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Gets server. | ||
* | ||
* @return ServerSelector | ||
*/ | ||
public function getServer() | ||
{ | ||
return $this->getChild('server'); | ||
} | ||
|
||
/** | ||
* Sets server. | ||
* | ||
* @param ServerSelector $server | ||
* @return self | ||
*/ | ||
public function setServer(ServerSelector $server) | ||
{ | ||
return $this->setChild('server', $server); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Zimbra\Admin\Tests\Request; | ||
|
||
use Zimbra\Admin\Tests\ZimbraAdminApiTestCase; | ||
use Zimbra\Admin\Request\SetServerOffline; | ||
use Zimbra\Admin\Struct\ServerSelector; | ||
use Zimbra\Enum\ServerBy; | ||
|
||
/** | ||
* Testcase class for SetServerOffline. | ||
*/ | ||
class SetServerOfflineTest extends ZimbraAdminApiTestCase | ||
{ | ||
public function testSetServerOfflineRequest() | ||
{ | ||
$value = $this->faker->word; | ||
$attrs = $this->faker->word; | ||
|
||
$server = new ServerSelector(ServerBy::NAME(), $value); | ||
$req = new SetServerOffline($server, [$attrs]); | ||
$this->assertInstanceOf('Zimbra\Admin\Request\Base', $req); | ||
$this->assertSame($server, $req->getServer()); | ||
|
||
$req->setServer($server); | ||
$this->assertSame($server, $req->getServer()); | ||
|
||
$xml = '<?xml version="1.0"?>' . "\n" | ||
. '<SetServerOfflineRequest attrs="' . $attrs . '">' | ||
. '<server by="' . ServerBy::NAME() . '">' . $value . '</server>' | ||
. '</SetServerOfflineRequest>'; | ||
$this->assertXmlStringEqualsXmlString($xml, (string) $req); | ||
|
||
$array = [ | ||
'SetServerOfflineRequest' => [ | ||
'_jsns' => 'urn:zimbraAdmin', | ||
'attrs' => $attrs, | ||
'server' => [ | ||
'by' => ServerBy::NAME()->value(), | ||
'_content' => $value, | ||
], | ||
], | ||
]; | ||
$this->assertEquals($array, $req->toArray()); | ||
} | ||
|
||
public function testSetServerOfflineApi() | ||
{ | ||
$value = $this->faker->word; | ||
$attrs = $this->faker->word; | ||
|
||
$server = new ServerSelector(ServerBy::NAME(), $value); | ||
|
||
$this->api->setServerOffline($server, [$attrs]); | ||
|
||
$client = $this->api->getClient(); | ||
$req = $client->lastRequest(); | ||
$xml = '<?xml version="1.0"?>' . "\n" | ||
. '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAdmin">' | ||
. '<env:Body>' | ||
. '<urn1:SetServerOfflineRequest attrs="' . $attrs . '">' | ||
. '<urn1:server by="' . ServerBy::NAME() . '">' . $value . '</urn1:server>' | ||
. '</urn1:SetServerOfflineRequest>' | ||
. '</env:Body>' | ||
. '</env:Envelope>'; | ||
$this->assertXmlStringEqualsXmlString($xml, (string) $req); | ||
} | ||
} |