public function setUp() { CM_Config::get()->CM_Model_Abstract->types[CM_Model_StreamChannel_Mock::getTypeStatic()] = 'CM_Model_StreamChannel_Mock'; if (!class_exists('CM_Model_StreamChannel_Mock')) { $this->getMockForAbstractClass('CM_Model_StreamChannel_Abstract', array(), 'CM_Model_StreamChannel_Mock', false); } }
public function testAdd() { CM_Config::get()->CM_Paging_Ip_Blocked->maxAge = 3 * 86400; $ip = '127.0.0.1'; $ip2 = '127.0.0.2'; $paging = new CM_Paging_Ip_Blocked(); $paging->add(ip2long($ip)); $this->assertEquals(1, $paging->getCount()); $entry = $paging->getItem(0); $this->assertTrue($paging->contains(ip2long($ip))); CMTest_TH::timeDaysForward(2); $paging->add(ip2long($ip2)); CM_Cache_Local::getInstance()->flush(); $paging->_change(); $this->assertEquals(2, $paging->getCount()); CMTest_TH::timeDaysForward(2); CM_Paging_Ip_Blocked::deleteOld(); CM_Cache_Local::getInstance()->flush(); $paging->_change(); $this->assertEquals(1, $paging->getCount()); CMTest_TH::timeDaysForward(2); CM_Paging_Ip_Blocked::deleteOld(); CM_Cache_Local::getInstance()->flush(); $this->assertEquals(1, $paging->getCount()); $paging->_change(); $this->assertEquals(0, $paging->getCount()); }
public function testLoadMultiple() { CM_Config::get()->CM_Model_Abstract = new stdClass(); CM_Config::get()->CM_Model_Abstract->types = array(1 => 'CMTest_ModelMock_1', 2 => 'CMTest_ModelMock_2'); $adapter = new CM_Model_StorageAdapter_Cache(); $id1 = 1; $id2 = 2; $id3 = 3; $id4 = 1; $id5 = 2; $dataSet = array(); $dataSet[] = array('type' => 1, 'id' => array('id' => $id1), 'data' => array('foo' => 'foo1', 'bar' => 1)); $dataSet[] = array('type' => 1, 'id' => array('id' => $id2), 'data' => array('foo' => 'foo2', 'bar' => 2)); $dataSet[] = array('type' => 1, 'id' => array('id' => $id3), 'data' => array('foo' => 'foo3', 'bar' => 3)); $dataSet[] = array('type' => 2, 'id' => array('id' => $id4), 'data' => array('foo' => 'foo4', 'bar' => 4)); $dataSet[] = array('type' => 2, 'id' => array('id' => $id5), 'data' => array('foo' => 'foo5', 'bar' => 5)); foreach ($dataSet as $data) { $adapter->save($data['type'], $data['id'], $data['data']); } $idsTypes = array('a' => array('type' => 1, 'id' => array('id' => $id1)), 2 => array('type' => 2, 'id' => array('id' => $id4)), 'foo' => array('type' => 1, 'id' => array('id' => $id2))); $expected = array('a' => array('foo' => 'foo1', 'bar' => 1), 2 => array('foo' => 'foo4', 'bar' => 4), 'foo' => array('foo' => 'foo2', 'bar' => 2)); $values = $adapter->loadMultiple($idsTypes); $this->assertSame(3, count($values)); $this->assertSame($expected, $values); }
public function testCheckStreams() { $mockAdapter = $this->getMockForAbstractClass('CM_Stream_Adapter_Video_Abstract', array(), 'CM_Stream_Adapter_Video_Mock', true, true, true, array('_stopStream', 'getType')); $mockAdapter->expects($this->exactly(2))->method('_stopStream')->will($this->returnValue(1)); $mockAdapter->expects($this->any())->method('getType')->will($this->returnValue(1)); CM_Config::get()->CM_Model_StreamChannel_Abstract->types[CM_Model_StreamChannel_Video_Mock::getTypeStatic()] = 'CM_Model_StreamChannel_Video_Mock'; $wowza = $wowza = $this->getMock('CM_Stream_Video', array('getAdapter')); $wowza->expects($this->any())->method('getAdapter')->will($this->returnValue($mockAdapter)); /** @var $wowza CM_Stream_Video */ // allowedUntil will be updated, if stream has expired and its user isn't $userUnchanged, hardcoded in CM_Model_StreamChannel_Video_Mock::canSubscribe() using getOnline() $userUnchanged = CMTest_TH::createUser(); $userUnchanged->setOnline(); $streamChannel = CM_Model_StreamChannel_Video_Mock::createStatic(array('key' => 'foo1', 'serverId' => 1, 'adapterType' => 1, 'width' => 100, 'height' => 100, 'thumbnailCount' => 0)); $streamSubscribeUnchanged1 = CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => $userUnchanged, 'key' => 'foo1_2', 'start' => time())); $streamSubscribeUnchanged2 = CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => CMTest_TH::createUser(), 'key' => 'foo1_4', 'start' => time())); $streamSubscribeChanged1 = CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => CMTest_TH::createUser(), 'key' => 'foo1_3', 'start' => time())); $streamPublishUnchanged1 = CM_Model_Stream_Publish::createStatic(array('streamChannel' => $streamChannel, 'user' => $userUnchanged, 'key' => 'foo1_2', 'start' => time())); $streamPublishChanged1 = CM_Model_Stream_Publish::createStatic(array('streamChannel' => CM_Model_StreamChannel_Video_Mock::createStatic(array('key' => 'foo2', 'serverId' => 1, 'adapterType' => 1, 'width' => 100, 'height' => 100, 'thumbnailCount' => 0)), 'user' => CMTest_TH::createUser(), 'key' => 'foo2_1', 'start' => time())); $this->assertSameTime($streamSubscribeUnchanged1->getAllowedUntil(), time() + 10); $this->assertSameTime($streamSubscribeUnchanged2->getAllowedUntil(), time() + 100); $this->assertSameTime($streamSubscribeChanged1->getAllowedUntil(), time() + 100); $this->assertSameTime($streamPublishUnchanged1->getAllowedUntil(), time() + 10); $this->assertSameTime($streamPublishChanged1->getAllowedUntil(), time() + 100); CMTest_TH::timeForward(200); $wowza->checkStreams(); $this->assertEquals($streamSubscribeUnchanged1->getAllowedUntil() + 10, $streamSubscribeUnchanged1->_change()->getAllowedUntil()); $this->assertEquals($streamSubscribeUnchanged2->getAllowedUntil() + 100, $streamSubscribeUnchanged2->_change()->getAllowedUntil()); $this->assertEquals($streamSubscribeChanged1->getAllowedUntil() + 100, $streamSubscribeChanged1->_change()->getAllowedUntil()); $this->assertEquals($streamPublishUnchanged1->getAllowedUntil() + 10, $streamPublishUnchanged1->_change()->getAllowedUntil()); $this->assertEquals($streamPublishChanged1->getAllowedUntil() + 100, $streamPublishChanged1->_change()->getAllowedUntil()); }
public function testGetConfig() { /** @var CM_Site_Abstract $site */ $site = $this->getMockForAbstractClass('CM_Site_Abstract'); $config = CM_Config::get()->CM_Site_Abstract; $this->assertEquals($config, $site->getConfig()); }
/** * @param string|null $classname * @param int|null $type * @param array|null $configuration * @param array|null $methods * @throws CM_Exception_Invalid * @return CM_Site_Abstract|PHPUnit_Framework_MockObject_MockObject */ public function getMockSite($classname = null, $type = null, array $configuration = null, array $methods = null) { if (null === $classname) { $classname = 'CM_Site_Abstract'; } $classname = (string) $classname; $config = CM_Config::get(); if (null === $type) { $type = $config->CM_Class_Abstract->typesMaxValue + 1; } $type = (int) $type; $types = $config->CM_Site_Abstract->types; if (isset($types[$type])) { throw new CM_Exception_Invalid('Site type ' . $type . ' already used'); } $methods = (array) $methods; $defaultConfiguration = array('url' => null, 'urlCdn' => null, 'name' => null, 'emailAddress' => null); $configuration = array_merge($defaultConfiguration, (array) $configuration); $mockClassname = $classname . '_Mock' . $type . '_' . uniqid(); $site = $this->getMockForAbstractClass($classname, array(), $mockClassname, true, true, true, $methods); $siteClassName = get_class($site); $config->CM_Site_Abstract->types[$type] = $siteClassName; $config->{$siteClassName} = new stdClass(); $config->{$siteClassName}->type = $type; foreach ($configuration as $key => $value) { $config->{$siteClassName}->{$key} = $value; } $config->CM_Class_Abstract->typesMaxValue = $type; return $site; }
/** * @return CM_Site_Abstract[] */ public static function getAll() { $siteList = array(); foreach (CM_Config::get()->CM_Site_Abstract->types as $className) { $siteList[] = new $className(); } return $siteList; }
public function testGetTableName() { CM_Config::get()->CM_Model_Abstract = new stdClass(); CM_Config::get()->CM_Model_Abstract->types = array(1 => 'CMTest_ModelMock_1', 2 => 'CMTest_ModelMock_2'); $adapter = new CM_Model_StorageAdapter_Database(); $method = CMTest_TH::getProtectedMethod('CM_Model_StorageAdapter_Database', '_getTableName'); $this->assertSame('cmtest_modelmock_1', $method->invoke($adapter, 1)); $this->assertSame('custom_table', $method->invoke($adapter, 2)); }
public function testGetCollectionName() { CM_Config::get()->CM_Model_Abstract = new stdClass(); CM_Config::get()->CM_Model_Abstract->types = [1 => 'CMTest_ModelMock_3', 2 => 'CMTest_ModelMock_4']; $adapter = new CM_Model_StorageAdapter_MongoDb(); $method = CMTest_TH::getProtectedMethod('CM_Model_StorageAdapter_MongoDb', '_getCollectionName'); $this->assertSame('cmtest_modelmock_3', $method->invoke($adapter, 1)); $this->assertSame('custom_table', $method->invoke($adapter, 2)); }
public function testHasZone() { $site = $this->getMockSite(); CM_Config::get()->CM_Adprovider->enabled = true; CM_Config::get()->CM_Adprovider->zones = array('foo' => array('adapter' => 'CM_AdproviderAdapter_Nonexistent')); $adprovider = new CM_Adprovider(); $this->assertSame(true, $adprovider->hasZone($site, 'foo')); $this->assertSame(false, $adprovider->hasZone($site, 'bar')); }
public function testGetHtml() { CM_Config::get()->CM_Adprovider->enabled = true; CM_Config::get()->CM_AdproviderAdapter_Openx->host = 'www.foo.org'; $openx = new CM_AdproviderAdapter_Openx(); $html = $openx->getHtml('zoneName1', array('zoneId' => 'zone1'), array('foo' => 'bar')); $this->assertContains('<div class="openx-ad" data-zone-id="zone1" data-host="www.foo.org" data-variables="{"foo":"bar"}"', $html); $html = $openx->getHtml('zoneName1', array('zoneId' => 'zone1'), array()); $this->assertContains('<div class="openx-ad" data-zone-id="zone1" data-host="www.foo.org" data-variables="{}"', $html); }
/** * @return array */ protected function _getAllTypes() { $config = CM_Config::get(); $typeList = []; foreach (get_object_vars($config) as $key => $value) { if (isset($value->types)) { $typeList += $value->types; } } return $typeList; }
public function generateInternalConfig() { if (isset(CM_Config::get()->CM_Class_Abstract->typesMaxValue)) { return; } $generator = new CM_Config_Generator(); $config = new CM_Config_Node(); $config->extendWithConfig($generator->getConfigClassTypes()); $config->extendWithConfig($generator->getConfigActionVerbs()); $config->extendWithConfig(CM_Config::get()); CM_Config::set($config->export()); }
public function testSend() { CM_Config::get()->CM_Mail->send = true; /** @var PHPMailer|\Mocka\AbstractClassTrait $_mockPHPMailer*/ $phpMailer = $this->mockObject('PHPMailer'); $setFromMethod = $phpMailer->mockMethod('SetFrom')->set(function ($address, $name) { $this->assertSame('*****@*****.**', $address); $this->assertSame('Sender', $name); }); $addReplyToMethod = $phpMailer->mockMethod('AddReplyTo')->set(function ($address) { $this->assertSame('*****@*****.**', $address); }); $addAddress = $phpMailer->mockMethod('AddAddress')->set(function ($address) { $this->assertSame('*****@*****.**', $address); }); $addCC = $phpMailer->mockMethod('AddCC')->set(function ($address, $name) { $this->assertSame('*****@*****.**', $address); $this->assertSame('foobar', $name); }); $addBCC = $phpMailer->mockMethod('AddBCC')->set(function ($address) { $this->assertSame('*****@*****.**', $address); }); $addCustomHeader = $phpMailer->mockMethod('AddCustomHeader')->at(0, function ($name, $value) { $this->assertSame('X-Foo', $name); $this->assertSame('bar,foo', $value); })->at(1, function ($name, $value) { $this->assertSame('X-Bar', $name); $this->assertSame('foo', $value); }); $sendMethod = $phpMailer->mockMethod('Send'); $mail = $this->mockObject('CM_Mail', ['*****@*****.**']); $mail->mockMethod('_getPHPMailer')->set(function () use($phpMailer) { return $phpMailer; }); /** @var CM_Mail $mail */ $mail->setSender('*****@*****.**', 'Sender'); $mail->setSubject('testSubject'); $mail->setHtml('<b>hallo</b>'); $mail->addReplyTo('*****@*****.**'); $mail->addCc('*****@*****.**', 'foobar'); $mail->addBcc('*****@*****.**'); $mail->addCustomHeader('X-Foo', 'bar'); $mail->addCustomHeader('X-Bar', 'foo'); $mail->addCustomHeader('X-Foo', 'foo'); $mail->send(); $this->assertSame(1, $setFromMethod->getCallCount()); $this->assertSame(1, $addReplyToMethod->getCallCount()); $this->assertSame(1, $addAddress->getCallCount()); $this->assertSame(1, $addCC->getCallCount()); $this->assertSame(1, $addBCC->getCallCount()); $this->assertSame(2, $addCustomHeader->getCallCount()); $this->assertSame(1, $sendMethod->getCallCount()); }
public static function init() { $output = new CM_OutputStream_Null(); $loader = CM_App::getInstance()->getProvisionLoader(); $loader->unload($output); $loader->load($output); self::$_configBackup = serialize(CM_Config::get()); // Reset environment self::clearEnv(); self::randomizeAutoincrement(); self::timeInit(); }
public function testGetHtmlInvalidAdapter() { $site = $this->getMockSite(); CM_Config::get()->CM_Adprovider->enabled = true; CM_Config::get()->CM_Adprovider->zones = array('foo' => array('adapter' => 'CM_AdproviderAdapter_Nonexistent')); $adprovider = new CM_Adprovider(); try { $adprovider->getHtml($site, 'foo'); $this->fail('No exception for invalid ad adapter'); } catch (CM_Exception_Invalid $e) { $this->assertContains('Invalid ad adapter', $e->getMessage()); } }
public function testGetConfigActionVerbsConfig() { CM_Config::get()->CM_Action_Abstract->verbsMaxValue = 5; CM_Config::get()->CM_Action_Abstract->verbs = array(); $actionVerbs = array(array('name' => 'CREATE', 'value' => 'Create', 'className' => 'CM_Action_Abstract')); $expected = new CM_Config_Node(); $expected->CM_Action_Abstract->verbs = ['CM_Action_Abstract::CREATE' => 6]; $expected->CM_Action_Abstract->verbsMaxValue = 6; $generator = $this->getMockBuilder('CM_Config_Generator')->setMethods(array('getActionVerbs'))->getMock(); $generator->expects($this->any())->method('getActionVerbs')->will($this->returnValue($actionVerbs)); /** @var CM_Config_Generator $generator */ $this->assertEquals($expected, $generator->getConfigActionVerbs()); }
public function testLoadTwice() { $dumper = new CM_Class_TypeDumper($this->getServiceManager()); CM_Config::get()->Foo = new stdClass(); CM_Config::get()->Foo->types = [1111 => 'Foo1', 2222 => 'Foo2', 3333 => 'Foo3']; $dumper->load(new CM_OutputStream_Null()); CM_Config::get()->Foo->types = [1111 => 'Foo1', 2222 => 'Foo2']; $dumper->load(new CM_OutputStream_Null()); $dbClient = $this->getServiceManager()->getDatabases()->getMaster(); $this->assertSame('1', (new CM_Db_Query_Count($dbClient, 'cm_tmp_classType', ['type' => 1111]))->execute()->fetchColumn()); $this->assertSame('1', (new CM_Db_Query_Count($dbClient, 'cm_tmp_classType', ['type' => 2222]))->execute()->fetchColumn()); $this->assertSame('0', (new CM_Db_Query_Count($dbClient, 'cm_tmp_classType', ['type' => 3333]))->execute()->fetchColumn()); }
/** * @return stdClass * @throws CM_Exception_Invalid */ protected static function _getConfigRaw() { $config = CM_Config::get(); $result = array(); foreach (self::_getClassHierarchy() as $class) { if (isset($config->{$class})) { $result = array_merge((array) $config->{$class}, $result); } } if (empty($result)) { throw new CM_Exception_Invalid('Class `' . get_called_class() . '` has no configuration.'); } return (object) $result; }
/** * @param CM_Site_Abstract $site * @param string $zoneName * @return mixed * @throws CM_Exception_Invalid */ protected function _getZone(CM_Site_Abstract $site, $zoneName) { $cacheKey = CM_CacheConst::AdproviderZones . '_siteId:' . $site->getId(); $cache = CM_Cache_Local::getInstance(); if (false === ($zones = $cache->get($cacheKey))) { $zones = CM_Config::get()->CM_Adprovider->zones; if (isset($site->getConfig()->CM_Adprovider->zones)) { $zones = array_merge($zones, $site->getConfig()->CM_Adprovider->zones); } $cache->set($cacheKey, $zones); } if (!array_key_exists($zoneName, $zones)) { throw new CM_Exception_Invalid('Zone `' . $zoneName . '` not configured.'); } return $zones[$zoneName]; }
/** * @param CM_Site_Abstract $site * @param string $zoneName * @return array * @throws CM_Exception_Invalid */ protected function _getZoneData(CM_Site_Abstract $site, $zoneName) { $cacheKey = CM_CacheConst::AdproviderZones . '_siteId:' . $site->getId(); $cache = CM_Cache_Local::getInstance(); if (false === ($zones = $cache->get($cacheKey))) { $zones = CM_Config::get()->CM_Adprovider->zones; if (isset($site->getConfig()->CM_Adprovider->zones)) { $zones = array_merge($zones, $site->getConfig()->CM_Adprovider->zones); } $cache->set($cacheKey, $zones); } if (!array_key_exists($zoneName, $zones)) { return null; } return $zones[$zoneName]; }
public function testRunJobLimit() { $serviceManager = new CM_Service_Manager(); $logger = $this->mockObject('CM_Log_Logger'); $serviceManager->registerInstance('logger', $logger); if (!extension_loaded('gearman')) { $this->markTestSkipped('Gearman Pecl Extension not installed.'); } $gearmanWorker = $this->mockClass('GearmanWorker')->newInstanceWithoutConstructor(); $workMethod = $gearmanWorker->mockMethod('work')->set(true); CM_Config::get()->CM_Jobdistribution_JobWorker->servers = []; $worker = $this->mockClass(CM_Jobdistribution_JobWorker::class)->newInstance([5]); $worker->mockMethod('_getGearmanWorker')->set($gearmanWorker); /** @var CM_Jobdistribution_JobWorker $worker */ $worker->setServiceManager($serviceManager); $worker->run(); $this->assertSame(5, $workMethod->getCallCount()); }
public function testGetConfigCaching() { $reflectedClass = new ReflectionClass('CM_Class_Abstract'); $configCacheList = $reflectedClass->getProperty('_classConfigList'); $configCacheList->setAccessible(true); CM_Config::get()->CM_Class_Implementation = new stdClass(); CM_Config::get()->CM_Class_Implementation->foo = 'foo'; $this->assertSame('foo', CM_Class_Implementation::getConfig()->foo); CM_Config::get()->CM_Class_Implementation->foo = 'bar'; $this->assertSame('foo', CM_Class_Implementation::getConfig()->foo); $configCacheList->setValue([]); $this->assertSame('foo', CM_Class_Implementation::getConfig()->foo); $cache = new CM_Cache_Storage_Apc(); $cache->flush(); $this->assertSame('foo', CM_Class_Implementation::getConfig()->foo); $configCacheList->setValue([]); $this->assertSame('bar', CM_Class_Implementation::getConfig()->foo); }
public function testModelListInvalidation() { CM_Config::get()->CM_Model_Abstract->types[CM_Paging_ModelAbstractTest_ModelMock::getTypeStatic()] = 'CM_Paging_ModelAbstractTest_ModelMock'; CM_Config::get()->CM_Model_Abstract->types[CM_Paging_ModelAbstractTest_ModelMock2::getTypeStatic()] = 'CM_Paging_ModelAbstractTest_ModelMock2'; $model1 = CM_Paging_ModelAbstractTest_ModelMock::create('foo'); $model2 = CM_Paging_ModelAbstractTest_ModelMock2::create('bar'); $model3 = CM_Paging_ModelAbstractTest_ModelMock::create('baz'); $model4 = CM_Paging_ModelAbstractTest_ModelMock::create('quux'); $model5 = CM_Paging_ModelAbstractTest_ModelMock::create('foobar'); $source = new CM_PagingSource_Array(array(array('type' => $model1->getType(), 'id' => $model1->getId()), array('type' => $model2->getType(), 'id' => $model2->getId()), array('type' => $model3->getType(), 'id' => $model3->getId()), array('type' => $model4->getType(), 'id' => $model4->getId()), array('type' => $model5->getType(), 'id' => $model5->getId()), array('type' => $model1->getType(), 'id' => 9999))); $modelPaging = $this->getMockBuilder('CM_Paging_ModelAbstract')->setConstructorArgs(array($source))->getMockForAbstractClass(); /** @var CM_Paging_ModelAbstract $modelPaging */ $modelPaging->setPage(1, 2); $this->assertEquals($model1, $modelPaging->getItem(0)); $this->assertEquals($model2, $modelPaging->getItem(1)); $modelPaging->setPage(2, 2); $this->assertEquals($model3, $modelPaging->getItem(0)); $this->assertEquals($model4, $modelPaging->getItem(1)); }
public function setUp() { $config = CM_Config::get(); $className = __CLASS__; $key = (string) $config->{$className}->key; $secret = (string) $config->{$className}->secret; $region = (string) $config->{$className}->region; if (empty($key) || empty($secret)) { $this->markTestSkipped('Missing `key` or `secret` config.'); } $this->_client = \Aws\S3\S3Client::factory(array('key' => $key, 'secret' => $secret)); $this->_client->getConfig()->set('curl.options', array('body_as_string' => true)); // https://github.com/aws/aws-sdk-php/issues/140#issuecomment-25117635 $this->_bucket = strtolower(str_replace('_', '-', 'test-' . __CLASS__ . uniqid())); $this->_filesystem = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_AwsS3($this->_client, $this->_bucket)); $this->_client->createBucket(array('Bucket' => $this->_bucket, 'LocationConstraint' => $region)); $this->_client->waitUntilBucketExists(array('Bucket' => $this->_bucket)); $this->_client->putBucketVersioning(array('Bucket' => $this->_bucket, 'Status' => 'Enabled')); $this->_restore = new CMService_AwsS3Versioning_Client($this->_client, $this->_bucket, new CM_OutputStream_Null()); }
public function testProcessExceptionCatching() { CM_Config::get()->CM_Http_Response_RPC->catchPublicExceptions = true; CM_Config::get()->CM_Http_Response_RPC->exceptionsToCatch = ['CM_Exception_Nonexistent' => []]; $request = $this->mockObject('CM_Http_Request_Abstract', ['/rpc/' . CM_Site_Abstract::factory()->getType() . '/foo']); $request->mockMethod('getQuery')->set(function () { throw new CM_Exception_Invalid('foo', null, ['messagePublic' => 'bar']); }); /** @var CM_Http_Request_Abstract|\Mocka\AbstractClassTrait $request */ $response = new CM_Http_Response_RPC($request, $this->getServiceManager()); $response->process(); $responseData = CM_Params::jsonDecode($response->getContent()); $this->assertSame(['error' => ['type' => 'CM_Exception_Invalid', 'msg' => 'bar', 'isPublic' => true]], $responseData); $request->mockMethod('getQuery')->set(function () { throw new CM_Exception_Nonexistent('foo'); }); $response = new CM_Http_Response_RPC($request, CMTest_TH::getServiceManager()); $response->process(); $responseData = CM_Params::jsonDecode($response->getContent()); $this->assertSame(['error' => ['type' => 'CM_Exception_Nonexistent', 'msg' => 'Internal server error', 'isPublic' => false]], $responseData); }
public function testPagingVariableType() { CM_Config::get()->CM_Model_Abstract->types[CM_Paging_ModelAbstractTest_ModelMock::getTypeStatic()] = 'CM_Paging_ModelAbstractTest_ModelMock'; CM_Config::get()->CM_Model_Abstract->types[CM_Paging_ModelAbstractTest_ModelMock2::getTypeStatic()] = 'CM_Paging_ModelAbstractTest_ModelMock2'; $model1 = CM_Paging_ModelAbstractTest_ModelMock::create('foo'); $model2 = CM_Paging_ModelAbstractTest_ModelMock2::create('bar'); $source = new CM_PagingSource_Array(array(array('type' => $model1->getType(), 'id' => $model1->getId()), array('type' => $model2->getType(), 'id' => $model2->getId()), array('type' => $model1->getType(), 'id' => 9999))); $modelPaging = $this->getMockBuilder('CM_Paging_ModelAbstract')->setConstructorArgs(array($source))->getMockForAbstractClass(); /** @var CM_Paging_ModelAbstract $modelPaging */ $this->assertCount(3, $modelPaging); $this->assertEquals($model1, $modelPaging->getItem(0)); $this->assertEquals($model2, $modelPaging->getItem(1)); try { $modelPaging->getItem(2); $this->fail('Can access nonexistent item.'); } catch (CM_Exception_Nonexistent $ex) { $this->assertContains('Model itemRaw: `Array', $ex->getMessage()); $this->assertContains('[type] => ' . $model1->getType(), $ex->getMessage()); $this->assertContains('[id] => 9999', $ex->getMessage()); $this->assertContains('` has no data', $ex->getMessage()); } }
/** * @return int */ public function getDeployVersion() { return (int) CM_Config::get()->deployVersion; }
public function setUp() { CM_Config::get()->CM_Stream_Video->servers = array(1 => array('publicHost' => 'video.example.com', 'publicIp' => '10.0.3.109', 'privateIp' => '10.0.3.108')); }
public function testFactoryGenericMultipleWithModelType() { CM_Config::get()->CM_Model_Abstract->types[CM_ModelMock::getTypeStatic()] = 'CM_ModelMock'; CM_Config::get()->CM_Model_Abstract->types[CM_ModelMock3::getTypeStatic()] = 'CM_ModelMock3'; /** @var CM_ModelMock $model1 */ $model1 = CM_ModelMock::createStatic(array('foo' => 'foo1')); /** @var CM_ModelMock $model2 */ $model2 = CM_ModelMock::createStatic(array('foo' => 'foo2')); /** @var CM_ModelMock[] $models */ $models = CM_Model_Abstract::factoryGenericMultiple(array($model1->getId(), $model2->getIdRaw()), CM_ModelMock::getTypeStatic()); $this->assertEquals($model1, $models[0]); $this->assertEquals($model2, $models[1]); }