public function test_renderContent_returns_twig_parsed_content() { $campaign2 = Campaign::create(['name' => 'Test split2', 'file_name' => 'test-split2.htm', 'file_type' => 'partial', 'start_at' => Carbon::today(), 'end_at' => Carbon::tomorrow(), 'version_a_content' => 'Foo', 'version_b_content' => 'Bar']); $campaign1 = Campaign::create(['name' => 'Test split1', 'file_name' => 'test-split1.htm', 'file_type' => 'partial', 'start_at' => Carbon::today(), 'end_at' => Carbon::tomorrow(), 'version_a_content' => 'Hello {{ split(' . $campaign2->id . ') }}', 'version_b_content' => 'World {{ split(' . $campaign2->id . ') }}']); $content = CmsHelper::renderContent($campaign1->id); $this->assertTrue(in_array($content, ['Hello Foo', 'Hello Bar', 'World Foo', 'World Bar'])); }
/** * Fetch the content of a split test * * @param mixed $id The campaign ID or slug * @return string */ public static function renderContent($id) { if ($campaign = Campaign::find($id)) { $twig = App::make('Cms\\Classes\\Controller')->getTwig(); $twig->setLoader(new TwigStringLoader()); return $twig->render($campaign->getTemplate(), ['splitSuccess' => 'data-splitter-id=' . $id]); } }
/** * Start active campaigns and stop inactive ones */ public function fire() { $active = Campaign::isActive()->isNotRunning()->get(); $inactive = Campaign::isNotActive()->isRunning()->get(); foreach ($active as $campaign) { CampaignManager::start($campaign); } foreach ($inactive as $campaign) { CampaignManager::end($campaign); } }
public function test_isActive_and_isNotActive_scopes() { // Active 1, defined start date $active1 = $this->mockCampaign(); $active1->start_at = Carbon::yesterday(); $active1->save(); // Inactive 1, expired end date $inactive1 = $this->mockCampaign(); $inactive1->start_at = Carbon::yesterday()->subDays(1); $inactive1->end_at = Carbon::yesterday(); $inactive1->save(); // Inactive 2, future start date $inactive2 = $this->mockCampaign(); $inactive2->start_at = Carbon::tomorrow(); $inactive2->end_at = Carbon::tomorrow()->addDays(1); $inactive2->save(); // Query the active campaigns $query = Campaign::isActive()->get(); $this->assertEquals(1, $query->count()); $this->assertEquals($active1->id, $query->first()->id); // Query the inactive campaigns $query = Campaign::isNotActive()->get(); $this->assertEquals(2, $query->count()); }
/** * Record a campaign conversion * * @return void */ public function onSuccess() { if ($campaign = Campaign::find(input('id'))) { $campaign->recordConversion(); } }