Repository-Simple

 view release on metacpan or  search on metacpan

t/engine_file_system.t  view on Meta::CPAN


    # Test has_permission($REMOVE) on node
    ok($engine->has_permission($path, $REMOVE));

    # Test has_permission($READ) on node
    ok($engine->has_permission($path, $READ));

    # Test path_exists() on node
    is($engine->path_exists($path), $NODE_EXISTS, "path_exists($path)");

    # Test node_type_of()
    my $node_type = $engine->node_type_of($path);
    is_deeply($node_type, $engine->node_type_named($paths{$path}), 
        'node_type_of');

    my %property_types = $node_type->property_types;

    # Test properties_in()
    is_deeply(
        [ sort $engine->properties_in($path) ],
        [ sort keys %property_types ], 
        'properties_in'
    );

    # Loop through all properties that are to be defined
    for my $property (keys %property_types) {
        my $property_path = $path_slash.$property;

        # Test has_permission($SET_PROPERTY) on property
        if ($property_types{$property} eq 'fs:scalar') {
            ok($engine->has_permission($property_path, $SET_PROPERTY));
        }

        # Test has_permission($REMOVE) on property: never applicable!
        # ok($engine->has_permission($property_path, $REMOVE));

        # Test has_permission($READ) on property
        ok($engine->has_permission($property_path, $READ));

        # Test path_exists() on property
        is($engine->path_exists($property_path), $PROPERTY_EXISTS,
            'path_exists');

        # Test property_type_of()
        my $property_type = $engine->property_type_of($property_path);
        is_deeply(
            $property_type, 
            $engine->property_type_named($property_types{$property}),
            'property_type_of'
        );

        # Test get_scalar() and get_handle()
        my $scalar = $engine->get_scalar($property_path);
        my $handle = $engine->get_handle($property_path);
        is($scalar, join '', <$handle>);
    }

    # Test path_exists() on a non-existent property
    ok(!$engine->path_exists($path_slash.'fs:notta'), '!path_exists property');

    # Test chown/chgrp if we are root
    SKIP: {
        skip 'Cannot test uid changes unless tested as root', 4 
            unless $< == 0;

        # Test chown
        my $fs_uid = $path_slash.'fs:uid';
        my $old_uid = $engine->get_scalar($fs_uid);
        $engine->set_scalar($fs_uid, 1);
        $engine->save_property($fs_uid);
        is($engine->get_scalar($fs_uid), 1);
        $engine->set_scalar($fs_uid, $old_uid);
        $engine->save_property($fs_uid);
        is($engine->get_scalar($fs_uid), $old_uid);

        # Test chgrp
        my $fs_gid = $path_slash.'fs:gid';
        my $old_gid = $engine->get_scalar($fs_gid);
        $engine->set_scalar($fs_gid, 1);
        $engine->save_property($fs_gid);
        is($engine->get_scalar($fs_gid), 1);
        $engine->set_scalar($fs_gid, $old_gid);
        $engine->save_property($fs_gid);
        is($engine->get_scalar($fs_gid), $old_gid);
    }

    # Test setting chmod
    my $fs_mode = $path_slash.'fs:mode';
    my $old_mode = $engine->get_scalar($fs_mode);
    my $new_mode = ($old_mode & ~0777) | 0755;
    $engine->set_scalar($fs_mode, $new_mode);
    $engine->save_property($fs_mode);
    is($engine->get_scalar($fs_mode), $new_mode);
    $engine->set_scalar($fs_mode, $old_mode);
    $engine->save_property($fs_mode);
    is($engine->get_scalar($fs_mode), $old_mode);

    # Test setting atime and mtime
    for my $time (qw( fs:atime fs:mtime )) {
        my $fs_time = $path_slash.$time;
        my $old_time = $engine->get_scalar($fs_time);
        $engine->set_scalar($fs_time, 0);
        $engine->set_scalar($fs_time, 0);
        $engine->save_property($fs_time);
        is($engine->get_scalar($fs_time), 0);
        $engine->set_scalar($fs_time, $old_time);
        $engine->set_scalar($fs_time, $old_time);
        $engine->save_property($fs_time);
        is($engine->get_scalar($fs_time), $old_time);
    }

    # Test setting fs:content
    if ($paths{$path} eq 'fs:file') {
        # Make sure the file is writable
        chmod 0644, $engine->real_path($path);

        my $test_str1 =
            qq(Besides, I'm training to be a cage fighter.\n);
        my $test_str2 =
            qq(What? You have like the worst reflexes in the world, Kip.\n);
        my $test_str3 =
            qq(Come down here and try to hit me, Napolean.\n);

        # Get ready to test setters on fs:content
        my $fs_content = $path_slash.'fs:content';
        my $old_content = $engine->get_scalar($fs_content);



( run in 0.347 second using v1.01-cache-2.11-cpan-5511b514fd6 )