Skip to content

Commit

Permalink
Add SetServerOffline request class
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyennv committed Mar 23, 2016
1 parent 0866906 commit 5dcc80b
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Request/SetServerOffline.php
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);
}
}
68 changes: 68 additions & 0 deletions Tests/Request/SetServerOfflineTest.php
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);
}
}

0 comments on commit 5dcc80b

Please sign in to comment.