<commit_before><?php

class BlogArchiveWidgetTest extends SapphireTest
{
    protected static $fixture_file = 'BlogArchiveWidgetTest.yml';

    public function setUp()
    {
        if (!class_exists('Widget')) {
            self::$fixture_file = null;
            parent::setUp();
            $this->markTestSkipped('Test requires silverstripe/widgets to be installed.');
        }

        SS_Datetime::set_mock_now('2017-09-20 12:00:00');

        parent::setUp();
    }

    public function tearDown()
    {
        parent::tearDown();

        SS_Datetime::clear_mock_now();
    }

    public function testArchiveMonthlyFromStage()
    {
        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf('SS_List', $archive);
        $this->assertCount(3, $archive);
        $this->assertDOSContains(array(
            array('Title' => 'August 2017'),
            array('Title' => 'September 2017'),
            array('Title' => 'May 2015'),
        ), $archive);
    }

    public function testArchiveMonthlyFromLive()
    {
        $original = Versioned::current_stage();

        $this->objFromFixture('BlogPost', 'post-b')->doPublish();
        Versioned::reading_stage('Live');

        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertCount(1, $archive);
        $this->assertDOSContains(array(
            array('Title' => 'August 2017'),
        ), $archive);

        Versioned::reading_stage($original);
    }

    public function testArchiveYearly()
    {
        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf('SS_List', $archive);
        $this->assertCount(2, $archive);
        $this->assertDOSContains(array(
            array('Title' => '2017'),
            array('Title' => '2015'),
        ), $archive);
    }

    public function testArchiveMonthlyWithNewPostsAdded()
    {
        $original = Versioned::current_stage();
        Versioned::reading_stage('Stage');

        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertCount(3, $archive, 'Three months are shown in the blog archive list from fixtures');

        SS_Datetime::set_mock_now('2018-01-01 12:00:00');

        $newPost = new BlogPost;
        $newPost->ParentID = $this->objFromFixture('Blog', 'my-blog')->ID;
        $newPost->Title = 'My new blog post';
        $newPost->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier
        $newPost->write();

        $archive = $widget->getArchive();

        $this->assertCount(4, $archive, 'Four months are shown in the blog archive list after new post added');

        Versioned::reading_stage($original);
    }
}<commit_msg>TEST Fix regression in tests from new Versioned exceptions<commit_after><?php

class BlogArchiveWidgetTest extends SapphireTest
{
    protected static $fixture_file = 'BlogArchiveWidgetTest.yml';

    public function setUp()
    {
        if (!class_exists('Widget')) {
            self::$fixture_file = null;
            parent::setUp();
            $this->markTestSkipped('Test requires silverstripe/widgets to be installed.');
        }

        SS_Datetime::set_mock_now('2017-09-20 12:00:00');

        parent::setUp();
    }

    public function tearDown()
    {
        parent::tearDown();

        SS_Datetime::clear_mock_now();
    }

    public function testArchiveMonthlyFromStage()
    {
        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf('SS_List', $archive);
        $this->assertCount(3, $archive);
        $this->assertDOSContains(array(
            array('Title' => 'August 2017'),
            array('Title' => 'September 2017'),
            array('Title' => 'May 2015'),
        ), $archive);
    }

    public function testArchiveMonthlyFromLive()
    {
        $original = Versioned::current_stage();

        $this->objFromFixture('BlogPost', 'post-b')->doPublish();
        Versioned::reading_stage('Live');

        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertCount(1, $archive);
        $this->assertDOSContains(array(
            array('Title' => 'August 2017'),
        ), $archive);

        if ($original) {
            Versioned::reading_stage($original);
        }
    }

    public function testArchiveYearly()
    {
        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf('SS_List', $archive);
        $this->assertCount(2, $archive);
        $this->assertDOSContains(array(
            array('Title' => '2017'),
            array('Title' => '2015'),
        ), $archive);
    }

    public function testArchiveMonthlyWithNewPostsAdded()
    {
        $original = Versioned::current_stage();
        Versioned::reading_stage('Stage');

        $widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertCount(3, $archive, 'Three months are shown in the blog archive list from fixtures');

        SS_Datetime::set_mock_now('2018-01-01 12:00:00');

        $newPost = new BlogPost;
        $newPost->ParentID = $this->objFromFixture('Blog', 'my-blog')->ID;
        $newPost->Title = 'My new blog post';
        $newPost->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier
        $newPost->write();

        $archive = $widget->getArchive();

        $this->assertCount(4, $archive, 'Four months are shown in the blog archive list after new post added');

        if ($original) {
            Versioned::reading_stage($original);
        }
    }
}
{'fraction_non_alphanumeric': 0.1511800627166199, 'fraction_numerical': 0.023436210595807888, 'mean_word_length': 2.733826247689464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, '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': '6425454', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1712, 'n_words': 334}