public function testCacheEntryBy() { $values = array('id', 'name'); foreach ($values as $value) { $this->assertTrue(\Zimbra\Enum\CacheEntryBy::has($value)); } }
public function testFlushCacheApi() { $value = $this->faker->word; $enums = $this->faker->randomElements(CacheType::enums(), mt_rand(1, count(CacheType::enums()))); $types = implode(',', $enums); $entry = new CacheEntrySelector(CacheEntryBy::NAME(), $value); $cache = new CacheSelector($types, true, [$entry]); $this->api->flushCache($cache); $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:FlushCacheRequest>' . '<urn1:cache type="' . $types . '" allServers="true">' . '<urn1:entry by="' . CacheEntryBy::NAME() . '">' . $value . '</urn1:entry>' . '</urn1:cache>' . '</urn1:FlushCacheRequest>' . '</env:Body>' . '</env:Envelope>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); }
public function testCacheEntrySelector() { $value = $this->faker->word; $entry = new CacheEntrySelector(CacheEntryBy::NAME(), $value); $this->assertTrue($entry->getBy()->is('name')); $this->assertSame($value, $entry->getValue()); $entry->setBy(CacheEntryBy::ID()); $this->assertTrue($entry->getBy()->is('id')); $xml = '<?xml version="1.0"?>' . "\n" . '<entry by="' . CacheEntryBy::ID() . '">' . $value . '</entry>'; $this->assertXmlStringEqualsXmlString($xml, (string) $entry); $array = ['entry' => ['by' => CacheEntryBy::ID()->value(), '_content' => $value]]; $this->assertEquals($array, $entry->toArray()); }
public function testCacheSelector() { $value1 = $this->faker->word; $value2 = $this->faker->word; $enums = $this->faker->randomElements(CacheType::enums(), mt_rand(1, count(CacheType::enums()))); $types = implode(',', $enums); $entry1 = new CacheEntrySelector(CacheEntryBy::ID(), $value1); $entry2 = new CacheEntrySelector(CacheEntryBy::NAME(), $value2); $cache = new CacheSelector($types, false, [$entry1]); $this->assertSame($types, $cache->getTypes()); $this->assertFalse($cache->isAllServers()); $this->assertSame([$entry1], $cache->getEntries()->all()); $cache->setTypes($types)->setAllServers(true)->addEntry($entry2); $this->assertSame($types, $cache->getTypes()); $this->assertTrue($cache->isAllServers()); $this->assertSame([$entry1, $entry2], $cache->getEntries()->all()); $xml = '<?xml version="1.0"?>' . "\n" . '<cache type="' . $types . '" allServers="true">' . '<entry by="' . CacheEntryBy::ID() . '">' . $value1 . '</entry>' . '<entry by="' . CacheEntryBy::NAME() . '">' . $value2 . '</entry>' . '</cache>'; $this->assertXmlStringEqualsXmlString($xml, (string) $cache); $array = ['cache' => ['type' => $types, 'allServers' => true, 'entry' => [['by' => CacheEntryBy::ID()->value(), '_content' => $value1], ['by' => CacheEntryBy::NAME()->value(), '_content' => $value2]]]]; $this->assertEquals($array, $cache->toArray()); }
public function testFlushCache() { $value = self::randomName(); $types = self::randomAttrs(\Zimbra\Enum\CacheType::enums()); $entry = new \Zimbra\Admin\Struct\CacheEntrySelector(CacheEntryBy::NAME(), $value); $cache = new \Zimbra\Admin\Struct\CacheSelector($types, true, [$entry]); $this->_api->flushCache($cache); $client = $this->_api->client(); $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:FlushCacheRequest>' . '<urn1:cache type="' . $types . '" allServers="true">' . '<urn1:entry by="' . CacheEntryBy::NAME() . '">' . $value . '</urn1:entry>' . '</urn1:cache>' . '</urn1:FlushCacheRequest>' . '</env:Body>' . '</env:Envelope>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); }
public function testCacheSelector() { $value1 = md5(self::randomString()); $value2 = md5(self::randomString()); $types = self::randomAttrs(\Zimbra\Enum\CacheType::enums()); $entry1 = new \Zimbra\Admin\Struct\CacheEntrySelector(CacheEntryBy::ID(), $value1); $entry2 = new \Zimbra\Admin\Struct\CacheEntrySelector(CacheEntryBy::NAME(), $value2); $cache = new \Zimbra\Admin\Struct\CacheSelector($types, false, [$entry1]); $this->assertSame($types, $cache->getTypes()); $this->assertFalse($cache->isAllServers()); $this->assertSame([$entry1], $cache->getEntries()->all()); $cache->setTypes($types)->setAllServers(true)->addEntry($entry2); $this->assertSame($types, $cache->getTypes()); $this->assertTrue($cache->isAllServers()); $this->assertSame([$entry1, $entry2], $cache->getEntries()->all()); $xml = '<?xml version="1.0"?>' . "\n" . '<cache type="' . $types . '" allServers="true">' . '<entry by="' . CacheEntryBy::ID() . '">' . $value1 . '</entry>' . '<entry by="' . CacheEntryBy::NAME() . '">' . $value2 . '</entry>' . '</cache>'; $this->assertXmlStringEqualsXmlString($xml, (string) $cache); $array = ['cache' => ['type' => $types, 'allServers' => true, 'entry' => [['by' => CacheEntryBy::ID()->value(), '_content' => $value1], ['by' => CacheEntryBy::NAME()->value(), '_content' => $value2]]]]; $this->assertEquals($array, $cache->toArray()); }
public function testFlushCache() { $value = self::randomName(); $types = self::randomAttrs(\Zimbra\Enum\CacheType::enums()); $entry = new \Zimbra\Admin\Struct\CacheEntrySelector(CacheEntryBy::NAME(), $value); $cache = new \Zimbra\Admin\Struct\CacheSelector($types, true, [$entry]); $req = new \Zimbra\Admin\Request\FlushCache($cache); $this->assertInstanceOf('Zimbra\\Admin\\Request\\Base', $req); $this->assertSame($cache, $req->getCache()); $req->setCache($cache); $this->assertSame($cache, $req->getCache()); $xml = '<?xml version="1.0"?>' . "\n" . '<FlushCacheRequest>' . '<cache type="' . $types . '" allServers="true">' . '<entry by="' . CacheEntryBy::NAME() . '">' . $value . '</entry>' . '</cache>' . '</FlushCacheRequest>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); $array = ['FlushCacheRequest' => ['_jsns' => 'urn:zimbraAdmin', 'cache' => ['type' => $types, 'allServers' => true, 'entry' => [['by' => CacheEntryBy::NAME()->value(), '_content' => $value]]]]]; $this->assertEquals($array, $req->toArray()); }