Пример #1
0
 /**
  * Sets cache types
  *
  * @param  string $type
  * @return self
  */
 public function setTypes($type)
 {
     $arrTypes = explode(',', $type);
     $types = [];
     foreach ($arrTypes as $type) {
         $type = trim($type);
         if (CacheType::has($type) && !in_array($type, $types)) {
             $types[] = $type;
         }
     }
     return $this->setProperty('type', implode(',', $types));
 }
Пример #2
0
 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);
 }
Пример #3
0
 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());
 }
Пример #4
0
 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());
 }
Пример #5
0
 public function testCacheType()
 {
     $values = array('skin', 'locale', 'account', 'cos', 'domain', 'server', 'zimlet');
     foreach ($values as $value) {
         $this->assertTrue(\Zimbra\Enum\CacheType::has($value));
     }
 }
Пример #6
0
 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);
 }
Пример #7
0
 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());
 }