<commit_before><?php

class Profile_BuilderTest extends PHPUnit_Framework_TestCase
{
	function testBasicProfile()
	{
		$builder = new Tiki_Profile_Builder;

		$expect = <<<EXPECT
---
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testAddObjects()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addObject(
			'wiki_page',
			'foo',
			array(
				'name' => 'Foo',
				'content' => 'Hello',
			)
		);
		$builder->addObject(
			'trackerfield',
			'date',
			array(
				'tracker' => $builder->ref('tracker'),
			)
		);

		$expect = <<<EXPECT
---
objects:
  -
    type: wiki_page
    ref: foo
    data:
      name: Foo
      content: Hello
  -
    type: trackerfield
    ref: date
    data:
      tracker: \$tracker
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testGroups()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addGroup('Base', $builder->user('group'));
		$builder->addGroup('Viewer', $builder->user('group') . ' Viewer', true);
		$builder->setManagingGroup('Base');

		$expect = <<<EXPECT
---
mappings:
  Base: \$profilerequest:group\$undefined\$
  Viewer: \$profilerequest:group\$undefined\$ Viewer
permissions:
  Base:
    description: \$profilerequest:group\$undefined\$
    objects:
      -
        type: group
        id: Base
        allow:
          - group_view
          - group_view_members
          - group_add_member
          - group_remove_member
      -
        type: group
        id: Viewer
        allow:
          - group_view
          - group_view_members
          - group_add_member
          - group_remove_member
  Viewer:
    description: \$profilerequest:group\$undefined\$ Viewer
    autojoin: y
    objects:
      -
        type: group
        id: Base
        allow:
          - group_view
          - group_view_members
      -
        type: group
        id: Viewer
        allow:
          - group_view
          - group_view_members
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testReplaceSimpleSyntax()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addGroup('Base', '{group}');
		$builder->setManagingGroup('Base');

		$expect = <<<EXPECT
---
mappings:
  Base: \$profilerequest:group\$undefined\$
permissions:
  Base:
    description: \$profilerequest:group\$undefined\$
    objects:
      -
        type: group
        id: Base
        allow:
          - group_view
          - group_view_members
          - group_add_member
          - group_remove_member
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testAssignDefaultGroup()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addObject(
			'wiki_page',
			'foo',
			array(
				'name' => 'Foo',
				'content' => 'Hello',
				'categories' => $builder->user('category'),
			)
		);

		$expect = <<<EXPECT
---
objects:
  -
    type: categorize
    data:
      type: wiki_page
      object: \$foo
      categories:
        - \$profilerequest:category\$undefined\$
  -
    type: wiki_page
    ref: foo
    data:<commit_msg>[FIX] Broken tests. I don't care what checkstyle says. That's how the code gets generated.<commit_after><?php

class Profile_BuilderTest extends PHPUnit_Framework_TestCase
{
	function testBasicProfile()
	{
		$builder = new Tiki_Profile_Builder;

		$expect = <<<EXPECT
---
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testAddObjects()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addObject(
			'wiki_page',
			'foo',
			array(
				'name' => 'Foo',
				'content' => 'Hello',
			)
		);
		$builder->addObject(
			'trackerfield',
			'date',
			array(
				'tracker' => $builder->ref('tracker'),
			)
		);

		$expect = <<<EXPECT
---
objects: 
  - 
    type: wiki_page
    ref: foo
    data: 
      name: Foo
      content: Hello
  - 
    type: trackerfield
    ref: date
    data: 
      tracker: \$tracker
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testGroups()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addGroup('Base', $builder->user('group'));
		$builder->addGroup('Viewer', $builder->user('group') . ' Viewer', true);
		$builder->setManagingGroup('Base');

		$expect = <<<EXPECT
---
mappings: 
  Base: \$profilerequest:group\$undefined\$
  Viewer: \$profilerequest:group\$undefined\$ Viewer
permissions: 
  Base: 
    description: \$profilerequest:group\$undefined\$
    objects: 
      - 
        type: group
        id: Base
        allow: 
          - group_view
          - group_view_members
          - group_add_member
          - group_remove_member
      - 
        type: group
        id: Viewer
        allow: 
          - group_view
          - group_view_members
          - group_add_member
          - group_remove_member
  Viewer: 
    description: \$profilerequest:group\$undefined\$ Viewer
    autojoin: y
    objects: 
      - 
        type: group
        id: Base
        allow: 
          - group_view
          - group_view_members
      - 
        type: group
        id: Viewer
        allow: 
          - group_view
          - group_view_members
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testReplaceSimpleSyntax()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addGroup('Base', '{group}');
		$builder->setManagingGroup('Base');

		$expect = <<<EXPECT
---
mappings: 
  Base: \$profilerequest:group\$undefined\$
permissions: 
  Base: 
    description: \$profilerequest:group\$undefined\$
    objects: 
      - 
        type: group
        id: Base
        allow: 
          - group_view
          - group_view_members
          - group_add_member
          - group_remove_member
EXPECT;
		$this->assertIs($expect, $builder->getContent());
	}

	function testAssignDefaultGroup()
	{
		$builder = new Tiki_Profile_Builder;
		$builder->addObject(
			'wiki_page',
			'foo',
			array(
				'name' => 'Foo',
				'content' => 'Hello',
				'categories' => $builder->user('category'),
			)
		);

		$expect = <<<EXPECT
---
objects: 
  - 
    type: categorize
    data: 
      type: wiki_page
      object: \$foo
      categories: 
        - \$profilerequest:category\$undefined\$
  - 
    type: wiki_page
    ref: foo
    data: 
{'fraction_non_alphanumeric': 0.13804768041237114, 'fraction_numerical': 0.0, 'mean_word_length': 2.307938199254129, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 55, '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': '6254950', 'n_tokens_mistral': 2222, 'n_tokens_neox': 1968, 'n_words': 383}