Beispiel #1
0
 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());
 }
Beispiel #2
0
    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));
    }
Beispiel #3
0
 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());
 }
Beispiel #4
0
 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']);
 }
Beispiel #5
0
 public function testAddGet()
 {
     $client = $this->getServiceManager()->getMongoDb();
     $encoder = new CM_Log_Encoder_MongoDb();
     $handler = new CM_Log_Handler_MongoDb($client, $encoder, CM_Paging_Log::COLLECTION_NAME);
     $user = CMTest_TH::createUser();
     $context = new CM_Log_Context();
     $context->setExtra(['bar' => 'quux']);
     $context->setUser($user);
     $record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context);
     $record2 = new CM_Log_Record(CM_Log_Logger::INFO, 'baz', new CM_Log_Context());
     $handler->handleRecord($record1);
     $handler->handleRecord($record2);
     $paging = new CM_Paging_Log([CM_Log_Logger::DEBUG, CM_Log_Logger::INFO]);
     $items = $paging->getItems();
     $this->assertSame(2, count($items));
     $this->assertSame('baz', $items[0]['message']);
     $this->assertSame(CM_Log_Logger::INFO, $items[0]['level']);
     $this->assertSame('foo', $items[1]['message']);
     $this->assertSame(CM_Log_Logger::DEBUG, $items[1]['level']);
     $this->assertSame($user->getDisplayName(), $items[1]['context']['user']['name']);
     $this->assertSame(['bar' => 'quux', 'type' => CM_Log_Handler_MongoDb::DEFAULT_TYPE], $items[1]['context']['extra']);
     $age = 86400;
     CMTest_TH::timeForward($age);
     CMTest_TH::timeForward($age);
     $record3 = new CM_Log_Record(CM_Log_Logger::CRITICAL, 'bar', new CM_Log_Context());
     $handler->handleRecord($record3);
     $paging2 = new CM_Paging_Log([CM_Log_Logger::CRITICAL], null, false, $age + 1);
     $items = $paging2->getItems();
     $this->assertSame(1, count($items));
     $this->assertSame('bar', $items[0]['message']);
     $this->assertSame(CM_Log_Logger::CRITICAL, $items[0]['level']);
 }
Beispiel #6
0
 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));
 }
Beispiel #7
0
 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();
 }
Beispiel #8
0
 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());
 }
Beispiel #9
0
 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());
 }
Beispiel #10
0
 public function testGetUser()
 {
     $user = CMTest_TH::createUser();
     $streamChannel = CMTest_TH::createStreamChannel();
     CMTest_TH::createStreamPublish($user, $streamChannel);
     $archive = CMTest_TH::createStreamChannelVideoArchive($streamChannel);
     $this->assertEquals($user, $archive->getUser());
     $user->delete();
     $this->assertNull($archive->getUser());
 }
Beispiel #11
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());
 }
Beispiel #12
0
 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']);
 }
Beispiel #13
0
 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));
 }
Beispiel #14
0
 public function testConstructor()
 {
     $user = CMTest_TH::createUser();
     $metaInfo = array('meta' => 'foo', 'user' => $user);
     $severity = CM_Exception::ERROR;
     $exception = new CM_Exception('foo', $severity, $metaInfo, ['messagePublic' => new CM_I18n_Phrase('foo {$bar}', ['bar' => 'foo'])]);
     $render = new CM_Frontend_Render();
     $this->assertSame('foo', $exception->getMessage());
     $this->assertSame('foo foo', $exception->getMessagePublic($render));
     $this->assertSame($severity, $exception->getSeverity());
     $this->assertSame($metaInfo, $exception->getMetaInfo());
 }
Beispiel #15
0
 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']);
 }
Beispiel #16
0
 /**
  * @param string|null           $email
  * @param CM_Site_Abstract|null $site
  * @return CM_Model_User|\Mocka\AbstractClassTrait
  */
 public function getMockUser($email = null, CM_Site_Abstract $site = null)
 {
     $email = null === $email ? '*****@*****.**' : $email;
     $site = null === $site ? $this->getMockSite() : $site;
     $mockBuilder = $this->getMockBuilder('CM_Model_User');
     $mockBuilder->setMethods(['getEmail', 'getSite']);
     $mockBuilder->setConstructorArgs([CMTest_TH::createUser()->getId()]);
     $userMock = $mockBuilder->getMock();
     $userMock->expects($this->any())->method('getEmail')->will($this->returnValue($email));
     $userMock->expects($this->any())->method('getSite')->will($this->returnValue($site));
     return $userMock;
 }
Beispiel #17
0
 public function testConstructor()
 {
     $user = CMTest_TH::createUser();
     $metaInfo = array('meta' => 'foo', 'user' => $user);
     $options = array('messagePublic' => 'foo {$bar}', 'messagePublicVariables' => array('bar' => 'foo'), 'severity' => CM_Exception::ERROR);
     $exception = new CM_Exception('foo', $metaInfo, $options);
     $render = new CM_Frontend_Render();
     $this->assertSame('foo', $exception->getMessage());
     $this->assertSame('foo foo', $exception->getMessagePublic($render));
     $this->assertSame(CM_Exception::ERROR, $exception->getSeverity());
     $this->assertSame($metaInfo, $exception->getMetaInfo());
 }
Beispiel #18
0
 public function testTrackPageViewSetsUser()
 {
     $inspectlet = new CMService_Inspectlet_Client(123);
     $environment = new CM_Frontend_Environment();
     $js = $inspectlet->getJs($environment);
     $this->assertNotContains("__insp.push(['identify'", $js);
     $viewer = CMTest_TH::createUser();
     $viewerId = $viewer->getId();
     $environmentWithViewer = new CM_Frontend_Environment(null, $viewer);
     $inspectlet->trackPageView($environmentWithViewer, '/foo');
     $js = $inspectlet->getJs($environment);
     $this->assertContains("__insp.push(['identify', 'user{$viewerId}']);", $js);
 }
Beispiel #19
0
 public function testAddFromRequest()
 {
     $user = CMTest_TH::createUser();
     $useragentList = new CM_Paging_Useragent_User($user);
     $time = time();
     $this->assertSame([], (new CM_Paging_Useragent_User($user))->getItems());
     $request = new CM_Http_Request_Get('/foo');
     $useragentList->addFromRequest($request);
     $this->assertSame([], (new CM_Paging_Useragent_User($user))->getItems());
     $request = new CM_Http_Request_Get('/foo', ['user-agent' => 'Mozilla']);
     $useragentList->addFromRequest($request);
     $this->assertSame([['useragent' => 'Mozilla', 'createStamp' => $time]], (new CM_Paging_Useragent_User($user))->getItems());
 }
Beispiel #20
0
 public function testPaging()
 {
     $user = CMTest_TH::createUser();
     CMTest_TH::createStreamChannelVideoArchive(null, $user);
     CMTest_TH::createStreamChannelVideoArchive(null, $user);
     CMTest_TH::timeForward(1);
     $streamChannel3 = CMTest_TH::createStreamChannelVideoArchive(null, $user);
     CMTest_TH::createStreamChannelVideoArchive();
     CMTest_TH::createStreamChannelVideoArchive();
     $paging = new CM_Paging_StreamChannelArchiveVideo_User($user);
     $this->assertSame(3, $paging->getCount());
     $this->assertEquals($streamChannel3, $paging->getItem(0));
 }
Beispiel #21
0
 public function testOnRedisMessageSubscribeUser()
 {
     $adapter = new CM_MessageStream_Adapter_SocketRedis([]);
     $user = CMTest_TH::createUser();
     $session = new CM_Session();
     $session->setUser($user);
     $session->write();
     $message = array('type' => 'subscribe', 'data' => array('channel' => 'foo:' . CM_Model_StreamChannel_Message::getTypeStatic(), 'clientKey' => 'bar', 'data' => array('sessionId' => $session->getId())));
     $adapter->onRedisMessage(json_encode($message));
     $streamChannel = CM_Model_StreamChannel_Message::findByKeyAndAdapter('foo', $adapter->getType());
     $streamSubscribe = CM_Model_Stream_Subscribe::findByKeyAndChannel('bar', $streamChannel);
     $this->assertEquals($user, $streamSubscribe->getUser());
 }
Beispiel #22
0
 public function testGetLanguageLoggedUser()
 {
     $user = CMTest_TH::createUser();
     $request = $this->_prepareRequest('/', null, $user);
     // No language at all
     $this->assertSame($request->getLanguage(), null);
     // Getting default language, user has no language
     $defaultLanguage = CMTest_TH::createLanguage();
     $this->assertEquals($request->getLanguage(), $defaultLanguage);
     // Getting user language
     $anotherUserLanguage = CMTest_TH::createLanguage();
     $user->setLanguage($anotherUserLanguage);
     $this->assertEquals($request->getLanguage(), $anotherUserLanguage);
 }
 public function testPaging()
 {
     $usersExpected = array(CMTest_TH::createUser(), CMTest_TH::createUser(), CMTest_TH::createUser());
     $streamChannel = CMTest_TH::createStreamChannel();
     foreach ($usersExpected as $user) {
         CMTest_TH::createStreamSubscribe($user, $streamChannel);
     }
     CMTest_TH::createStreamSubscribe(null, $streamChannel);
     CMTest_TH::createStreamSubscribe(null, $streamChannel);
     $usersActual = new CM_Paging_User_StreamChannelSubscriber($streamChannel);
     $this->assertEquals(3, $usersActual->getCount());
     foreach ($usersExpected as $user) {
         $this->assertContains($user, $usersActual);
     }
 }
Beispiel #24
0
 public function testExecute()
 {
     $user = CMTest_TH::createUser();
     $user->setOnline();
     $userChannel = CM_Model_StreamChannel_Message_User::createStatic(['key' => CM_Model_StreamChannel_Message_User::getKeyByUser($user), 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()]);
     $job = new CM_User_OfflineJob();
     $this->assertSame(true, $user->getOnline());
     $job->run(['user' => $user]);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(true, $user->getOnline());
     $userChannel->delete();
     $job->run(['user' => $user]);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(false, $user->getOnline());
 }
Beispiel #25
0
 public function testRenderTranslated()
 {
     $recipient = CMTest_TH::createUser();
     $mail = new CM_Mail_Welcome($recipient);
     $language = CM_Model_Language::create('Test language', 'foo', true);
     $language->setTranslation('Welcome to {$siteName}!', 'foo');
     list($subject, $html, $text) = $mail->render();
     $nodeList = new CM_Dom_NodeList($html);
     $this->assertContains('foo', $nodeList->getText());
     $nodeLink = $nodeList->find('a');
     $this->assertSame(1, $nodeLink->count());
     $this->assertSame('http://www.default.dev/example', $nodeLink->getAttribute('href'));
     $this->assertSame('Example Page', $nodeLink->getText());
     $this->assertContains('border-style:solid;', $nodeLink->getAttribute('style'));
 }
Beispiel #26
0
 public function testWriting()
 {
     $collection = 'cm_event_log';
     $level = CM_Log_Logger::DEBUG;
     $message = 'foo';
     $ttl = 30;
     $user = CMTest_TH::createUser();
     $httpRequest = CM_Http_Request_Abstract::factory('post', '/foo?bar=1&baz=quux', ['bar' => 'baz'], ['foo' => 'quux'], '{"bar":"2", "quux":"baz"}');
     $clientId = $httpRequest->getClientId();
     $computerInfo = new CM_Log_Context_ComputerInfo('www.example.com', 'v7.0.1');
     $mongoClient = $this->getServiceManager()->getMongoDb();
     $this->assertSame(0, $mongoClient->count($collection));
     $mongoClient->createIndex($collection, ['expireAt' => 1], ['expireAfterSeconds' => 0]);
     $recordContext = new CM_Log_Context();
     $recordContext->setExtra(['bar' => ['baz' => 'quux']]);
     $recordContext->setUser($user);
     $recordContext->setHttpRequest($httpRequest);
     $recordContext->setComputerInfo($computerInfo);
     $record = new CM_Log_Record($level, $message, $recordContext);
     $encoder = $this->mockObject(CM_Log_Encoder_MongoDb::class);
     /** @var CM_Log_Encoder_MongoDb $encoder */
     $handler = new CM_Log_Handler_MongoDb($mongoClient, $encoder, $collection, $ttl, ['w' => 0], $level);
     $this->callProtectedMethod($handler, '_writeRecord', [$record]);
     $this->assertSame(1, $mongoClient->count($collection));
     $savedRecord = $mongoClient->findOne($collection);
     $this->assertSame($level, $savedRecord['level']);
     $this->assertSame($message, $savedRecord['message']);
     /** @var MongoDate $createdAt */
     $createdAt = $savedRecord['createdAt'];
     /** @var MongoDate $expireAt */
     $expireAt = $savedRecord['expireAt'];
     $this->assertInstanceOf('MongoDate', $createdAt);
     $this->assertInstanceOf('MongoDate', $expireAt);
     $this->assertSame($ttl, $expireAt->sec - $createdAt->sec);
     $context = $savedRecord['context'];
     $this->assertSame(['id' => $user->getId(), 'name' => $user->getDisplayName()], $context['user']);
     $this->assertSame('POST', $context['httpRequest']['method']);
     $this->assertSame('/foo?bar=1&baz=quux', $context['httpRequest']['uri']);
     $this->assertSame(['bar' => '2', 'baz' => 'quux', 'quux' => 'baz'], $context['httpRequest']['query']);
     $this->assertSame(['bar' => 'baz'], $context['httpRequest']['headers']);
     $this->assertSame(['foo' => 'quux'], $context['httpRequest']['server']);
     $this->assertSame($clientId, $context['httpRequest']['clientId']);
     $this->assertSame('www.example.com', $context['computerInfo']['fqdn']);
     $this->assertSame('v7.0.1', $context['computerInfo']['phpVersion']);
     $this->assertSame(['bar' => ['baz' => 'quux'], 'type' => CM_Log_Handler_MongoDb::DEFAULT_TYPE], $context['extra']);
     $this->assertSame('{"bar":"2", "quux":"baz"}', $context['httpRequest']['body']);
 }
Beispiel #27
0
 public function testProcessNonexistentUser()
 {
     $user = CMTest_TH::createUser();
     $mail = new CM_Mail_Welcome($user);
     $site = CM_Site_Abstract::factory();
     $headers = array('host' => $site->getHost());
     $render = new CM_Frontend_Render(new CM_Frontend_Environment($site));
     $request = new CM_Http_Request_Get($render->getUrlEmailTracking($mail), $headers);
     $response = new CM_Http_Response_EmailTracking($request, $this->getServiceManager());
     $user->delete();
     try {
         $response->process();
         $this->fail('Expected exception not thrown');
     } catch (CM_Exception_Nonexistent $e) {
         $this->assertSame(CM_Exception::WARN, $e->getSeverity());
     }
 }
Beispiel #28
0
 public function testProcessLanguageNoRedirect()
 {
     $language = CMTest_TH::createLanguage('en');
     $user = CMTest_TH::createUser();
     $response = CMTest_TH::createResponsePage('/en/mock5');
     $response->process();
     $this->assertEquals($language, $response->getRequest()->getLanguageUrl());
     $response = CMTest_TH::createResponsePage('/mock5');
     $response->process();
     $this->assertNull($response->getRequest()->getLanguageUrl());
     $response = CMTest_TH::createResponsePage('/mock5', null, $user);
     $response->process();
     $this->assertNull($response->getRequest()->getLanguageUrl());
     foreach ($response->getHeaders() as $header) {
         $this->assertNotContains('Location:', $header);
     }
 }
Beispiel #29
0
 public function testSetConversionStatic()
 {
     $user1 = CMTest_TH::createUser();
     $user2 = CMTest_TH::createUser();
     CM_Model_Splittest_User::setConversionStatic('foo', $user1);
     $splittest = CM_Model_Splittest_User::create('foo', ['bar']);
     /** @var CM_Model_SplittestVariation $variation */
     $variation = $splittest->getVariations()->getItem(0);
     $splittest->isVariationFixture($user1, 'bar');
     $splittest->isVariationFixture($user2, 'bar');
     $this->assertSame(0, $variation->getConversionCount());
     CM_Model_Splittest_User::setConversionStatic('foo', $user1);
     CMTest_TH::clearCache();
     $this->assertSame(1, $variation->getConversionCount());
     CM_Model_Splittest_User::setConversionStatic('foo', $user2, 2.5);
     CMTest_TH::clearCache();
     $this->assertSame(2, $variation->getConversionCount());
     $this->assertSame(1.75, $variation->getConversionRate());
 }
Beispiel #30
0
 public function testProcessLanguageNoRedirect()
 {
     $language = CMTest_TH::createLanguage('en');
     $site = CM_Site_Abstract::factory();
     $request = new CM_Http_Request_Get('/en/mock5', ['host' => $site->getHost()]);
     $response = CM_Http_Response_Page::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertEquals($language, $response->getRequest()->getLanguageUrl());
     $request = new CM_Http_Request_Get('/mock5', ['host' => $site->getHost()]);
     $response = CM_Http_Response_Page::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertNull($response->getRequest()->getLanguageUrl());
     $viewer = CMTest_TH::createUser();
     $request = new CM_Http_Request_Get('/mock5', ['host' => $site->getHost()], null, $viewer);
     $response = CM_Http_Response_Page::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertNull($response->getRequest()->getLanguageUrl());
     foreach ($response->getHeaders() as $header) {
         $this->assertNotContains('Location:', $header);
     }
 }