/** * @expectedException CM_Exception * @expectedExceptionMessage Path is out of filesystem directory */ public function testGetRelativePathOutOfFilesystem() { $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass(); /** @var CM_File_Filesystem_Adapter $adapter */ $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getRelativePath'); $method->invoke($adapter, '/base/base2/../foo'); }
public function testProcessTranslationsEnableKey() { $language = CMTest_TH::createLanguage('test'); $languageKey = CM_Model_LanguageKey::create('Hello World'); $this->assertSame(false, $languageKey->getJavascript()); $site = CM_Site_Abstract::factory(); $render = new CM_Frontend_Render(new CM_Frontend_Environment(null, null, $language)); // Check that key is *not* included in the JS translations list $versionJavascript = CM_Model_Language::getVersionJavascript(); $request = new CM_Http_Request_Get($render->getUrlResource('library-js', "translations/{$versionJavascript}.js")); $response = CM_Http_Response_Resource_Javascript_Library::createFromRequest($request, $site, $this->getServiceManager()); $response->process(); $this->assertNotContains('Hello World', $response->getContent()); // Request JS-enabling of language key via RPC call $body = CM_Params::jsonEncode(['method' => 'CM_Model_Language.requestTranslationJs', 'params' => ['Hello World']]); $request = new CM_Http_Request_Post('/rpc', null, null, $body); $response = CM_Http_Response_RPC::createFromRequest($request, $site, $this->getServiceManager()); $response->process(); CMTest_TH::reinstantiateModel($languageKey); $this->assertSame(true, $languageKey->getJavascript()); // Check that key *is* included in the JS translations list $versionJavascript = CM_Model_Language::getVersionJavascript(); $request = new CM_Http_Request_Get($render->getUrlResource('library-js', "translations/{$versionJavascript}.js")); $response = CM_Http_Response_Resource_Javascript_Library::createFromRequest($request, $site, $this->getServiceManager()); $response->process(); $this->assertContains('Hello World', $response->getContent()); }
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 testRender() { $time = strtotime('2003-02-01 12:34'); foreach ([['params' => ['time' => $time], 'expected' => '2/1/03'], ['params' => ['time' => $time, 'showTime' => true], 'expected' => CMTest_TH::getVersionICU() < 50 ? '2/1/03 12:34 PM' : '2/1/03, 12:34 PM'], ['params' => ['time' => $time, 'showTime' => true, 'timeZone' => new DateTimeZone('US/Eastern')], 'expected' => CMTest_TH::getVersionICU() < 50 ? '2/1/03 7:34 AM' : '2/1/03, 7:34 AM'], ['params' => ['time' => $time, 'showTime' => true, 'timeZone' => 'US/Eastern'], 'expected' => CMTest_TH::getVersionICU() < 50 ? '2/1/03 7:34 AM' : '2/1/03, 7:34 AM'], ['params' => ['time' => $time, 'showWeekday' => true], 'expected' => 'Sat 2/1/03']] as $testData) { $this->_assertSame($testData['expected'], $testData['params']); } }
public function testSetValueByEnvironment() { $location = CMTest_TH::createLocation(); $locationCity = $location->get(CM_Model_Location::LEVEL_CITY); $environment = new CM_Frontend_Environment(); $environment->setLocation(null); $field = new CM_FormField_Location(); $field->setValueByEnvironment($environment); $this->assertNull($field->getValue()); $environment->setLocation($location->get(CM_Model_Location::LEVEL_COUNTRY)); $field = new CM_FormField_Location(['levelMin' => CM_Model_Location::LEVEL_CITY]); $field->setValueByEnvironment($environment); $this->assertNull($field->getValue()); $environment->setLocation($location); $field = new CM_FormField_Location(['levelMin' => CM_Model_Location::LEVEL_CITY, 'levelMax' => CM_Model_Location::LEVEL_CITY]); $field->setValueByEnvironment($environment); $value = $field->getValue(); /** @var CM_Model_Location $locationValue */ $locationValue = $value[0]; $this->assertSame($locationCity->getId(), $locationValue->getId()); $this->assertSame($locationCity->getLevel(), $locationValue->getLevel()); $environment->setLocation($locationCity); $field = new CM_FormField_Location(['levelMin' => CM_Model_Location::LEVEL_CITY, 'levelMax' => CM_Model_Location::LEVEL_CITY]); $field->setValueByEnvironment($environment); $value = $field->getValue(); /** @var CM_Model_Location $locationValue */ $locationValue = $value[0]; $this->assertSame($locationCity->getId(), $locationValue->getId()); $this->assertSame($locationCity->getLevel(), $locationValue->getLevel()); }
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 testGetRecordContext() { $user = CMTest_TH::createUser(); $httpRequest = CM_Http_Request_Abstract::factory('post', '/foo?bar=1&baz=quux&viewInfoList=fooBar', ['bar' => 'baz', 'host' => 'foo.bar:8080'], ['http_referer' => 'http://bar/baz', 'http_user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_10)', 'foo' => 'quux'], '{"foo" : "bar", "quux" : "baz"}'); $clientId = $httpRequest->getClientId(); $computerInfo = new CM_Log_Context_ComputerInfo('www.example.com', 'v7.0.1'); $exception = new CM_Exception_Invalid('Bad', null, ['foo' => 'bar']); $context = new CM_Log_Context(); $context->setExtra(['bar' => 'baz', 'baz' => 'quux']); $context->setUser($user); $context->setException($exception); $context->setComputerInfo($computerInfo); $context->setHttpRequest($httpRequest); $contextFormatter = new CM_Log_ContextFormatter_Cargomedia('appName'); $formattedContext = $contextFormatter->formatContext($context); $this->assertSame('www.example.com', $formattedContext['computerInfo']['fqdn']); $this->assertSame('v7.0.1', $formattedContext['computerInfo']['phpVersion']); $this->assertSame('/foo?bar=1&baz=quux&viewInfoList=fooBar', $formattedContext['httpRequest']['uri']); $this->assertSame(join("\n", ['{', ' "bar": "1",', ' "baz": "quux",', ' "foo": "bar",', ' "quux": "baz"', '}']), $formattedContext['httpRequest']['query']); $this->assertSame('POST', $formattedContext['httpRequest']['method']); $this->assertSame('http://bar/baz', $formattedContext['httpRequest']['referer']); $this->assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_10)', $formattedContext['httpRequest']['useragent']); $this->assertSame('foo.bar', $formattedContext['httpRequest']['hostname']); $this->assertSame(['id' => $user->getId(), 'displayName' => 'user' . $user->getId()], $formattedContext['appName']['user']); $this->assertSame($clientId, $formattedContext['appName']['client']['id']); $this->assertSame('baz', $formattedContext['appName']['bar']); $this->assertSame('quux', $formattedContext['appName']['baz']); $this->assertSame('CM_Exception_Invalid', $formattedContext['exception']['type']); $this->assertSame('Bad', $formattedContext['exception']['message']); $this->assertArrayHasKey('stack', $formattedContext['exception']); $this->assertInternalType('string', $formattedContext['exception']['stack']); $this->assertSame(['foo' => "'bar'"], $formattedContext['exception']['metaInfo']); $this->assertRegExp('/library\\/CM\\/Log\\/ContextFormatter\\/CargomediaTest\\.php\\(\\d+\\)/', $formattedContext['exception']['stack']); }
public function testAggregate() { $paging = $this->getMockBuilder('CM_Paging_Log_Abstract')->disableOriginalConstructor()->setMethods(array('getType'))->getMockForAbstractClass(); $paging->expects($this->any())->method('getType')->will($this->returnValue(1)); /** @var CM_Paging_Log_Abstract $paging */ $paging->__construct(); CMTest_TH::callProtectedMethod($paging, '_add', ['haha']); CMTest_TH::callProtectedMethod($paging, '_add', ['huhu']); CMTest_TH::timeDaysForward(1); CMTest_TH::timeDaysForward(1); CMTest_TH::callProtectedMethod($paging, '_add', ['haha']); CMTest_TH::callProtectedMethod($paging, '_add', ['haha', array('id' => 123123, 'ip' => 1234123)]); CMTest_TH::timeDaysForward(1); CMTest_TH::callProtectedMethod($paging, '_add', ['ha']); CMTest_TH::callProtectedMethod($paging, '_add', ['ha']); CMTest_TH::callProtectedMethod($paging, '_add', ['ha']); $paging->__construct(true, 2 * 86400); $this->assertEquals(2, $paging->getCount()); $warning1 = $paging->getItem(0); $warning2 = $paging->getItem(1); $this->assertEquals(3, $warning1['count']); $this->assertEquals(2, $warning2['count']); $this->assertEquals('haha', $warning2['msg']); $this->assertEquals('ha', $warning1['msg']); }
public function testGetLabel_typeNotConfigured() { $actor = CMTest_TH::createUser(); $typeEmail = mt_rand(); $action = new CM_Action_Email(CM_Action_Abstract::VIEW, $actor, $typeEmail); $this->assertSame('Email View ' . $typeEmail, $action->getLabel()); }
public function testFindByMediaId() { $this->assertNull(CM_Model_StreamChannelArchive_Media::findByMediaId('foo')); /** @var CM_Model_StreamChannel_Media $streamChannel */ $streamChannel = $streamChannel = CMTest_TH::createStreamChannel(null, null, 'foo'); $this->assertEquals($streamChannel, CM_Model_StreamChannel_Media::findByMediaId($streamChannel->getMediaId())); }
public function testTrackPageView() { $viewer = CMTest_TH::createUser(); $environment = new CM_Frontend_Environment(CM_Site_Abstract::factory(), $viewer); $client = new CMService_AdWords_Client(); $pushConversion = new ReflectionMethod($client, '_pushConversion'); $pushConversion->setAccessible(true); $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}}')); $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":789}')); $this->assertSame('', $client->getJs()); $this->assertSame(<<<EOD <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script> EOD , $client->getHtml($environment)); $client->trackPageView($environment, '/'); $this->assertSame(<<<EOD window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789}); EOD , $client->getJs()); $this->assertSame(<<<EOD <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script><script type="text/javascript"> /* <![CDATA[ */ window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789}); //]]> </script> EOD , $client->getHtml($environment)); }
public function setUp() { $smarty = new Smarty(); $this->_render = new CM_Frontend_Render(); $this->_template = $smarty->createTemplate('string:'); $this->_template->assignGlobal('render', $this->_render); $this->_location = CMTest_TH::createLocation(); }
public function test_Get() { $user = CMTest_TH::createUser(); $user->getRoles()->add(self::ROLE_A, 2000); $stamps = CM_Db_Db::select('cm_role', array('startStamp', 'expirationStamp'), array('userId' => $user->getId()))->fetch(); $this->assertEquals($stamps['startStamp'], $user->getRoles()->getStartStamp(self::ROLE_A)); $this->assertEquals($stamps['expirationStamp'], $user->getRoles()->getExpirationStamp(self::ROLE_A)); }
public function test_encodeRecord() { /** @var CM_Log_Handler_Fluentd|\Mocka\AbstractClassTrait $mock */ $mock = $this->mockClass('CM_Log_Handler_Fluentd')->newInstanceWithoutConstructor(); $this->assertSame([], CMTest_TH::callProtectedMethod($mock, '_encodeRecord', [[]])); $record = ['foo' => ['id' => 123, 'bar' => (object) ['baz'], 'baz' => new DateTime('01-01-2001'), 'bax' => new CM_Model_Mock_Fluentd()]]; $this->assertSame(['foo' => ['id' => '123', 'bar' => ['class' => 'stdClass'], 'baz' => '2001-01-01T00:00:00+00:00', 'bax' => ['class' => 'CM_Model_Mock_Fluentd', 'id' => '42']]], CMTest_TH::callProtectedMethod($mock, '_encodeRecord', [$record])); }
public function bootstrap() { $this->generateInternalConfig(); CMTest_TH::init(); $comparatorFactory = SebastianBergmann\Comparator\Factory::getInstance(); $comparatorFactory->register(new CMTest_Comparator_Comparable()); $comparatorFactory->register(new CMTest_Comparator_BetterArrayComparator()); }
public function testGetCacheKey() { 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(); $method = CMTest_TH::getProtectedMethod('CM_Model_StorageAdapter_Cache', '_getCacheKey'); $this->assertSame('CM_Model_StorageAdapter_Cache_type:1_id:a:1:{s:2:"id";i:2;}', $method->invoke($adapter, 1, array('id' => 2))); $this->assertSame('CM_Model_StorageAdapter_Cache_type:2_id:a:1:{s:2:"id";i:3;}', $method->invoke($adapter, 2, array('id' => 3))); }
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 testInvalidatedModel() { CM_ModelAsset_User_Preferences::setDefault('test', 'foo', false, true); CM_ModelAsset_User_Preferences::setDefault('test', 'bar', true, true); $user = CMTest_TH::createUser(); $user->_change(); $user->getPreferences()->getAll(); $user->getLatestActivity(); }
public function testDeleteOlder() { $file = CM_File_UserContent_Temp::create('foo.txt', 'bar'); $this->assertTrue($file->exists()); CM_File_UserContent_Temp::deleteOlder(100); $this->assertTrue($file->exists()); CMTest_TH::timeForward(1000); CM_File_UserContent_Temp::deleteOlder(100); $this->assertFalse($file->exists()); }
public function testOnSubscribe() { $user = CMTest_TH::createUser(); /** @var CM_Model_StreamChannel_Message_User $channel */ $channel = CM_Model_StreamChannel_Message_User::createStatic(['key' => CM_Model_StreamChannel_Message_User::getKeyByUser($user), 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()]); $this->assertSame(false, $user->getOnline()); $subscribe = CMTest_TH::createStreamSubscribe($user, $channel); CMTest_TH::reinstantiateModel($user); $this->assertSame(true, $user->getOnline()); }
public function testGetLanguageByBrowser() { $defaultLanguage = CMTest_TH::createLanguage('en'); $browserLanguage = CMTest_TH::createLanguage('de'); $this->assertEquals(CM_Model_Language::findDefault(), $defaultLanguage); $request = $this->_prepareRequest('/', array('Accept-Language' => 'de')); $this->assertEquals($request->getLanguage(), $browserLanguage); $request = $this->_prepareRequest('/', array('Accept-Language' => 'pl')); $this->assertEquals($request->getLanguage(), $defaultLanguage); }
public function testProcessLanguageRedirect() { CMTest_TH::createLanguage('en'); $response = CMTest_TH::createResponsePageEmbed('/en/mock7'); $response->process(); $this->assertNull($response->getRedirectUrl()); $response = CMTest_TH::createResponsePageEmbed('/en/mock7', null, CMTest_TH::createUser()); $response->process(); $this->assertSame($response->getSite()->getUrl() . '/mock7', $response->getRedirectUrl()); }
public function testDeleteExpired() { CMTest_TH::timeInit(); $runtime = new CM_Cache_Storage_Runtime(); $runtime->set('foo', true); $this->assertTrue($runtime->get('foo')); CMTest_TH::timeForward(5); $runtime->set('bar', true); $this->assertFalse($runtime->get('foo')); }
public function testIsInt() { $schema = new CM_Model_Schema_Definition(array()); $_isInt = CMTest_TH::getProtectedMethod('CM_Model_Schema_Definition', '_isInt'); $this->assertTrue($_isInt->invoke($schema, 1)); $this->assertTrue($_isInt->invoke($schema, '1')); $this->assertFalse($_isInt->invoke($schema, 1.2)); $this->assertFalse($_isInt->invoke($schema, '1.0')); $this->assertFalse($_isInt->invoke($schema, '4E2')); $this->assertFalse($_isInt->invoke($schema, 400.0)); }
public function testPaging() { $user = CMTest_TH::createUser(); $streamChannel = CMTest_TH::createStreamChannel(); CMTest_TH::createStreamSubscribe($user, $streamChannel); $streams = new CM_Paging_StreamSubscribe_User($user); $this->assertEquals(1, $streams->getCount()); $user->delete(); $streams = new CM_Paging_StreamSubscribe_User($user); $this->assertEquals(0, $streams->getCount()); }
public function testExtractTraceRow() { $trace = array(array('file' => 'test.php', 'line' => 18, 'function' => 'foo', 'args' => array()), array('file' => 'test.php', 'line' => 26, 'function' => 'bar', 'class' => 'Foo', 'type' => '->', 'args' => array()), array('file' => 'test.php(28) : eval()\'d code', 'line' => 1, 'function' => '{closure}', 'args' => array()), array('file' => 'test.php', 'line' => 28, 'function' => 'eval')); $expected = array(array('code' => 'foo()', 'file' => 'test.php', 'line' => 18), array('code' => 'Foo->bar()', 'file' => 'test.php', 'line' => 26), array('code' => '{closure}()', 'file' => 'test.php(28) : eval()\'d code', 'line' => 1), array('code' => 'eval', 'file' => 'test.php', 'line' => 28)); $exception = $this->getMockBuilder('Exception')->setMethods(array('getTrace'))->getMockForAbstractClass(); $exception->expects($this->any())->method('getTrace')->will($this->returnValue($trace)); $method = CMTest_TH::getProtectedMethod('CM_ExceptionHandling_SerializableException', '_extractTraceRow'); foreach ($trace as $key => $traceRow) { $this->assertSame($expected[$key], $method->invoke(null, $traceRow)); } }
public function testJsonSerializable() { $user = CMTest_TH::createUser(); $id = CM_Model_Entity_Mock::createStatic(array('userId' => $user->getId(), 'foo' => 'boo')); $mock = $this->getMockBuilder('CM_Model_Entity_Mock')->setConstructorArgs(array($id->getId()))->setMethods(array('getType'))->getMock(); $mock->expects($this->any())->method('getType')->will($this->returnValue(null)); /** @var $mock CM_Model_Entity_Abstract */ $data = $mock->jsonSerialize(); $this->assertArrayHasKey('path', $data); $this->assertNull($data['path']); }
public function setUp() { $smarty = new Smarty(); $this->_render = new CM_Frontend_Render(); $this->_template = $smarty->createTemplate('string:'); $this->_template->assignGlobal('render', $this->_render); $language = CMTest_TH::createLanguage(); $language->setTranslation('.date.period.years', '{$count} years', ['count']); $language->setTranslation('.date.period.hour', '1 hour'); $language->setTranslation('.date.period.day', '1 day'); }
public function testContains() { $user = CMTest_TH::createUser(); $this->assertFalse((new CM_Paging_User_Online())->contains($user)); CM_Cache_Local::getInstance()->flush(); $user->setOnline(true); $this->assertTrue((new CM_Paging_User_Online())->contains($user)); CM_Cache_Local::getInstance()->flush(); $user->setOnline(false); $this->assertFalse((new CM_Paging_User_Online())->contains($user)); }
public function testLoadPageRedirectLanguage() { $site = CM_Site_Abstract::factory(); CMTest_TH::createLanguage('en'); $viewer = CMTest_TH::createUser(); $environment = new CM_Frontend_Environment(null, $viewer); $component = new CM_Page_View_Ajax_Test_Mock(); $response = $this->getResponseAjax($component, 'loadPage', ['path' => '/en' . CM_Page_View_Ajax_Test_Mock::getPath()], $environment); $this->assertViewResponseSuccess($response); $responseDecoded = CM_Params::jsonDecode($response->getContent()); $this->assertSame($site->getUrl() . CM_Page_View_Ajax_Test_Mock::getPath(), $responseDecoded['success']['data']['url']); }