def test_references_dx_to_at(self):
     at = create(Builder('page').titled(u'AT'))
     dx = create(Builder('example dx type').titled(u'DX'))
     helpers.set_related_items(dx, at, force_relation_values=True)
     self.assertEquals(
         [at],
         list(get_state(dx).get_references())
     )
    def test_do_not_fail_getting_published_references_if_ref_is_none(self):
        foo = create(
            Builder('page').titled(u'Foo').in_state(EXAMPLE_WF_PUBLISHED))
        bar = create(Builder('page').titled(u'Bar'))
        helpers.set_related_items(bar, foo)
        self.portal._delObject(foo.getId(), suppress_events=True)

        self.assertEquals([], list(get_state(bar).get_published_references()))
 def test_references_dx_to_dx(self):
     foo = create(Builder('example dx type').titled(u'Foo'))
     bar = create(Builder('example dx type').titled(u'Bar'))
     helpers.set_related_items(bar, foo, force_relation_values=True)
     self.assertEquals(
         [foo],
         list(get_state(bar).get_references())
     )
 def test_references_at_to_dx(self):
     dx = create(Builder('example dx type').titled(u'DX'))
     at = create(Builder('page').titled(u'AT'))
     helpers.set_related_items(at, dx)
     self.assertEquals(
         [dx],
         list(get_state(at).get_references())
     )
    def test_do_not_fail_getting_published_references_if_ref_is_none(self):
        foo = create(Builder('page').titled(u'Foo')
                     .in_state(EXAMPLE_WF_PUBLISHED))
        bar = create(Builder('page').titled(u'Bar'))
        helpers.set_related_items(bar, foo)
        self.portal._delObject(foo.getId(), suppress_events=True)

        self.assertEquals(
            [], list(get_state(bar).get_published_references()))
    def test_warning_not_shown_when_referencing_children_without_workflow(self, browser):
        parent = create(Builder('folder').titled(u'Parent'))
        child = create(Builder('file').titled(u'Child').within(parent))
        helpers.set_related_items(parent, child)

        browser.login().visit(parent)
        Workflow().do_transition('publish')
        self.assertItemsEqual(
            [],
            statusmessages.warning_messages(),
        )
    def test_getting_unpublished_references(self):
        foo = create(Builder('page').titled(u'Foo'))
        bar = create(Builder('page').titled(u'Bar'))
        helpers.set_related_items(bar, foo)

        self.assertEquals(
            [foo], list(get_state(bar).get_unpublished_references()))

        self._set_state_of(foo, EXAMPLE_WF_PUBLISHED)
        self.assertEquals(
            [], list(get_state(bar).get_unpublished_references()))
    def test_warning_on_publish_when_references_are_not_published(
            self, browser):
        page = create(Builder('page').titled(u'The Page'))
        other_page = create(Builder('page').titled(u'The Other Page'))
        helpers.set_related_items(page, other_page)

        browser.login().visit(page)
        Workflow().do_transition('publish')
        statusmessages.assert_message(
            'The referenced object <a href="http://nohost/plone'
            '/the-other-page">The Other Page</a> is not yet published.')
    def test_do_not_fail_if_reference_is_none(self, browser):
        page = create(Builder('page').titled(u'The Page'))
        other_page = create(Builder('page').titled(u'The Other Page'))
        helpers.set_related_items(page, other_page)

        self.portal._delObject(other_page.getId(), suppress_events=True)
        transaction.commit()

        browser.login().visit(page)
        Workflow().do_transition('publish')
        statusmessages.assert_no_error_messages()
    def test_getting_published_references(self):
        foo = create(
            Builder('page').titled(u'Foo').in_state(EXAMPLE_WF_PUBLISHED))
        bar = create(Builder('page').titled(u'Bar'))
        helpers.set_related_items(bar, foo)

        self.assertEquals([foo],
                          list(get_state(bar).get_published_references()))

        self._set_state_of(foo, EXAMPLE_WF_INTERNAL)
        self.assertEquals([], list(get_state(bar).get_published_references()))
    def test_warning_shown_when_referencing_children_with_separate_workflow(self, browser):
        parent = create(Builder('folder').titled(u'Parent'))
        child = create(Builder('folder').titled(u'Child').within(parent))
        helpers.set_related_items(parent, child)

        browser.login().visit(parent)
        Workflow().do_transition('publish')
        self.assertItemsEqual(
            ['The referenced object <a href="http://nohost/plone'
             '/parent/child">Child</a> is not yet published.'],
            statusmessages.warning_messages(),
        )
    def test_warning_not_shown_when_referencing_children_without_workflow(
            self, browser):
        parent = create(Builder('folder').titled(u'Parent'))
        child = create(Builder('file').titled(u'Child').within(parent))
        helpers.set_related_items(parent, child)

        browser.login().visit(parent)
        Workflow().do_transition('publish')
        self.assertItemsEqual(
            [],
            statusmessages.warning_messages(),
        )
    def test_do_not_fail_if_reference_is_none(self, browser):
        page = create(Builder('page')
                      .titled(u'The Page'))
        other_page = create(Builder('page')
                            .titled(u'The Other Page'))
        helpers.set_related_items(page, other_page)

        self.portal._delObject(other_page.getId(), suppress_events=True)
        transaction.commit()

        browser.login().visit(page)
        Workflow().do_transition('publish')
        statusmessages.assert_no_error_messages()
    def test_warning_on_publish_when_references_are_not_published(self, browser):
        page = create(Builder('page')
                      .titled(u'The Page'))
        other_page = create(Builder('page')
                            .titled(u'The Other Page'))
        helpers.set_related_items(page, other_page)

        browser.login().visit(page)
        Workflow().do_transition('publish')
        statusmessages.assert_message(
            'The referenced object <a href="http://nohost/plone'
            '/the-other-page">The Other Page</a> is not yet published.'
        )
    def test_warning_shown_when_referencing_children_with_separate_workflow(
            self, browser):
        parent = create(Builder('folder').titled(u'Parent'))
        child = create(Builder('folder').titled(u'Child').within(parent))
        helpers.set_related_items(parent, child)

        browser.login().visit(parent)
        Workflow().do_transition('publish')
        self.assertItemsEqual(
            [
                'The referenced object <a href="http://nohost/plone'
                '/parent/child">Child</a> is not yet published.'
            ],
            statusmessages.warning_messages(),
        )
    def test_warning_on_retract_when_references_are_still_published(
            self, browser):
        page = create(Builder('page').titled(u'The Page'))
        other_page = create(Builder('page').titled(u'The Other Page'))
        helpers.set_related_items(page, other_page)

        api.content.transition(obj=page, to_state=EXAMPLE_WF_PUBLISHED)
        api.content.transition(obj=other_page, to_state=EXAMPLE_WF_PUBLISHED)
        transaction.commit()

        browser.login().visit(page)
        Workflow().do_transition('retract')

        statusmessages.assert_message(
            'The referenced object <a href="http://nohost/plone'
            '/the-other-page">The Other Page</a> is still published.')
    def test_warning_on_retract_when_references_are_still_published(self, browser):
        page=create(Builder('page')
                      .titled(u'The Page'))
        other_page=create(Builder('page')
                            .titled(u'The Other Page'))
        helpers.set_related_items(page, other_page)

        api.content.transition(obj=page,to_state=EXAMPLE_WF_PUBLISHED)
        api.content.transition(obj=other_page,to_state=EXAMPLE_WF_PUBLISHED)
        transaction.commit()

        browser.login().visit(page)
        Workflow().do_transition('retract')

        statusmessages.assert_message(
            'The referenced object <a href="http://nohost/plone'
            '/the-other-page">The Other Page</a> is still published.'
        )
 def test_references_dx_to_dx(self):
     foo = create(Builder('example dx type').titled(u'Foo'))
     bar = create(Builder('example dx type').titled(u'Bar'))
     helpers.set_related_items(bar, foo, force_relation_values=True)
     self.assertEquals([foo], list(get_state(bar).get_references()))
 def test_references_at_to_dx(self):
     dx = create(Builder('example dx type').titled(u'DX'))
     at = create(Builder('page').titled(u'AT'))
     helpers.set_related_items(at, dx)
     self.assertEquals([dx], list(get_state(at).get_references()))
 def test_references_dx_to_at(self):
     at = create(Builder('page').titled(u'AT'))
     dx = create(Builder('example dx type').titled(u'DX'))
     helpers.set_related_items(dx, at, force_relation_values=True)
     self.assertEquals([at], list(get_state(dx).get_references()))