<commit_before><?php


namespace Xibo\Tests\integration;


use Jenssegers\Date\Date;
use Xibo\Entity\Display;
use Xibo\Helper\Random;
use Xibo\OAuth2\Client\Entity\XiboDaypart;
use Xibo\Tests\Helper\DisplayHelperTrait;
use Xibo\Tests\Helper\LayoutHelperTrait;
use Xibo\Tests\LocalWebTestCase;

class ScheduleDayPartTest extends LocalWebTestCase
{
    use LayoutHelperTrait;
    use DisplayHelperTrait;

    /** @var \Xibo\OAuth2\Client\Entity\XiboLayout */
    protected $layout;

    /** @var \Xibo\OAuth2\Client\Entity\XiboDisplay */
    protected $display;

    /** @var \Xibo\OAuth2\Client\Entity\XiboSchedule */
    protected $event;

    /** @var \Xibo\OAuth2\Client\Entity\XiboDaypart */
    protected $dayPart;

    // <editor-fold desc="Init">
    public function setup()
    {
        parent::setup();

        $this->getLogger()->debug('Setup test for ' . get_class() .' Test');

        // Create a Layout
        $this->layout = $this->createLayout();

        $layout = $this->getDraft($this->layout);

        $response = $this->getEntityProvider()->post('/playlist/widget/text/' . $layout->regions[0]->regionPlaylist->playlistId);
        $response = $this->getEntityProvider()->put('/playlist/widget/' . $response['widgetId'], [
            'text' => 'Widget A',
            'duration' => 100,
            'useDuration' => 1
        ]);

        // Check us in again
        $this->layout = $this->publish($this->layout);

        // Build the layout
        $this->buildLayout($this->layout);

        // Create a Display
        $this->display = $this->createDisplay();

        $this->displaySetStatus($this->display, Display::$STATUS_DONE);
        $this->displaySetLicensed($this->display);

        // Make sure the Layout Status is as we expect
        $this->assertTrue($this->layoutStatusEquals($this->layout, 1), 'Layout Status isnt as expected');

        // Make sure our Display is already DONE
        $this->assertTrue($this->displayStatusEquals($this->display, Display::$STATUS_DONE), 'Display Status isnt as expected');

        // Create a Day Part
        // calculate a few hours either side of now
        $now = Date::now()->startOfHour()->subHour();

        $this->dayPart = (new XiboDaypart($this->getEntityProvider()))->create(
            Random::generateString(5),
            '',
            $now->format('H:i'),
            $now->copy()->addHours(5)->format('H:i')
        );

        $this->getLogger()->debug('Finished Setup');
    }

    public function tearDown()
    {
        $this->getLogger()->debug('Tear Down');

        parent::tearDown();

        // Delete the Layout we've been working with
        $this->deleteLayout($this->layout);

        // Delete the Display
        $this->deleteDisplay($this->display);

        // Delete the DayPart
        $this->dayPart->delete();
    }
    // </editor-fold>

    public function testSchedule()
    {
        // Our CMS is in GMT
        // Create a schedule one hours time in my player timezone
        $date = Date::now()->setTime(0,0,0);

        $this->getLogger()->debug('Event start will be at: ' . $date->format('Y-m-d H:i:s'));

        $response = $this->client->post('/schedule', [
            'fromDt' => $date->format('Y-m-d H:i:s'),
            'dayPartId' => $this->dayPart->dayPartId,
            'eventTypeId' => 1,
            'campaignId' => $this->layout->campaignId,
            'displayGroupIds' => [$this->display->displayGroupId],
            'displayOrder' => 1,
            'isPriority' => 0,
            'scheduleRecurrenceType' => null,<commit_msg>Fix day part test - this test did not ever succeed in the 5 hours up to midnight (it was nothing to do with the linked issue change). xibosignage/xibo#2102<commit_after><?php


namespace Xibo\Tests\integration;


use Jenssegers\Date\Date;
use Xibo\Entity\Display;
use Xibo\Helper\Random;
use Xibo\OAuth2\Client\Entity\XiboDaypart;
use Xibo\Tests\Helper\DisplayHelperTrait;
use Xibo\Tests\Helper\LayoutHelperTrait;
use Xibo\Tests\LocalWebTestCase;

class ScheduleDayPartTest extends LocalWebTestCase
{
    use LayoutHelperTrait;
    use DisplayHelperTrait;

    /** @var \Xibo\OAuth2\Client\Entity\XiboLayout */
    protected $layout;

    /** @var \Xibo\OAuth2\Client\Entity\XiboDisplay */
    protected $display;

    /** @var \Xibo\OAuth2\Client\Entity\XiboSchedule */
    protected $event;

    /** @var \Xibo\OAuth2\Client\Entity\XiboDaypart */
    protected $dayPart;

    // <editor-fold desc="Init">
    public function setup()
    {
        parent::setup();

        $this->getLogger()->debug('Setup test for ' . get_class() .' Test');

        // Create a Layout
        $this->layout = $this->createLayout();

        $layout = $this->getDraft($this->layout);

        $response = $this->getEntityProvider()->post('/playlist/widget/text/' . $layout->regions[0]->regionPlaylist->playlistId);
        $response = $this->getEntityProvider()->put('/playlist/widget/' . $response['widgetId'], [
            'text' => 'Widget A',
            'duration' => 100,
            'useDuration' => 1
        ]);

        // Check us in again
        $this->layout = $this->publish($this->layout);

        // Build the layout
        $this->buildLayout($this->layout);

        // Create a Display
        $this->display = $this->createDisplay();

        $this->displaySetStatus($this->display, Display::$STATUS_DONE);
        $this->displaySetLicensed($this->display);

        // Make sure the Layout Status is as we expect
        $this->assertTrue($this->layoutStatusEquals($this->layout, 1), 'Layout Status isnt as expected');

        // Make sure our Display is already DONE
        $this->assertTrue($this->displayStatusEquals($this->display, Display::$STATUS_DONE), 'Display Status isnt as expected');

        // Create a Day Part
        // calculate a few hours either side of now
        // must be tomorrow
        // must not cross the day boundary
        $now = Date::now()->startOfDay()->addDay()->addHour();

        $this->dayPart = (new XiboDaypart($this->getEntityProvider()))->create(
            Random::generateString(5),
            '',
            $now->format('H:i'),
            $now->copy()->addHours(5)->format('H:i')
        );

        $this->getLogger()->debug('Finished Setup');
    }

    public function tearDown()
    {
        $this->getLogger()->debug('Tear Down');

        parent::tearDown();

        // Delete the Layout we've been working with
        $this->deleteLayout($this->layout);

        // Delete the Display
        $this->deleteDisplay($this->display);

        // Delete the DayPart
        $this->dayPart->delete();
    }
    // </editor-fold>

    public function testSchedule()
    {
        // Our CMS is in GMT
        // Create a schedule one hours time in my player timezone
        $date = Date::now()->addDay()->setTime(0,0,0);

        $this->getLogger()->debug('Event start will be at: ' . $date->format('Y-m-d H:i:s'));

        $response = $this->client->post('/schedule', [
            'fromDt' => $date->format('Y-m-d H:i:s'),
            'dayPartId' => $this->dayPart->dayPartId,
            'eventTypeId' => 1,
            'campaignId' => $this->layout->campaignId,
            'displayGroupIds' => [$this->display->displayGroupId],
            'displayOrder' => 1,
            'isPriority' => 0,
            'scheduleRecurrenceType' => null,
{'fraction_non_alphanumeric': 0.1611681990265008, 'fraction_numerical': 0.005813953488372093, 'mean_word_length': 2.46463700234192, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 155, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6190094', 'n_tokens_mistral': 2257, 'n_tokens_neox': 2146, 'n_words': 457}